Just some practical experimenting with optimizing Docker builds between CI and CD to multiple environments. With this workflow you are only building your image once and re-tagging it for production releases.
The GitHub workflow in this repository does the following:
- Trigger on commits to
refs/heads/trunk
- which is my imaginary test/dev environment. - Pulls alpine:latest
- Tags it with
kimiversen.azurecr.io/alpine:${{ env.github_sha }}
- Push the image
- End - dev build is now built and pushed, ready for CD to deploy.
A second job is ran for production
- Trigger on tags with the rule
*.*.*
- Pull the already built image from the commit sha
kimiversen.azurecr.io/alpine:${{ github.sha }}
- Re-tag to
kimiversen.azurecr.io/alpine:${{ github.ref_name }}
- Push the image
# Push to development
git push origin trunk
# Push to production (where $COMMIT_SHA is the commit sha of the dev build you want to lift to production)
git tag -a 0.0.1 -m "Canon" $COMMIT_SHA
git push origin 0.0.1