cool-easter-32542
03/21/2024, 5:29 PMrewrite-timestamp=true option
Setting the env var SOURCE_DATE_EPOCH also needs to occur so that the dates in the image metadata are stable. It would be nice if pants could derive this from the sources somehow, so that builds across different git commits are stable.
Additional context
Heres a script that showcases this behavior
#!/bin/bash
set -o errexit
set -o nounset
set -o pipefail
set -x trace
cat > Dockerfile.test <<EOF
FROM scratch
COPY test.txt /test.txt
EOF
if [ ! -f test.txt ]; then
touch test.txt
fi
# buildx 0.13 is required for rewrite-timestamp
# <https://github.com/moby/buildkit/blob/master/docs/build-repro.md>
docker buildx create --use --driver-opt image=moby/buildkit:v0.13.1
build_opts="--tag=test:latest --output=type=docker,rewrite-timestamp=true --file=Dockerfile.test"
SOURCE_DATE_EPOCH=1710990413 docker buildx build $build_opts --iidfile=one.txt .
# remove all local caches/images to force a rebuild
docker system prune --all --force
sleep 1
SOURCE_DATE_EPOCH=1710990413 docker buildx build $build_opts --iidfile=two.txt .
if ! diff one.txt two.txt; then
echo "Builds are not reproducible"
exit 1
else
echo "Builds are reproducible!"
fi
pantsbuild/pants