forked from ChelseaKR/habitable
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheck_reproducible_relay_image.sh
More file actions
executable file
·65 lines (57 loc) · 2.27 KB
/
Copy pathcheck_reproducible_relay_image.sh
File metadata and controls
executable file
·65 lines (57 loc) · 2.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/usr/bin/env bash
# SPDX-License-Identifier: AGPL-3.0-or-later
# Copyright 2026 Chelsea Kelly-Reif
#
# Build the relay twice from the same tracked source and compare the complete
# OCI archives byte for byte. This proves reproducibility for this pinned base,
# platform, Dockerfile, BuildKit invocation, and Debian archive state; it does
# not claim that unrelated builder versions or CPU architectures emit the same
# bytes.
#
# Debian archive state is on that list because the Dockerfile applies Debian
# security updates over the pinned base digest (see relay/Dockerfile for why the
# digest alone leaves a HIGH CVE unpatched). Both builds here run seconds apart
# against the same archive, so the package set is identical and the comparison
# is meaningful; a rebuild months later, after Debian has published a newer
# security upload, is expected to differ and that difference is the patch
# arriving, not a reproducibility failure.
set -euo pipefail
repo_root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
cd "$repo_root"
for command in docker git tar cmp; do
command -v "$command" >/dev/null || {
echo "error: required executable not found: $command" >&2
exit 2
}
done
docker buildx version >/dev/null
epoch="${SOURCE_DATE_EPOCH:-$(git log -1 --format=%ct)}"
if [[ ! "$epoch" =~ ^[0-9]+$ ]]; then
echo "error: SOURCE_DATE_EPOCH must be an integer Unix timestamp" >&2
exit 2
fi
tmp="$(mktemp -d "${TMPDIR:-/tmp}/habitable-relay-repro.XXXXXX")"
trap 'rm -rf "$tmp"' EXIT
mkdir "$tmp/context"
git archive --format=tar HEAD -- relay/Dockerfile src | tar -xf - -C "$tmp/context"
build() {
local destination="$1"
docker buildx build \
--no-cache \
--provenance=false \
--build-arg "SOURCE_DATE_EPOCH=$epoch" \
--file "$tmp/context/relay/Dockerfile" \
--platform linux/amd64 \
--output "type=oci,dest=$destination,rewrite-timestamp=true" \
"$tmp/context"
}
echo "habitable: verifying reproducible relay image (SOURCE_DATE_EPOCH=$epoch)"
echo " building OCI archive #1..."
build "$tmp/relay-1.tar"
echo " building OCI archive #2..."
build "$tmp/relay-2.tar"
if ! cmp -s "$tmp/relay-1.tar" "$tmp/relay-2.tar"; then
echo "FAIL: relay OCI archives differ byte for byte" >&2
exit 1
fi
echo "habitable: relay OCI archive is byte-identical across clean rebuilds"