Skip to content

apollo-graphql-deploy-to-gcp-cloud-run #41

apollo-graphql-deploy-to-gcp-cloud-run

apollo-graphql-deploy-to-gcp-cloud-run #41

name: apollo-graphql-deploy-to-gcp-cloud-run
on:
# use pull_request if you want to run this action when new PR is created
push:
branches:
- master
# https://docs.github.com/en/actions/learn-github-actions/workflow-syntax-for-github-actions#onpushpull_requestpaths
paths:
- 'apollo/**'
- '.github/workflows/apollo_graphql_deploy_to_run.yml'
workflow_dispatch:
inputs:
name:
description: 'Enter the name of this workflow trigger'
required: true
env:
REGION: asia-east1
SERVICE: campus-apollo-graphql-server
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Into the repo
uses: actions/checkout@v2
# * below steps reference from here
# https://github.com/google-github-actions/deploy-cloudrun/blob/main/.github/workflows/example-workflow.yaml
# https://cloud.google.com/community/tutorials/cicd-cloud-run-github-actions?hl=zh-tw
# * setup cloud SDK is needed since it would need the credential to configure
# in the docker.
# * available inputs:
# https://github.com/google-github-actions/deploy-cloudrun#inputs
- name: Setup Cloud SDK
uses: google-github-actions/setup-gcloud@v0.2.0
with:
project_id: ${{ secrets.GCP_PROJECT_ID }}
service_account_key: ${{ secrets.GCP_SA_KEY }}
export_default_credentials: true # Set to true to authenticate the Cloud Run action
- name: Authorize Docker push
run: gcloud auth configure-docker
- name: Build and Push Container
# https://yaml-multiline.info/
# Keep newlines (literal), No newline at end (strip)
run: |-
docker build -t gcr.io/${{ secrets.GCP_PROJECT_ID }}/${{ env.SERVICE }}:${{ github.sha }} apollo/
docker push gcr.io/${{ secrets.GCP_PROJECT_ID }}/${{ env.SERVICE }}:${{ github.sha }}
- name: Deploy to Cloud Run
id: deploy
uses: google-github-actions/deploy-cloudrun@main
with:
service: ${{ env.SERVICE }}
image: gcr.io/${{ secrets.GCP_PROJECT_ID }}/${{ env.SERVICE }}:${{ github.sha }}
region: ${{ env.REGION }}
- name: Redirect traffic to latest revision
uses: google-github-actions/deploy-cloudrun@main
with:
service: ${{ env.SERVICE }}
region: ${{ env.REGION }}
# https://cloud.google.com/sdk/gcloud/reference/run/services/update-traffic#--to-latest
# this need to be seperate step
revision_traffic: LATEST=100