Skip to content

Commit b01ab92

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 binary reproducible. - `/tmp/*` is removed as they contain files created by `memcached` - 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` > [!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 8174e5a commit b01ab92

File tree

3 files changed

+39
-9
lines changed

3 files changed

+39
-9
lines changed

1/alpine/Dockerfile

Lines changed: 9 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

1/debian/Dockerfile

Lines changed: 14 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Dockerfile.template

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@ FROM alpine:{{ .alpine.version }}
44
FROM debian:{{ .debian.version }}-slim
55
{{ ) end -}}
66

7+
# SOURCE_DATE_EPOCH is consumed by build scripts
8+
ARG SOURCE_DATE_EPOCH
9+
710
# add our user and group first to make sure their IDs get assigned consistently, regardless of whatever dependencies get added
11+
# On Debian, useradd recognizes SOURCE_DATE_EPOCH to reproduce the "lastchanged" field in /etc/shadow.
812
{{ if env.variant == "alpine" then ( -}}
913
RUN set -eux; \
1014
addgroup -g 11211 memcache; \
@@ -24,7 +28,9 @@ RUN set -eux; \
2428
apt-get install -y --no-install-recommends \
2529
libsasl2-modules \
2630
; \
27-
rm -rf /var/lib/apt/lists/*
31+
rm -rf /var/lib/apt/lists/*; \
32+
# clean up for reproducibility
33+
rm -rf /var/log/* /var/cache/ldconfig/aux-cache
2834
{{ ) end -}}
2935

3036
ENV MEMCACHED_VERSION {{ .version }}
@@ -34,7 +40,7 @@ ENV MEMCACHED_SHA1 {{ .sha1 }}
3440
RUN set -eux; \
3541
\
3642
{{ if env.variant == "alpine" then ( -}}
37-
apk add --no-cache --virtual .build-deps \
43+
apk add --no-cache --virtual .build-deps=0 \
3844
ca-certificates \
3945
coreutils \
4046
cyrus-sasl-dev \
@@ -67,6 +73,8 @@ RUN set -eux; \
6773
wget \
6874
; \
6975
rm -rf /var/lib/apt/lists/*; \
76+
# clean up for reproducibility
77+
rm -rf /var/log/* /var/cache/ldconfig/aux-cache; \
7078
{{ ) end -}}
7179
\
7280
wget -O memcached.tar.gz "$MEMCACHED_URL"; \
@@ -109,7 +117,7 @@ RUN set -eux; \
109117
| sort -u \
110118
| awk 'system("[ -e /usr/local/lib/" $1 " ]") == 0 { next } { print "so:" $1 }' \
111119
)"; \
112-
apk add --no-network --virtual .memcached-rundeps $runDeps; \
120+
apk add --no-network --virtual .memcached-rundeps=0 $runDeps; \
113121
apk del --no-network .build-deps; \
114122
{{ ) else ( -}}
115123
apt-mark auto '.*' > /dev/null; \
@@ -123,9 +131,13 @@ RUN set -eux; \
123131
| xargs -r apt-mark manual \
124132
; \
125133
apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false; \
134+
# clean up for reproducibility
135+
rm -rf /var/log/* /var/cache/ldconfig/aux-cache; \
126136
{{ ) end -}}
127137
\
128-
memcached -V
138+
memcached -V ;\
139+
# clean up for reproducibility
140+
rm -rf /tmp/*
129141

130142
COPY docker-entrypoint.sh /usr/local/bin/
131143
RUN ln -s usr/local/bin/docker-entrypoint.sh /entrypoint.sh # backwards compat

0 commit comments

Comments
 (0)