Chapter 04: GitOps & Version Promotion
Chapter 04: GitOps & Version Promotion
Why This Chapter Exists
Production safety depends on controlled promotion, not ad-hoc rebuilds. This chapter defines one deployment model:
developdeploysdevelop-*imagesstagingdeploysstaging-*imagesproductiondeploysproduction-*images from explicit promotion
The Incident Hook
A team rebuilds “the same” code for production during incident pressure. The binary differs from staging due to dependency drift and build-time variance. Rollback is confusing because the promoted artifact is not the one that was tested. Time is lost proving artifact lineage instead of restoring service.
What AI Would Propose (Brave Junior)
- “Just rebuild from main and deploy to production now.”
- “Use mutable
latesttag for speed.”
Why this sounds reasonable:
- fast and simple under pressure
- fewer manual steps
Why This Is Dangerous
- Rebuild breaks artifact immutability.
- Mutable tags destroy auditability.
- Incident response becomes guesswork across envs.
Guardrails That Stop It
- Promotion without rebuild:
staging-*is retagged toproduction-*. - Immutable env/version tags are required.
- Flux image automation writes all image updates to Git.
- GitOps-first rollback via commit revert.
- Pre-commit branch/history hooks prevent risky Git operations before promotion PRs:
scripts/pre-commit-master-check.shscripts/prevent-amend-after-push.sh
- Pre-commit manifest hook validates local Flux renders before promotion PRs:
scripts/flux-kustomize-validate.sh
Repo Mapping
docs/gitops-workflow.mdflux/bootstrap/infrastructure/image-automation/flux/apps/backend/develop/,flux/apps/backend/staging/,flux/apps/backend/production/flux/apps/frontend/overlays/develop/,flux/apps/frontend/overlays/staging/,flux/apps/frontend/overlays/production/
Current Model (As Implemented)
- Build on service
developbranch pushesdevelop-*image tags. - Build on service
mainbranch pushesstaging-*image tags. - Manual promotion workflow retags selected
staging-*image to:
productionproduction-v<major>.<minor>.<patch>-<short_sha>-<unix_ts>
- Flux
ImagePolicyselects latest env-matching immutable tag. - Flux
ImageUpdateAutomationcommits updated tags to Git and reconciles.
Lab Files
lab.mdquiz.md
Done When
- learner can explain “promotion instead of rebuild”
- learner can verify Flux image automation across all three environments
- learner can perform and explain GitOps-first rollback