Collection of reusable GitHub Actions workflows:
Sets up docker and builds a container from Dockerfile in the calling repository.
The workflow authenticates to Google Container Registry through Workload Identity Federation. The calling repository needs to be given access to use workload identity. Ask #team-platform about this.
The workflow generates the following tags on the built container image:
latestif the event was a push to the default branch of the repository.commit-sha(short) on push.vx.y.zfor releases with semver tag.
name: Docker Build, Push & Deploy
on:
release:
types: [published]
push:
branches: ["main"]
jobs:
build:
uses: atb-as/workflows/.github/workflows/cluster-docker-build-tag-push.yaml@v2
with:
image: gcr.io/atb-mobility-platform/foo
secrets:
github_pat: ${{ secrets.GH_PAT }}If your service applies database migrations (e.g. a Flyway
image run as an ArgoCD PreSync hook), set migrations_dockerfile to build a second image in
the same run. Both images are built before anything is deployed, so if either build fails the
whole run fails and neither image is bumped — and on success both image tags are bumped in
the same infra commit (one ArgoCD sync), keeping the app and its migrations atomic.
jobs:
build:
uses: atb-as/workflows/.github/workflows/cluster-docker-build-tag-push.yaml@v2
with:
image: gcr.io/atb-mobility-platform/foo
migrations_dockerfile: Dockerfile.migrations
secrets:
github_pat: ${{ secrets.GH_PAT }}The migrations image is named <image>-migrations by default (e.g.
gcr.io/atb-mobility-platform/foo-migrations); override with migrations_image. It is tagged
the same way as the app image (short SHA on push, semver on release). Omit
migrations_dockerfile and the workflow behaves exactly as before (single image).
- Create PR
- Get approval
- Merge into main branch
- The docker image is built and tagged
- The docker image is pushed to GCR
- The docker image is deployed to staging
- Create a GitHub release with a tag
- The docker image is built and tagged (skipped if it exists)
- The docker image is pushed to GCR (skipped if it exists)
- The docker image is deployed to production
Only do this if there are changes in main that cannot be deployed to production.
- Checkout the tag and create a new branch
- Make the hotfix and push the branch
- Create a new release from the branch
- The docker image is built and tagged (skipped if it exists)
- The docker image is pushed to GCR (skipped if it exists)
- The docker image is deployed to production
It's preferable to do this as a PR in the cluster-infra repo. Do a revert of the commit that deployed the release you want to roll back and create a PR with the reverted commit.