Workflow: Promote, Never Rebuild
Built Twice, Promoted Once
The backend and the frontend each have their own repository and their own build:
| Step | What happens | Image |
|---|---|---|
push to the develop branch | build, scan, sign, push | develop-v…-<sha>-<timestamp> |
merge to main | build, scan, sign, push | staging-v…-<sha>-<timestamp> |
promote-production (run by hand) | no build: docker buildx imagetools create gives a tested staging image a production tag | production-v… with the same suffix and the same digest |
So the honest claim is narrower than “one artifact through three environments”: develop is its own build; from staging to production nothing is rebuilt. Staging tests the exact bytes production will run. A rebuild - even of the same commit - pulls dependencies and base images as they are on the day of the build; its digest is new, and nothing proves it behaves like the image staging tested.
Name, Rule and Identity
Three different things are easy to mix up:
| What it is | What it proves | |
|---|---|---|
The tag’s format - production-v0.0.0-165ecab-1790509191 | a naming convention: environment, version, commit, build timestamp | nothing about content - anyone with push rights can push any image under any name |
| A tag that is never overwritten | a rule: every build gets a new timestamp, so a tag name is used once | only as long as the rule holds - the registry itself does not forbid moving a tag |
The digest - sha256:4ca3a6… | the hash of the content | identity: the same digest is the same image, byte for byte |
A multi-platform image has two levels of digest: the index - the list of platforms - and one manifest per platform (linux/amd64, linux/arm64). A promotion copies the index, so staging and production share the index digest; a pod’s imageID shows the index digest it was pulled by - on kind and the platform, whose runtime is containerd. Compare index with index - not an index with one platform’s manifest. Another runtime may report a different identifier there (Docker Engine, for example, the image’s local ID); if imageID is not a repo@sha256:... you recognise, compare the digest the image was pulled by in the node’s own tooling (crictl images --digests --no-trunc on the node) instead of reading a mismatch as the wrong version.
How Production Picks Its Version
On the cloud cluster, each environment has an ImagePolicy. Production’s accepts only its own format and picks the newest:
Backend ImagePolicy (production)
---
apiVersion: image.toolkit.fluxcd.io/v1
kind: ImagePolicy
metadata:
name: backend
namespace: production
spec:
imageRepositoryRef:
name: backend
namespace: flux-system
filterTags:
pattern: '^production-v[0-9]+\.[0-9]+\.[0-9]+-[a-f0-9]+-(?P<ts>[0-9]+)$'
extract: '$ts'
policy:
numerical:
order: asc
pattern: '^production-v[0-9]+\.[0-9]+\.[0-9]+-[a-f0-9]+-(?P<ts>[0-9]+)$'- a production tag with a semantic version, a commit hash and a timestamp, and nothing else: nostaging-…, noproduction-latest, no-amd64suffix.extract: '$ts'withnumerical: asc- of the accepted tags, the one with the highest timestamp wins.
The pattern checks the name. It cannot tell a promoted image from one built on a laptop and pushed under a well-formed name with a newer timestamp - that is why production images come only from the promotion workflow, and why the proof is the digest.
The picked tag reaches Git through image automation: every five minutes it compares the policy’s choice with the one line marked by a setter comment. Only when they differ does it rewrite that line, commit Update production backend image and push it straight to main - no pull request, and the commit message carries [ci skip], so none of the pull-request checks below run on it (only what the policy’s pattern accepts reaches Git). The production path therefore has four separate steps: the code is reviewed in a pull request; a person decides to promote one tested staging tag; automation writes the version; and the rollout is proven afterwards, by digest. Flux then applies it like any other commit - a rolling update that keeps the old pods serving until the new ones are Ready (Chapter 09).
Production overlay (newTag and its setter)
Show the production overlay
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
namespace: production
namePrefix: ""
labels:
- pairs:
environment: production
includeSelectors: true
includeTemplates: true
resources:
- ../base
- image-policy.yaml
- image-automation.yaml
- hpa.yaml
- pdb.yaml
images:
- name: backend
newName: ${image_registry}/backend
newTag: production-v0.0.0-13f9e84-1791575727 # {"$imagepolicy": "production:backend:tag"}
patches:
# The backend reads backend-secrets and app-postgres-app as env vars, once, at start. A rotation sets
# this to the current UTC time (date -u +%FT%TZ) in the same pull request as the Secret - or, for the Terraform-made database password, in a
# pull request right after it: the pod template changes, and Flux rolls the pods like any release
# (one new pod Ready before an old one goes). Not `kubectl rollout restart` - Flux removes its
# annotation on the next reconcile and, mid-rollout, keeps the old pods with the old value
# (docs/credential-rotation.md).
- patch: |-
apiVersion: apps/v1
kind: Deployment
metadata:
name: backend
spec:
template:
metadata:
annotations:
safeops.io/secrets-rotated: "2026-09-26T00:00:00Z"
kind has no image automation. The local profile leaves it out - it would need write access to your fork. On kind, a version changes only when you commit it; the lab builds the production policy in lab to watch it choose, without writing anything.
The check in the pull request. check-image-tags.sh refuses an overlay whose newTag does not match its own environment’s ImagePolicy - a staging tag in production, a malformed tag - or whose setter comment is missing or names another policy. Without the comment, automation silently stops updating that environment.
check-image-tags.sh
Show the image tag check
#!/usr/bin/env bash
repo_root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
cd "${repo_root}"
command -v yq >/dev/null || { echo "check-image-tags: yq is required (make check-tools)" >&2; exit 1; }
failures=()
checked=0
# The policy for this image: an ImagePolicy named like the image, in the overlay's namespace.
select_policy="select(.kind == \"ImagePolicy\" and .metadata.name == \"${name}\" and .metadata.namespace == \"${namespace}\")"
policy=""
for candidate in "${dir}"/*.yaml; do
if [[ "$(yq ea "${select_policy} | .metadata.name" "${candidate}")" == "${name}" ]]; then
policy="${candidate}"
break
fi
done
if [[ -z "${policy}" ]]; then
failures+=("${kustomization}: image '${name}' sets newTag but ${dir} has no ImagePolicy '${name}' in namespace '${namespace}'")
continue
fi
pattern="$(yq ea "${select_policy} | .spec.filterTags.pattern" "${policy}")"
policy_ref="${namespace}:${name}"
# The ImagePolicy pattern uses a named group, (?P<ts>...), for Flux; bash regex (ERE) has only plain
# groups, so drop the name - what the pattern accepts stays the same.
ere="${pattern//\(\?P<[a-z]*>/(}"
if [[ ! "${tag}" =~ ${ere} ]]; then
failures+=("${kustomization}: image '${name}' newTag '${tag}' does not match ${policy} (${pattern})")
fi
expected_setter="{\"\$imagepolicy\": \"${policy_ref}:tag\"}"
if [[ "${setter}" != "${expected_setter}" ]]; then
failures+=("${kustomization}: image '${name}': the newTag line must end with # ${expected_setter} (got: '${setter}')")
fi
checked=$((checked + 1))
done
done < <(find flux/apps -name kustomization.yaml | sort)
if [[ "${checked}" -eq 0 && ${#failures[@]} -eq 0 ]]; then
echo "check-image-tags: no overlay with newTag found under flux/apps" >&2
exit 1
fi
if [[ ${#failures[@]} -gt 0 ]]; then
echo "check-image-tags: ${#failures[@]} problem(s):" >&2
printf ' - %s\n' "${failures[@]}" >&2
exit 1
fi
echo "check-image-tags: OK (${checked} image tags)"
Rolling Back
| kind (no automation) | the cloud cluster (automation every five minutes) | |
|---|---|---|
| What chooses the version | the commit you make | the ImagePolicy - the automation writes its choice into Git |
| The rollback | a pull request that sets newTag back to the good tag | one pull request: the policy’s pattern narrowed to the good tag and newTag set to it |
| After the fix | promote it as usual | promote it, then a second pull request restores the pattern |
A revert of newTag alone on the cloud cluster lasts until the next automation run - the incident. Flux documents the same answer: change what the policy selects, not only the line it writes.
Never instead:
kubectl set imageorkubectl rollout undo- Flux sets the Deployment back at the next reconcile, and Git no longer says what runs (Chapter 03);- a rebuild pushed as a new tag - an untested image with a new digest;
- deleting the automation - promotion silently stops for every later release.
What the Platform Does Not Do Yet
- “Tested” is a decision, not a record. The digest proves that production runs the image staging ran. It does not prove which checks that image passed in staging: the promotion workflow scans the image, but nothing in it checks a staging acceptance result for that digest - the person who runs the promotion makes that call.
- Git references images by tag, not by digest. At admission the platform’s image policy (Chapter 17) checks the image’s signature and writes the verified digest into the pod, so a pod whose image is under the platform’s registry runs exactly what was verified - and in
develop,stagingandproductionan image under the platform’s registry (${image_registry}/...) that our builds did not sign is refused. The policy checks only that registry: images the admission guardrails allow from elsewhere, such as CloudNativePG’s, are not verified or pinned by it. A tag moved between two pods’ creation still gives two pods different images, each signed: pinning the digest in Git, through image automation, would close that, and is not done yet.
Guardrails That Stop It
- The promotion workflow (backend and frontend repositories) - production tags are re-tags of staging tags; nothing is built for production.
check-image-tags.sh(workstation, CI) - each overlay’s tag matches its own policy, with the setter comment.- The ImagePolicy (cloud cluster) - accepts only its environment’s format.
- Flux (cluster) - a hand change to the Deployment is set back at the next reconcile.
- RBAC (cluster, Hetzner) - the everyday sign-in reads production, it cannot change it.
Safe Workflow (Step-by-Step)
- Promote, never build: run the promotion with the staging tag that was tested.
- Prove the promotion: the staging and production tags have the same digest.
- Prove the rollout: the production pods’
imageIDis that digest;/versionreports the staging build. - To roll back: on the cloud cluster, one pull request that pins the policy to the good tag and sets
newTag; on kind,newTagalone.hooksrunscheck-image-tags.sh;flux diffshows the one line that will change. - Prove the rollback by digest, then restore the pattern once the fix is promoted.
Instructions for Your AI Agent
The rules this chapter adds:
- Never build or push an image for production. Promote a tested staging tag, and prove it by digest: the two tags (
docker buildx imagetools inspect) and the running pods (status.containerStatuses[].imageID) show the same index digest. Enforced by: production images come only from the promotion workflow (promote-production.yml, a re-tag); the proof is instruction only. - Never change a running image by hand (
kubectl set image,kubectl rollout undo). ChangenewTagthrough a pull request. Enforced by: Flux sets the Deployment back; on Hetzner the everyday sign-in only reads production. - Keep each overlay’s
newTagmatching its own environment’s ImagePolicy, with the setter comment# {"$imagepolicy": "<namespace>:<name>:tag"}. Enforced by:scripts/check-image-tags.shin pre-commit and CI. - A production rollback on the cloud cluster pins the ImagePolicy’s pattern to the good tag together with
newTag, in one pull request - a revert ofnewTagalone is written back by the automation. Restore the pattern in another once the fix is promoted. Enforced by: instruction only (reviewed in the pull request).
The full list, chapter by chapter, is docs/agent-rules.md in your fork of the platform repository.
This builds on: Availability Engineering (Chapter 09) - a promotion is a rolling update; the replicas and budgets keep it invisible. This enables: Observability (Chapter 11) - after a promotion, the metrics are how you know whether it was good.