Skip to content

Commit 87d184e

Browse files
committed
Support reproducible builds (except packages)
See docker-library/official-images issue 16044 - `SOURCE_DATE_EPOCH` is added. The value is consumed by the build scripts to make the binary reproducible. - 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` - For Alpine, `/var/cache/fontconfig` is removed > [!NOTE] > 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 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.2/docs/build-repro.md> > > - To reproduce packages, see the `RUN` instruction hook proposed in > moby/buildkit issue 4576 Signed-off-by: Akihiro Suda <[email protected]>
1 parent f7e3d05 commit 87d184e

File tree

22 files changed

+198
-44
lines changed

22 files changed

+198
-44
lines changed

Dockerfile.template

+15-5
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44
-}}
55
FROM php:{{ env.phpVersion }}-{{ env.variant }}
66

7+
# The global SOURCE_DATE_EPOCH is consumed by commands that are not associated with a source artifact.
8+
# This is not propagated from --build-arg: https://github.com/moby/buildkit/issues/4576#issuecomment-2159501282
9+
ENV SOURCE_DATE_EPOCH 0
10+
711
{{ if env.version != "cli" then ( -}}
812
# persistent dependencies
913
{{ if is_alpine then ( -}}
@@ -15,15 +19,19 @@ RUN set -eux; \
1519
ghostscript \
1620
# Alpine package for "imagemagick" contains ~120 .so files, see: https://github.com/docker-library/wordpress/pull/497
1721
imagemagick \
18-
;
22+
; \
23+
# clean up for reproducibility
24+
rm -rf /var/cache/fontconfig
1925
{{ ) else ( -}}
2026
RUN set -eux; \
2127
apt-get update; \
2228
apt-get install -y --no-install-recommends \
2329
# Ghostscript is required for rendering PDF previews
2430
ghostscript \
2531
; \
26-
rm -rf /var/lib/apt/lists/*
32+
rm -rf /var/lib/apt/lists/* ; \
33+
# clean up for reproducibility
34+
rm -rf /var/log/* /var/cache/ldconfig/aux-cache
2735
{{ ) end -}}
2836
{{ ) else ( -}}
2937
# install wp-cli dependencies
@@ -43,7 +51,7 @@ WORKDIR /var/www/html
4351
RUN set -ex; \
4452
\
4553
{{ if is_alpine then ( -}}
46-
apk add --no-cache --virtual .build-deps \
54+
apk add --no-cache --virtual .build-deps=0 \
4755
$PHPIZE_DEPS \
4856
freetype-dev \
4957
icu-dev \
@@ -120,7 +128,7 @@ RUN set -ex; \
120128
| sort -u \
121129
| awk 'system("[ -e /usr/local/lib/" $1 " ]") == 0 { next } { print "so:" $1 }' \
122130
)"; \
123-
apk add --no-network --virtual .wordpress-phpexts-rundeps $runDeps; \
131+
apk add --no-network --virtual .wordpress-phpexts-rundeps=0 $runDeps; \
124132
apk del --no-network .build-deps; \
125133
{{ ) else ( -}}
126134
# reset apt-mark's "manual" list so that "purge --auto-remove" will remove all build dependencies
@@ -136,6 +144,8 @@ RUN set -ex; \
136144
\
137145
apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false; \
138146
rm -rf /var/lib/apt/lists/*; \
147+
# clean up for reproducibility
148+
rm -rf /var/log/* /var/cache/ldconfig/aux-cache; \
139149
{{ ) end -}}
140150
\
141151
! { ldd "$extDir"/*.so | grep 'not found'; }; \
@@ -244,7 +254,7 @@ ENV WORDPRESS_CLI_SHA512 {{ .sha512 }}
244254

245255
RUN set -ex; \
246256
\
247-
apk add --no-cache --virtual .fetch-deps \
257+
apk add --no-cache --virtual .fetch-deps=0 \
248258
gnupg \
249259
; \
250260
\

beta/php8.1/apache/Dockerfile

+9-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

beta/php8.1/fpm-alpine/Dockerfile

+9-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

beta/php8.1/fpm/Dockerfile

+9-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

beta/php8.2/apache/Dockerfile

+9-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

beta/php8.2/fpm-alpine/Dockerfile

+9-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

beta/php8.2/fpm/Dockerfile

+9-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

beta/php8.3/apache/Dockerfile

+9-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

beta/php8.3/fpm-alpine/Dockerfile

+9-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

beta/php8.3/fpm/Dockerfile

+9-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)