Q&A-24Design a pipeline that builds an artifact once and promotes that identical artifact through staging and production. How is it identified as it moves, where does environment-specific configuration get injected, and how do promotion gates attach?
Answer
First 90 seconds. The guarantee you're buying is that the bytes that passed staging are the bytes that run in production. That only holds if identity is content-addressed (the OCI digest, sha256:... computed over the manifest) and if nothing downstream rebuilds. Tags are mutable pointers: app:v1.4.2 can be re-pushed and prod will pull different bytes under the same name. So the unit of promotion is the digest, and every stage pins it.
The build job checks out, builds, pushes, signs and attests, then emits the digest as an output. Staging and production jobs consume that digest as an input and never run docker build.
| Stage | What runs | Pinned to | Gate |
|---|---|---|---|
| build | build, push, sign, attest | commit SHA → digest | required checks on PR |
| staging | deploy only | digest | auto on merge |
| production | deploy only | same digest | required reviewers on the production environment |
yaml jobs: build: runs-on: ubuntu-latest outputs: digest: ${{ steps.push.outputs.digest }} steps: - uses: actions/checkout@v4 - id: push run: | docker build -t $REGISTRY/app:$GITHUB_SHA . docker push $REGISTRY/app:$GITHUB_SHA echo "digest=$(docker inspect --format='{{index .RepoDigests 0}}' $REGISTRY/app:$GITHUB_SHA)" >> "$GITHUB_OUTPUT" deploy-staging: needs: build environment: staging steps: - run: ./deploy.sh --image ${{ needs.build.outputs.digest }} deploy-prod: needs: deploy-staging environment: production # required reviewers attach here steps: - run: ./deploy.sh --image ${{ needs.build.outputs.digest }}
Configuration. Injected at deploy time, never baked. ConfigMaps and Secrets, Helm values per environment, env vars: the image stays byte-identical. In Kubernetes the Deployment references registry/app@sha256:...; changing the digest is what triggers a rollout, and the pod's imageID reports the digest that actually ran. Argo CD syncs the pinned digest from Git, with sync windows or manual sync as the production gate.
Failure modes.
- A rebuild inside the deploy job "just to add config". Detect by comparing digests across environments: they must be equal.
- Tag re-push. Detect by comparing
kubectl get pod -o jsonpath='{.status.containerStatuses[0].imageID}'against the promoted digest and alerting on drift. - Config compiled in (
NODE_ENV=productionbaked at build), so the staging artifact is not the production artifact. - Base image drift: rebuilding the same commit a week later picks up a re-pushed
python:3.12-slimand produces a different digest. Two builds of one commit are not the same release. - Secrets written into layers, which then travel to every environment.
Gates. They attach to the digest, not to a branch. GitHub environment protection rules with required reviewers, Argo CD sync windows, and deployment records linking digest → approver → timestamp. SLSA provenance ties the digest back to the source commit and builder, so the approval is provably about the artifact that shipped.
When not to. Genuinely environment-specific builds (native compilation, different CPU architecture, licensed binaries) should be separate artifacts, labelled honestly rather than claimed as parity. And if config differs between staging and production, staging did not test production's behaviour: validate config against a schema and keep the staging config shape identical to production's.
Curated: · Written: · Reviewed:
Log in free to save your progress and keep bookmarks and notes for a quick revision before your interview.