Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Work around COPY --link limitations by pre-creating full filesystem tree #521

Merged
merged 1 commit into from
Jun 13, 2024

Conversation

tianon
Copy link
Member

@tianon tianon commented Jun 13, 2024

Without this, COPY --link insists on creating /usr and /usr/local for us, and does so with non-reproducible timestamps, defeating the purpose of our carefully crafted reproducible /usr/local/go -- this combats that by pre-creating a full /target directory that includes /target/usr/local/go so we can COPY --link /target/ / and get a properly reproducible layer.

I've also added more sanity checks to validate our reproducibility assumptions (namely that our detected SOURCE_DATE_EPOCH value is older than our build/wall clock and that no files in our final tree are newer than our SOURCE_DATE_EPOCH).

See also #505

… tree

Without this, `COPY --link` insists on creating `/usr` and `/usr/local` for us, and does so with non-reproducible timestamps, defeating the purpose of our carefully crafted reproducible `/usr/local/go` -- this combats that by pre-creating a full `/target` directory that includes `/target/usr/local/go` so we can `COPY --link /target/ /` and get a *properly* reproducible layer.

I've also added more sanity checks to validate our reproducibility assumptions (namely that our detected `SOURCE_DATE_EPOCH` value is older than our build/wall clock and that no files in our final tree are newer than our `SOURCE_DATE_EPOCH`).
@tianon
Copy link
Member Author

tianon commented Jun 13, 2024

Anyone following along at home can do something like the following to verify this:

$ docker buildx --builder foo build https://github.com/docker-library/golang.git#refs/pull/521/head:1.22/bookworm --output type=oci --quiet | tar -tv | grep 060aaf7efd0676cdf56165fe26e63a047d7f3c483ab1043d530db9370e6c28e7
-r--r--r-- 0/0        69345548 1969-12-31 16:00 blobs/sha256/060aaf7efd0676cdf56165fe26e63a047d7f3c483ab1043d530db9370e6c28e7

Replacing bookworm with any of bullseye, alpine3.20, or alpine3.19 should also work and return that exact same layer digest.

@tianon
Copy link
Member Author

tianon commented Jun 13, 2024

$ docker buildx --builder foo build https://github.com/docker-library/golang.git#refs/pull/521/head:1.22/bookworm --output type=oci --quiet | tar -x --to-stdout blobs/sha256/060aaf7efd0676cdf56165fe26e63a047d7f3c483ab1043d530db9370e6c28e7 | tar -tvz | grep -E ' usr(/local(/go)?)?/$'
drwxr-xr-x 0/0               0 2024-05-30 12:26 usr/
drwxr-xr-x 0/0               0 2024-05-30 12:26 usr/local/
drwxr-xr-x 0/0               0 2024-05-30 12:26 usr/local/go/

vs:

$ crane blob golang@sha256:69828e165440b00c6a6cf1cc039b1812b75b8604568728dccd4d39573d405e26 | tar -tvz | grep -E ' usr(/local(/go)?)?/$'
drwxr-xr-x 0/0               0 2024-06-13 11:14 usr/
drwxr-xr-x 0/0               0 2024-06-13 11:14 usr/local/
drwxr-xr-x 0/0               0 2024-05-30 12:26 usr/local/go/

@tianon tianon merged commit 1a33f8b into docker-library:master Jun 13, 2024
14 checks passed
@tianon tianon deleted the copy-link-redux branch June 13, 2024 22:43
docker-library-bot added a commit to docker-library-bot/official-images that referenced this pull request Jun 13, 2024
Changes:

- docker-library/golang@1a33f8b: Merge pull request docker-library/golang#521 from infosiftr/copy-link-redux
- docker-library/golang@81c0d31: Work around `COPY --link` limitations by pre-creating full filesystem tree
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants