Skip to content

CD

CD #392

Workflow file for this run

name: CD
on:
workflow_dispatch: {}
workflow_run:
workflows: [CI]
types: [completed]
branches: main
permissions: {}
jobs:
deploy:
name: Deploy
runs-on: ubuntu-20.04
permissions: read-all
# Skip if this was a dependabot push, as we don't want to spam deploys
# for small dependency upgrades. If we need a dependency upgrade in production
# just use the workflow dispatch manual trigger after CI passed
# Also skip if there is a no-deploy tag in the commit message
if: ${{ github.event.sender.login != 'dependabot[bot]' && ! startsWith(github.event.commits[0].message, '[no-deploy]') && github.event.workflow_run.conclusion == 'success' }}
env:
PRODUCTION_SERVICE: speedcubing-trainer
STAGING_SERVICE: staging-speedcubing-trainer
REGION: us-east4
DOCKER_HUB_TAG: sctrainer/main:production-${{ github.sha }}
PROJECT_ID: carbide-ether-306312
# Remember to update project id here if you update the variable above
GOOGLE_TAG: us-east4-docker.pkg.dev/carbide-ether-306312/speedcubing-trainer/main:${{ github.sha }}
steps:
- name: Pull our production image
run: docker pull ${{ env.DOCKER_HUB_TAG }}
- name: Retag our production image to Google format
run: docker image tag ${{ env.DOCKER_HUB_TAG }} ${{ env.GOOGLE_TAG }}
- name: Authenticate to Google Cloud
id: auth
uses: google-github-actions/auth@v1
with:
credentials_json: "${{ secrets.GOOGLE_CLOUD_DEPLOY_SA_KEY }}"
- name: Setup Cloud SDK
uses: google-github-actions/[email protected]
with:
project_id: ${{ env.PROJECT_ID }}
- name: Configure and Authorize Docker For Pushing to Google
run: gcloud auth configure-docker ${{ env.REGION }}-docker.pkg.dev
- name: Push Image to the Artifacts Registry
run: docker push ${{ env.GOOGLE_TAG }}
- name: Deploy Production to Cloud Run
id: deploy-production
uses: google-github-actions/[email protected]
with:
service: ${{ env.PRODUCTION_SERVICE }}
image: ${{ env.GOOGLE_TAG }}
region: ${{ env.REGION }}
- name: Show Production Output
run: echo ${{ steps.deploy-production.outputs.url }}
- name: Deploy Staging to Cloud Run
id: deploy-staging
uses: google-github-actions/[email protected]
with:
service: ${{ env.STAGING_SERVICE }}
image: ${{ env.GOOGLE_TAG }}
region: ${{ env.REGION }}
- name: Show Staging Output
run: echo ${{ steps.deploy-staging.outputs.url }}