Reproducible Builds
Same Source, Different Artifact
Developer toolingdeveloper tooling / build systems
The scenario
Prod is on fire. You need to roll back to v1.4.2, but the registry garbage-collected the image. No problem: git checkout v1.4.2, rebuild, push.
The new image digest is sha256:9f3c... Prod's audit log says v1.4.2 was sha256:41ab... Same commit. Same Dockerfile. Different bytes.
Now you cannot answer the only question that matters: "is this the code that was running?" Your supply-chain attestation just became a sticky note.
Same root cause also explains a slower daily pain: your CI cache never hits, because every layer hash changes on every run.
The four things that leak into your artifact
1️⃣ Timestamps — tar, zip and gzip embed mtime. Two builds a second apart = two different tarballs with identical content.
2️⃣ File order — tar takes files in readdir() order, which is inode order, which is not stable across machines.
3️⃣ Build paths & env — Go and C bake $PWD into debug info. /home/hamza/app vs /github/workspace = different binary.
4️⃣ Floating inputs — FROM node:20 is a moving tag. pip install requests resolves to whatever shipped this morning.
The fixes, concretely
export SOURCE_DATE_EPOCH=$(git log -1 --format=%ct) # commit time, not now()
tar --sort=name \
--mtime="@$SOURCE_DATE_EPOCH" \
--owner=0 --group=0 --numeric-owner \
-cf dist.tar dist/ && gzip -n dist.tar
go build -trimpath -ldflags="-buildid=" ./cmd/api
# C/C++: -fdebug-prefix-map=$PWD=/src
# Pin the base by digest, not tag:
# FROM node:20.11.1@sha256:a1b2c3...
LC_ALL=C is also worth exporting — sort order and some codegen depend on locale.
The 60-second test you can run today
sha256sum dist/app
rm -rf dist && make clean && make
sha256sum dist/app
Different? Find out why without guessing:
diffoscope build-a.tar.gz build-b.tar.gz
It will tell you literally "mtime: 2026-11-10 06:15 vs 06:17" or "file order differs". For images: docker save each, then diffoscope the tarballs.
The nuance people get wrong
"Reproducible" is not the goal. The goal is: the output digest is a pure function of the declared inputs. Bit-identical output is just the proof.
And reproducible ≠ hermetic. Hermetic means the build can't see the host (no system python, no network fetches, no $HOME). Hermeticity is how you get reproducibility reliably — otherwise you're playing whack-a-mole with leaks forever.
Also: stop chasing 100%. Getting your release tarball and your container layers deterministic buys you rollback confidence and cache hits. Making your entire 400-package dependency tree bit-identical is a research project.
Your exercise
Build your main artifact twice in a row in a clean tree and sha256sum both.
If they match: change nothing, add the double-build + checksum compare as a CI step so it stays true.
If they differ: run diffoscope on the two outputs and find the FIRST reported difference. Which of the four leaks was it — time, order, path, or a floating input? That one answer tells you more about your build system than a week of reading its docs.