Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 7684a6b

Browse files
committedMay 2, 2024
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. - 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 Also, Alpine-based images still have the following diff: ```diff diff -ur /tmp/foo/diff/input-0/layers-3/lib/apk/db/installed /tmp/foo/diff/input-1/layers-3/lib/apk/db/installed --- /tmp/foo/diff/input-0/layers-3/lib/apk/db/installed 2024-04-26 07:07:33.000000000 +0900 +++ /tmp/foo/diff/input-1/layers-3/lib/apk/db/installed 2024-04-26 07:07:33.000000000 +0900 @@ -1,4 +1,4 @@ -C:Q1z4Lv7mwS00FpNJwDUHdH70eM2ic= +C:Q1gHSJHNX/rtq0yNsVTKaNb96s8Mk= P:.ruby-rundeps V:0 A:noarch ``` Signed-off-by: Akihiro Suda <akihiro.suda.cz@hco.ntt.co.jp>
1 parent 0d22570 commit 7684a6b

File tree

24 files changed

+183
-25
lines changed

24 files changed

+183
-25
lines changed
 

‎3.0/alpine3.16/Dockerfile

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

‎3.0/bullseye/Dockerfile

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

‎3.0/buster/Dockerfile

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

‎3.0/slim-bullseye/Dockerfile

Lines changed: 10 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎3.0/slim-buster/Dockerfile

Lines changed: 10 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎3.1/alpine3.18/Dockerfile

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

‎3.1/alpine3.19/Dockerfile

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

‎3.1/bookworm/Dockerfile

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

‎3.1/bullseye/Dockerfile

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

‎3.1/slim-bookworm/Dockerfile

Lines changed: 10 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎3.1/slim-bullseye/Dockerfile

Lines changed: 10 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎3.2/alpine3.18/Dockerfile

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

‎3.2/alpine3.19/Dockerfile

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

‎3.2/bookworm/Dockerfile

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

‎3.2/bullseye/Dockerfile

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

‎3.2/slim-bookworm/Dockerfile

Lines changed: 10 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎3.2/slim-bullseye/Dockerfile

Lines changed: 10 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎3.3/alpine3.18/Dockerfile

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

‎3.3/alpine3.19/Dockerfile

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

‎3.3/bookworm/Dockerfile

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

‎3.3/bullseye/Dockerfile

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

‎3.3/slim-bookworm/Dockerfile

Lines changed: 10 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎3.3/slim-bullseye/Dockerfile

Lines changed: 10 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎Dockerfile.template

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ FROM debian:{{ env.variant | ltrimstr("slim-") }}-slim
1313
FROM buildpack-deps:{{ env.variant }}
1414
{{ ) end -}}
1515

16+
# SOURCE_DATE_EPOCH is consumed by build scripts
17+
ARG SOURCE_DATE_EPOCH
18+
1619
{{ if is_alpine then ( -}}
1720
RUN set -eux; \
1821
apk add --no-cache \
@@ -38,7 +41,9 @@ RUN set -eux; \
3841
procps \
3942
zlib1g-dev \
4043
; \
41-
rm -rf /var/lib/apt/lists/*
44+
rm -rf /var/lib/apt/lists/*; \
45+
# clean up for reproducibility
46+
rm -rf /var/log/* /var/cache/ldconfig/aux-cache
4247

4348
{{ ) else "" end -}}
4449
# skip installing gem documentation
@@ -67,7 +72,7 @@ ENV RUBY_DOWNLOAD_SHA256 {{ .sha256.xz }}
6772
RUN set -eux; \
6873
\
6974
{{ if is_alpine then ( -}}
70-
apk add --no-cache --virtual .ruby-builddeps \
75+
apk add --no-cache --virtual .ruby-builddeps=0 \
7176
autoconf \
7277
{{ if [ "3.0", "3.1", "3.2" ] | index(env.version | rtrimstr("-rc")) then ( -}}
7378
{{ # https://github.com/docker-library/ruby/pull/438 -}}
@@ -132,6 +137,8 @@ RUN set -eux; \
132137
{{ ) else "" end -}}
133138
; \
134139
rm -rf /var/lib/apt/lists/*; \
140+
# clean up for reproducibility
141+
rm -rf /var/log/* /var/cache/ldconfig/aux-cache ;\
135142
{{ ) end -}}
136143
{{ if .rust.version then ( -}}
137144
\
@@ -275,7 +282,7 @@ RUN set -eux; \
275282
| sort -u \
276283
| awk 'system("[ -e /usr/local/lib/" $1 " ]") == 0 { next } { print "so:" $1 }' \
277284
)"; \
278-
apk add --no-network --virtual .ruby-rundeps $runDeps; \
285+
apk add --no-network --virtual .ruby-rundeps=0 $runDeps; \
279286
apk del --no-network .ruby-builddeps; \
280287
{{ ) else ( -}}
281288
apt-mark auto '.*' > /dev/null; \
@@ -289,6 +296,8 @@ RUN set -eux; \
289296
| xargs -r apt-mark manual \
290297
; \
291298
apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false; \
299+
# clean up for reproducibility
300+
rm -rf /var/log/* /var/cache/ldconfig/aux-cache ;\
292301
{{ ) end -}}
293302
\
294303
cd /; \

0 commit comments

Comments
 (0)
Please sign in to comment.