allow multiple region deployment #1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: GCP Cloud Run Deploy | |
on: | |
workflow_call: | |
inputs: | |
service: | |
type: string | |
default: ${{ github.event.repository.name }} | |
regions: | |
type: array | |
default: ['us-east1'] | |
ingress: | |
type: string | |
default: all | |
execution-environment: | |
type: string | |
default: gen2 | |
port: | |
type: number | |
default: 8080 | |
cpu: | |
type: number | |
default: 1 | |
memory: | |
type: string | |
default: 1Gi | |
min-instances: | |
type: number | |
default: 0 | |
max-instances: | |
type: number | |
default: 10 | |
concurrency: | |
type: number | |
default: 100 | |
timeout: | |
type: number | |
default: 60 | |
cloud-sql: | |
type: boolean | |
default: false | |
deploy-args: | |
type: string | |
env: | |
GCP_PREFIX: ${{ fromJSON('{"master":"prd","stage":"stg"}')[github.ref_name] }} | |
CLOUD_RUN_IMAGE: ${{ format('gcr.io/{0}-cnpja/{1}-{2}:{3}', fromJSON('{"master":"prd","stage":"stg"}')[github.ref_name], fromJSON('{"master":"prd","stage":"stg"}')[github.ref_name], github.event.repository.name, github.sha) }} | |
jobs: | |
deploy: | |
name: Cloud Run Deploy | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout Code | |
uses: actions/checkout@v4 | |
- name: Authenticate Google Cloud Platform | |
uses: google-github-actions/auth@v2 | |
with: | |
credentials_json: ${{ secrets[format('{0}_GCP_SERVICE_ACCOUNT_KEY', fromJSON('{"master":"PRD","stage":"STG"}')[github.ref_name])] }} | |
- name: Set up Google Cloud SDK | |
uses: google-github-actions/setup-gcloud@v2 | |
- name: Configure Google Cloud CLI | |
run: gcloud auth configure-docker | |
- name: Download Build Artifacts | |
uses: actions/download-artifact@v4 | |
continue-on-error: true | |
with: | |
name: build-artifacts | |
- name: Build Container Image | |
run: | | |
docker build . -t $CLOUD_RUN_IMAGE \ | |
--build-arg NPM_TOKEN=${{ secrets.GLB_NPM_TOKEN }} | |
- name: Publish Image to Container Registry | |
run: docker push $CLOUD_RUN_IMAGE | |
- name: Deploy Image on Cloud Run | |
run: | | |
for region in ${{ inputs.regions }}; do | |
DEPLOY_CMD="gcloud run deploy $GCP_PREFIX-${{ inputs.service }} \ | |
--project $GCP_PROJECT \ | |
--region $region \ | |
--allow-unauthenticated \ | |
--cpu-boost \ | |
--image $CLOUD_RUN_IMAGE \ | |
--ingress ${{ inputs.ingress }} \ | |
--execution-environment ${{ inputs.execution-environment }} \ | |
--port ${{ inputs.port }} \ | |
--cpu ${{ inputs.cpu }} \ | |
--memory ${{ inputs.memory }} \ | |
--max-instances ${{ inputs.max-instances }} \ | |
--min-instances ${{ inputs.min-instances }} \ | |
--concurrency ${{ inputs.concurrency }} \ | |
--timeout ${{ inputs.timeout }}" | |
if [ "${{ inputs.cloud-sql }}" = "true" ]; then | |
DEPLOY_CMD="$DEPLOY_CMD \ | |
--network default \ | |
--subnet default \ | |
--vpc-egress private-ranges-only \ | |
--set-cloudsql-instances ${{ fromJSON('{"master":"prd-cnpja:us-east1:prd-mysql-ha","stage":"stg-cnpja:us-east1:stg-mysql"}')[github.ref_name] }}" | |
fi | |
DEPLOY_CMD="$DEPLOY_CMD ${{ inputs.deploy-args }}" | |
eval $DEPLOY_CMD | |
done |