$ run as a normal user# run as root (or with sudo)
The quick answer
name: promote
on:
workflow_dispatch:
inputs:
digest:
description: "Image digest tested in staging (sha256:...)"
required: true
jobs:
production:
runs-on: ubuntu-latest
environment: production
permissions:
contents: write
steps:
- uses: actions/checkout@v4
- run: |
cd envs/prod
kustomize edit set image registry.example.com/shop/api@${{ inputs.digest }}
git config user.name "release-bot"
git config user.email "release-bot@example.com"
git commit -am "prod: shop/api ${{ inputs.digest }}"
git pushStep by step
- Build once — CI builds the image one time per commit and pushes it; the build output is the digest (
sha256:…), which never changes (a tag like:latestor even:1.4.2can be moved). - Deploy to staging by digest — the staging overlay in the GitOps repo gets
image@sha256:…; Argo CD or Flux deploys it. - Test in staging — automatic smoke and integration tests, plus manual checks if needed. Record the result (a check run or a comment).
- Promote the same digest (quick answer) — a workflow updates the production overlay with the tested digest. Nothing is rebuilt.
- Approval gate — the
productionenvironment in GitHub (Settings → Environments) with required reviewers: the job waits until a reviewer approves. Optionally a wait timer and allowed branches. - Promotion is a Git commit — the production repo history shows who promoted which digest and when. Rollback =
git revertof that commit. - Promote the config too — keep environment differences small and explicit (replicas, URLs, secrets references in overlays); everything else is shared.
- Stronger guarantees — sign images (Cosign) in CI and let the production cluster accept only signed images from your pipeline (Kyverno/admission policy).
Check that it worked
The image digest running in production (kubectl -n shop get deploy api -o jsonpath='{.spec.template.spec.containers[0].image}') is exactly the digest tested in staging; the promote run shows the reviewer's approval; the GitOps repo has one commit per promotion.
Common problems
| Problem | Cause | Fix |
|---|---|---|
| Production behaves differently than staging | Rebuilt image or moved tag. | Deploy by digest; never rebuild for production. |
| Promote job runs without approval | Environment not protected. | Required reviewers on the production environment. |
git push rejected in the workflow | Missing contents: write or branch protection. | Permission in the job; allow the bot or use a PR + auto-merge. |
| Rollback is slow | Rollback means a new build. | Revert the promotion commit; the old digest is still in the registry. |
| Old images deleted by cleanup | Registry retention removed the digest. | Keep images that are deployed or recently promoted. |
| Config drift between environments | Big differences in overlays. | Keep overlays small; review them with the code. |
Go further
- Command pages: git, kustomize, gh.
- Next how-tos: Build and push an image in CI, Deploy from Git with Flux, Do a canary release in Kubernetes, Sign and verify an image with Cosign.
- Learn it: GitOps — Promotion, GitOps — Promotion safety, GitHub Actions — Environments.
1Why deploy by image digest and not by tag?
A digest always points to exactly the same image; a tag can be moved to another build.
2How do you roll back a promotion in a GitOps setup?
Revert the promotion commit; the GitOps tool deploys the previous digest again.