@@ -88,20 +88,35 @@ artifact_dir_absolute="$(realpath "$ARTIFACT_DIR")"
8888# --provenance=false keeps a build-time attestation (which embeds the clock and
8989# the runner identity) out of the image. Without both, two builds of identical
9090# source produce different layers and therefore different measurements.
91- docker buildx build --pull --no-cache --provenance=false \
92- --label " org.opencontainers.image.source=https://github.com/${SOURCE_REPOSITORY} " \
93- --label " org.opencontainers.image.revision=${SOURCE_REVISION} " \
94- --label " org.opencontainers.image.version=${VERSION} " \
95- --build-arg " SOURCE_REVISION=${SOURCE_REVISION} " \
96- --build-arg " AWS_REGION=${AWS_REGION} " \
97- --build-arg " KMS_KEY_ARN=${KMS_KEY_ARN} " \
98- -f apps/gateway/Dockerfile.enclave \
99- --output " type=docker,name=${enclave_image} ,rewrite-timestamp=true" \
100- .
91+ #
92+ # The docker driver accepts rewrite-timestamp and ignores it, normalising only
93+ # the config's created field, so it must not be used to cut a release.
94+ # awk must not exit early here: SIGPIPE on docker would abort the script.
95+ builder_driver=" $( docker buildx inspect --bootstrap 2> /dev/null | awk -F' : *' ' /^Driver:/{if (driver == "") driver = $2} END {print driver}' ) " || builder_driver=" "
96+ if [[ " $builder_driver " != " docker-container" ]]; then
97+ printf ' reproducible build check failed: buildx driver is %s, need docker-container\n' \
98+ " ${builder_driver:- unknown} " >&2
99+ printf ' The docker driver silently ignores rewrite-timestamp, so this build would\n' >&2
100+ printf ' produce measurements nobody else can reproduce. Create a builder with:\n' >&2
101+ printf ' docker buildx create --driver docker-container --use\n' >&2
102+ exit 1
103+ fi
104+
105+ build_enclave_image () {
106+ docker buildx build --pull --no-cache --provenance=false \
107+ --label " org.opencontainers.image.source=https://github.com/${SOURCE_REPOSITORY} " \
108+ --label " org.opencontainers.image.revision=${SOURCE_REVISION} " \
109+ --label " org.opencontainers.image.version=${VERSION} " \
110+ --build-arg " SOURCE_REVISION=${SOURCE_REVISION} " \
111+ --build-arg " AWS_REGION=${AWS_REGION} " \
112+ --build-arg " KMS_KEY_ARN=${KMS_KEY_ARN} " \
113+ -f apps/gateway/Dockerfile.enclave \
114+ --output " type=docker,name=$1 ,rewrite-timestamp=true" \
115+ .
116+ }
117+
118+ build_enclave_image " $enclave_image "
101119
102- # A buildx too old to honour rewrite-timestamp would still succeed here and
103- # publish a release that nobody can reproduce, so prove the normalisation
104- # actually applied rather than assuming it did.
105120image_created_epoch=" $( date -u -d " $( docker image inspect --format ' {{.Created}}' " $enclave_image " ) " +%s) "
106121if [[ " $image_created_epoch " != " $SOURCE_DATE_EPOCH " ]]; then
107122 printf ' reproducible build check failed: image timestamp is %s, expected %s\n' \
@@ -111,7 +126,25 @@ if [[ "$image_created_epoch" != "$SOURCE_DATE_EPOCH" ]]; then
111126 exit 1
112127fi
113128
114- docker build --pull \
129+ # A normalised created field is not proof the layers were normalised, so test
130+ # determinism by building twice instead of asserting it in the manifest.
131+ determinism_image=" ${enclave_image} -determinism-check"
132+ build_enclave_image " $determinism_image "
133+ first_image_id=" $( docker image inspect --format ' {{.Id}}' " $enclave_image " ) "
134+ second_image_id=" $( docker image inspect --format ' {{.Id}}' " $determinism_image " ) "
135+ docker image rm -f " $determinism_image " > /dev/null 2>&1 || true
136+ if [[ " $first_image_id " != " $second_image_id " ]]; then
137+ printf ' reproducible build check failed: two builds of %s produced different images\n' \
138+ " $SOURCE_REVISION " >&2
139+ printf ' first: %s\n' " $first_image_id " >&2
140+ printf ' second: %s\n' " $second_image_id " >&2
141+ printf ' Publishing these measurements would break deploy/nitro/verify-build.sh.\n' >&2
142+ exit 1
143+ fi
144+
145+ # --load is required: a docker-container builder leaves results in the build
146+ # cache, and build-enclave below needs the image in the daemon.
147+ docker buildx build --pull --load \
115148 -f deploy/nitro/nitro-cli-builder.Dockerfile \
116149 -t " $nitro_cli_image " \
117150 deploy/nitro
0 commit comments