Skip to content

Commit

Permalink
merge image builds and add update services workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
glass-ships committed Sep 22, 2023
1 parent fbe5894 commit 91be7f3
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 147 deletions.
68 changes: 0 additions & 68 deletions .github/workflows/build-image-test.yaml

This file was deleted.

64 changes: 0 additions & 64 deletions .github/workflows/build-image.yaml

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,27 +1,54 @@
name: Deploy Frontend

name: Build and Push Docker Images
on:
workflow_dispatch:
push:
branches:
- main
- [main, automate-docker-update]
release:
types: [published]

# This job uses RafikFarhad's GitHub action to build and
# push a docker image to a specified GCP repository
jobs:
build-and-push-api-image:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0 # to get all tags

defaults:
run:
working-directory: ./frontend
- name: Generate Image Tag
id: get-tag
run: |
REV=$(git rev-list --tags --max-count=1)
IMAGE_TAG=$(git describe --tags $REV)
echo "IMAGE_TAG=${IMAGE_TAG//v}"
echo "IMAGE_TAG=${IMAGE_TAG//v}" >> $GITHUB_OUTPUT
permissions:
contents: write
- name: Build and Push Image
uses: RafikFarhad/push-to-gcr-github-action@v5-beta
with:
gcloud_service_key: ${{ secrets.JSON_GCLOUD_SERVICE_ACCOUNT_JSON }}
registry: us-central1-docker.pkg.dev
project_id: monarch-initiative
image_name: monarch-api/monarch-api
image_tag: latest, ${{ steps.get-tag.outputs.IMAGE_TAG }}, ${{ github.sha }}
dockerfile: ./backend/Dockerfile

jobs:
deploy:
build-and-push-frontend-image:
runs-on: ubuntu-latest
defaults:
run:
working-directory: ./frontend
permissions:
contents: write
steps:
- name: Checkout code
uses: actions/checkout@v3
with:
fetch-depth: 0 # to get all tags

- name: Set up Node
uses: actions/setup-node@v3
with:
Expand All @@ -33,9 +60,6 @@ jobs:
- name: Build app
run: yarn build

# also create an image based off of nginx with the frontend baked in
# (copied from ./build-image.yaml, with modifications)

- name: Generate Image Tag for Frontend Dir
id: get-tag
run: |
Expand All @@ -51,7 +75,7 @@ jobs:
- name: Build and Push Image
uses: RafikFarhad/push-to-gcr-github-action@v5-beta
with:
gcloud_service_key: ${{ secrets.JSON_GCLOUD_SERVICE_ACCOUNT_JSON }} # not needed if you use google-github-actions/auth
gcloud_service_key: ${{ secrets.JSON_GCLOUD_SERVICE_ACCOUNT_JSON }}
registry: us-central1-docker.pkg.dev
project_id: monarch-initiative
image_name: monarch-api/monarch-ui
Expand Down
33 changes: 33 additions & 0 deletions .github/workflows/update-gcp-services.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: Update GCP Docker Services
on:
workflow_dispatch:
workflow_run:
workflows: ["Build and Push Docker Images"]
branches: [main, automate-docker-update]
types:
- completed

jobs:
update-gcp-services:
runs-on: ubuntu-latest
needs: build-and-push-to-gcr
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0 # to get all tags

- id: "auth"
uses: "google-github-actions/auth@v1"
with:
credentials_json: "${{ secrets.JSON_GCLOUD_SERVICE_ACCOUNT_JSON }}"

- name: "Set up Cloud SDK"
uses: "google-github-actions/setup-gcloud@v1"
with:
version: ">= 447.0.0"

- name: "Update API Service"
run: |
gcloud compute ssh --zone us-central1-a monarch-v3-dev-manager -- sudo docker service update monarch-v3_api --with-registry-auth --update-order=start-first --force --image us-central1-docker.pkg.dev/monarch-initiative/monarch-api/monarch-api:${{ github.sha }}
gcloud compute ssh --zone us-central1-a monarch-v3-dev-manager -- sudo docker service update monarch-v3_nginx --with-registry-auth --update-order=start-first --force --image us-central1-docker.pkg.dev/monarch-initiative/monarch-api/monarch-ui:${{ github.sha }}

0 comments on commit 91be7f3

Please sign in to comment.