Skip to content

Lesson 12 of 13 · 20m

Build Once, Promote Many: Artifacts and Environments

Deploy the digest you verified — immutable images, signed provenance, and environment gates are what keep staging's bytes identical to production's.

The unit that moves through your pipeline isn't code — it's an artifact: a container image, a tarball, a binary. The discipline that makes deployments trustworthy is build once, promote many: the exact bytes that passed staging are the bytes that reach production, identified by digest, not by a label someone moved.

Why :latest is a lie

myapp:latest isn't an identity — it's a pointer. Yesterday's latest and today's latest are different images, and "roll back to latest" is a sentence that means nothing. The identity is the content digest: myapp@sha256:4b8f…, which names the immutable blob the registry stores. Kubernetes manifests and compose files referencing tags redeploy whatever the tag now means; digests redeploy what you verified. Amazon ECR can enforce it at the registry level — imageTagMutability: IMMUTABLE rejects pushes that overwrite an existing tag, turning "please don't reuse tags" into a hard error.

Build once, promote many

Rebuilding per environment sounds safe and voids the point: nondeterminism — timestamped builds, a dependency that floated since staging's build, a toolchain that repointed ubuntu-latest — means the thing you tested isn't the thing running. The pipeline: CI builds and pushes myapp:abc123 once; staging deploys that digest; production's promotion step deploys the same digest. The deploy diff between environments is configuration, not bytes. When something is wrong in prod you can answer "is this the same image that passed staging?" with a hash instead of a shrug.

Provenance: signed artifacts and attestations

The follow-up question an incident asks: where did these bytes come from? Sigstore's cosign signs images by digest — cosign sign --key cosign.key myapp@sha256:…, or keyless via the same OIDC JWT machinery from the secrets lesson. docker buildx build can emit SBOM and SLSA provenance attestations recording the source repo, workflow, and materials that produced the image. SLSA provenance lets a deploy gate ask "was this image built by our CI from our main branch?" and get a cryptographic yes instead of a registry listing. syft generates the SBOM if the build doesn't.

Verification belongs at admission, not audit: cosign verify in the deploy step, or a policy engine — Kyverno's verifyImages, Sigstore's policy-controller — rejecting unsigned images before they schedule. A signature checked quarterly in a report is a signature that never stops anything.

Environments as the promotion gate

GitHub environments: give each deploy target its own secrets and its own protection rules: production requires a reviewer's click before its secrets release to the job; staging deploys on every merge to main. Deployment history, review trails, and per-environment secrets all live there — which is why the deploy job declares environment: production instead of merely having a step named "deploy to prod." The environment is where the gate and the credentials meet; a deploy step without one holds production keys with no gate at all.

Two mechanics round it out: url: on the environment surfaces the deployed URL on the PR and in the deployments view, and a concurrency: group on the deploy job serializes promotions — two merges racing to deploy the same environment is how staging gets the newer image and prod gets a half-finished rollout.

Field notes

  • Tag images with the commit SHA for humans and pin digests for machines — the tag is a convenience, the digest is the truth.
  • docker buildx imagetools inspect myapp:tag shows which digest a tag currently resolves to — the fastest "same bits?" check across environments.
  • Registries are security boundaries: a public ghcr.io package publishes your image layers to the internet. Check package visibility before the first push.
  • Promotion through environments is also the audit trail: who promoted which digest, when, on whose approval.

Was this lesson helpful?

Sign in to rate

Keep reading

Related articles from the SudoSecurity blog.