Skip to content

Commit b02e249

Browse files
committed
Support reproducible builds (except packages)
See docker-library/official-images issue 16044 - `ARG SOURCE_DATE_EPOCH` is added. The argument value is consumed by the build scripts to make the `httpd` binary reproducible. - GNU implementation of `wget` is executed with `--no-hsts` to disable creating `/root/.wget-hsts` - For Debian, `/var/log/*` is removed as they contain timestamps - For Debian, `/var/cache/ldconfig/aux-cache` is removed as they contain inode numbers, etc. - For Alpine, virtual package versions are pinned to "0" to eliminate the timestamp-based version numbers that appear in `/etc/apk/world` and `/lib/apk/db/installed` The following topics are NOT covered by this commit: - To reproduce file timestamps in layers, BuildKit has to be executed with `--output type=<TYPE>,rewrite-timestamp=true`. Needs BuildKit v0.13.0-beta1 or later. - To reproduce the base image by the hash, reproducers may: - modify the `FROM` instruction in Dockerfile manually - or, use the `CONVERT` action of source policies to replace the base image. <https://github.com/moby/buildkit/blob/v0.13.0-beta1/docs/build-repro.md> - To reproduce Debian packages, reproducers may: - modify the `RUN` instructions in the Dockerfile to rewrite `/etc/apt/sources.list` to use <http://snapshot.debian.org>, and restore `/etc/apt/sources.list` at the end of the instruction (See the rejected PR 248) - or, specify a custom Dockerfile frontend implementation that rewrites/restores `/etc/apt/sources.list` - or, specify a custom `HTTP_PROXY` that redirects HTTP requests for <http://deb.debian.org> to <http://snapshot.debian.org>. This is less reliable in long-term due to `Acquire::Check-Valid-Until`. Signed-off-by: Akihiro Suda <[email protected]>
1 parent 02a2b56 commit b02e249

File tree

2 files changed

+25
-7
lines changed

2 files changed

+25
-7
lines changed

2.4/Dockerfile

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
FROM debian:bookworm-slim
22

3+
# The global SOURCE_DATE_EPOCH is consumed by commands that are not associated with a source artifact
4+
ARG SOURCE_DATE_EPOCH
5+
36
# add our user and group first to make sure their IDs get assigned consistently, regardless of whatever dependencies get added
47
#RUN groupadd -r www-data && useradd -r --create-home -g www-data www-data
58

@@ -20,7 +23,9 @@ RUN set -eux; \
2023
# https://github.com/docker-library/httpd/issues/209
2124
libldap-common \
2225
; \
23-
rm -rf /var/lib/apt/lists/*
26+
rm -rf /var/lib/apt/lists/* ; \
27+
# clean up for reproducibility
28+
rm -rf /var/log/* /var/cache/ldconfig/aux-cache
2429

2530
ENV HTTPD_VERSION 2.4.59
2631
ENV HTTPD_SHA256 ec51501ec480284ff52f637258135d333230a7d229c3afa6f6c2f9040e321323
@@ -68,7 +73,7 @@ RUN set -eux; \
6873
# if the version is outdated, we have to pull from the archive
6974
https://archive.apache.org/dist/ \
7075
; do \
71-
if wget -O "$f" "$distUrl$distFile" && [ -s "$f" ]; then \
76+
if wget --no-hsts -O "$f" "$distUrl$distFile" && [ -s "$f" ]; then \
7277
success=1; \
7378
break; \
7479
fi; \
@@ -170,7 +175,7 @@ RUN set -eux; \
170175
local patchSha256="$1"; shift; \
171176
ddist "$patchFile" "httpd/patches/apply_to_$HTTPD_VERSION/$patchFile"; \
172177
echo "$patchSha256 *$patchFile" | sha256sum -c -; \
173-
patch -p0 < "$patchFile"; \
178+
patch --set-utc --force -p0 < "$patchFile"; \
174179
rm -f "$patchFile"; \
175180
done; \
176181
}; \
@@ -180,6 +185,10 @@ RUN set -eux; \
180185
CFLAGS="$(dpkg-buildflags --get CFLAGS)"; \
181186
CPPFLAGS="$(dpkg-buildflags --get CPPFLAGS)"; \
182187
LDFLAGS="$(dpkg-buildflags --get LDFLAGS)"; \
188+
SOURCE_DATE_EPOCH="$(find . -type f -exec stat -c '%Y' {} + | sort -nr | head -n1)"; \
189+
export SOURCE_DATE_EPOCH; \
190+
# for logging validation/edification
191+
date --date "@$SOURCE_DATE_EPOCH" --rfc-2822; \
183192
./configure \
184193
--build="$gnuArch" \
185194
--prefix="$HTTPD_PREFIX" \
@@ -225,7 +234,9 @@ RUN set -eux; \
225234
apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false; \
226235
\
227236
# smoke test
228-
httpd -v
237+
httpd -v; \
238+
# clean up for reproducibility
239+
rm -rf /var/log/* /var/cache/ldconfig/aux-cache
229240

230241
# https://httpd.apache.org/docs/2.4/stopping.html#gracefulstop
231242
STOPSIGNAL SIGWINCH

2.4/alpine/Dockerfile

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
FROM alpine:3.20
22

3+
# The global SOURCE_DATE_EPOCH is consumed by commands that are not associated with a source artifact
4+
ARG SOURCE_DATE_EPOCH
5+
36
# ensure www-data user exists
47
RUN set -x \
58
&& adduser -u 82 -D -S -G www-data www-data
@@ -35,7 +38,7 @@ ENV HTTPD_PATCHES=""
3538
# see https://httpd.apache.org/docs/2.4/install.html#requirements
3639
RUN set -eux; \
3740
\
38-
apk add --no-cache --virtual .build-deps \
41+
apk add --no-cache --virtual .build-deps=0 \
3942
apr-dev \
4043
apr-util-dev \
4144
coreutils \
@@ -181,13 +184,17 @@ RUN set -eux; \
181184
local patchSha256="$1"; shift; \
182185
ddist "$patchFile" "httpd/patches/apply_to_$HTTPD_VERSION/$patchFile"; \
183186
echo "$patchSha256 *$patchFile" | sha256sum -c -; \
184-
patch -p0 < "$patchFile"; \
187+
patch --set-utc --force -p0 < "$patchFile"; \
185188
rm -f "$patchFile"; \
186189
done; \
187190
}; \
188191
patches $HTTPD_PATCHES; \
189192
\
190193
gnuArch="$(dpkg-architecture --query DEB_BUILD_GNU_TYPE)"; \
194+
SOURCE_DATE_EPOCH="$(find . -type f -exec stat -c '%Y' {} + | sort -nr | head -n1)"; \
195+
export SOURCE_DATE_EPOCH; \
196+
# for logging validation/edification
197+
date --date "@$SOURCE_DATE_EPOCH" --rfc-2822; \
191198
./configure \
192199
--build="$gnuArch" \
193200
--prefix="$HTTPD_PREFIX" \
@@ -219,7 +226,7 @@ RUN set -eux; \
219226
| sort -u \
220227
| awk 'system("[ -e /usr/local/lib/" $1 " ]") == 0 { next } { print "so:" $1 }' \
221228
)"; \
222-
apk add --no-network --virtual .httpd-so-deps $deps; \
229+
apk add --no-network --virtual .httpd-so-deps=0 $deps; \
223230
apk del --no-network .build-deps; \
224231
\
225232
# smoke test

0 commit comments

Comments
 (0)