Skip to content

Deploy to Cloud Run (prod) #586

Deploy to Cloud Run (prod)

Deploy to Cloud Run (prod) #586

Workflow file for this run

# Copyright 2019 Google, LLC.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# Original
# https://github.com/google-github-actions/setup-gcloud/blob/95e2d15420adee2aa7d97b08aff5d50feacb17b0/example-workflows/cloud-run/.github/workflows/cloud-run.yml
name: Deploy to Cloud Run (prod)
on: workflow_dispatch
env:
PROJECT_ID: fgosccalc
RUN_REGION: asia-northeast1
# prod
SERVICE_NAME: fgosccalc
jobs:
setup-build-deploy:
name: Deploy to Cloud Run (prod)
runs-on: ubuntu-latest
permissions:
id-token: write
contents: read
steps:
- name: Checkout
uses: actions/checkout@v2
with:
submodules: true
- name: Generate version information
run: |-
git log -1 > static/version
# https://github.com/google-github-actions/setup-gcloud#authorization
- name: Google Cloud Authorization
id: auth
uses: google-github-actions/auth@v0
with:
workload_identity_provider: '${{ secrets.GCLOUD_WORKLOAD_IDENTITY_PROVIDER }}'
service_account: '${{ secrets.GCLOUD_SERVICE_ACCOUNT }}'
- name: Setup Cloud SDK
uses: google-github-actions/setup-gcloud@v0
- name: Build and push the image to Google Container Registry
run: |-
gcloud builds submit \
--quiet \
--tag "gcr.io/$PROJECT_ID/$SERVICE_NAME:$GITHUB_SHA"
- name: Deploy to Cloud Run
id: deploy
uses: google-github-actions/deploy-cloudrun@v0
with:
service: ${{ env.SERVICE_NAME }}
region: ${{ env.RUN_REGION }}
image: gcr.io/${{ env.PROJECT_ID }}/${{ env.SERVICE_NAME }}:${{ github.sha }}
# Delete old revisions and container images in order to reduce the storage usage
- name: Delete old revisions
run: |-
gcloud run revisions list \
--service $SERVICE_NAME \
--region $RUN_REGION \
| tail -n +5 \
| awk '{{ print $2 }}' \
| xargs -I % gcloud run revisions delete % --region asia-northeast1 --quiet
- name: Delete old container images
run: |-
gcloud container images list-tags gcr.io/$PROJECT_ID/$SERVICE_NAME \
| tail -n +5 \
| awk '{{ print $1 }}' \
| xargs -I % gcloud container images delete \
gcr.io/$PROJECT_ID/$SERVICE_NAME@sha256:% --quiet --force-delete-tags