The same commit built twice produces images with different digests. Why does that matter, and how do you make builds reproducible?

AdvancedScenarioPipelines at scale
Answer

Situation read → If you can't rebuild the same artifact, you can't verify what's running matches the source, and a rebuild for a hotfix may pull in unexpected changes.

What I'd do →

  1. Pin base images by digest, not tag:
FROM python:3.12-slim@sha256:2f0c...
  1. Use lockfiles and install from them (npm ci, pip install --require-hashes, go.sum).
  2. Avoid apt-get upgrade and unpinned package installs, or pin versions.
  3. Remove timestamps: set SOURCE_DATE_EPOCH and use BuildKit's rewrite-timestamp option so file times are fixed.
SOURCE_DATE_EPOCH=$(git log -1 --format=%ct) docker buildx build \
  --output type=image,name=ecr/api:$SHA,push=true,rewrite-timestamp=true .
  1. Build once and promote the digest anyway, so day-to-day you never depend on rebuilding.

Why → Reproducibility lets you prove an artifact came from a given commit, which is the basis of supply-chain verification.

Interview tip → Even if bit-for-bit reproducibility isn't reached, pinned inputs alone remove most surprises; say that.

All Real-World Interview questions Roadmap: Interview readiness

More on Pipelines at scale