-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Dockerfile: add ALPINE_CACHE image to lock apk versions #4238
Conversation
FROM alpine:${ALPINE_VERSION} AS alpine-s390x | ||
FROM alpine:${ALPINE_VERSION} AS alpine-ppc64le | ||
FROM alpine:edge@sha256:2d01a16bab53a8405876cec4c27235d47455a7b72b75334c614f2fb0968b3f90 AS alpine-riscv64 | ||
FROM --platform=amd64 alpine:${ALPINE_VERSION} AS alpine-amd64 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(This change is due to:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you need to set the base first with build platform:
FROM --platform=$BUILDPLATFORM alpine:${ALPINE_VERSION} AS alpine
FROM alpine AS alpine-amd64
...
Pretty much like https://github.com/moby/moby/pull/44735/files#diff-dd2c0eb6ea5cfc6c4bd4eac30934e2d5746747af48fef6da689e85b752f39557R40-R52
Dockerfile
Outdated
# alpine-cache-local is the stage to collect apk cache files. | ||
# This stage can be pushed for sake of reproducible builds. | ||
FROM scratch AS alpine-cache-local | ||
COPY --from=alpine-cache-local-base /etc/apk/cache /etc/apk/cache |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Eventually we want to "unsquash" the /etc/apk/cache
layer to multiple layers in the apk file granularity to help deduplicating the layer blobs:
2f9bca7
to
5d0f1bc
Compare
The `ALPINE_CACHE` image contains `/etc/apk/cache` for apk files referred from the entire Dockerfile. All the `apk add` commands in the Dockerfile are now executed with the mount for `ALPINE_CACHE` and with `--no-network`. The `ALPINE_CACHE` image defaults to the `alpine-cache-local` stage, but can be also set to `docker.io/moby/buildkit:${RELEASE}-alpine-cache` for reproducibility. Signed-off-by: Akihiro Suda <akihiro.suda.cz@hco.ntt.co.jp>
5d0f1bc
to
0cbda2e
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks like way too much extra work for a very custom behavior. I think instead, we should a "material-attestation" and that would save the snapshots. Currently, in provenance we have digests for the materials, but we could also have a separate manifest that would allow pulling all these digests from the registry.
Could you elaborate? How will the Dockerfile and the build command look like? |
I think we've discussed this in the past. Maybe in slack. For alpine you would need something like https://github.com/tonistiigi/buildkit-alpine . Eg. this is an example image https://explore.ggcr.dev/?image=tonistiigi%2Ftest:alpine-curl . If you look at the provenance attestation then there are individual alpine packages all there with their checksums. The missing piece would be to also push the blobs to the registry and then you can use the source policy rule that converts from https URL or apk package into the same blob in registry. |
Yes, but how is this expected to be integrated to the Dockerfile syntax? |
You can use |
For anything that gets too custom in the package manger territory, it is easier to implement such things with full frontend API rather that let the user hack something together with Dockerfile limitations. We get lot of consistency for free like provenance materials detection and verification, unified storage and automatic snapshot loading from previous provenance via source policies. Doing this by hand doesn't have any of such guarantees/features. |
Copying what we discussed in Slack here: Example:
|
Alternatively, we may just support OCI exporter for cache mounts and call it a day. Dockerfile: FROM alpine:3.18@sha256:deadbeef
RUN --mount=type=cache,target=/etc/apk/cache,id=etc-apk-cache \
apk add gcc Push: # orasify=true ORAS-ifies the cache blobs for deduplication.
# (1 blob = 1 apk file)
# This option should be optional.
docker buildx build . \
--push \
-t example.com/myimage:v1.2.3 \
--cache-to type=oci,orasify=true,cache-mount-id=etc-apk-cache,target=example.com/myimage:v1.2.3-etc-apk-cache Repro: docker buildx build . \
--cache-from type=oci,cache-mount-id=etc-apk-cache,src=example.com/myimage:v1.2.3-etc-apk-cache |
Opened an issue to continue the discussion |
The
ALPINE_CACHE
image contains/etc/apk/cache
for apk files referred from the entire Dockerfile.All the
apk add
commands in the Dockerfile are now executed with the mount forALPINE_CACHE
and with--no-network
.The
ALPINE_CACHE
image defaults to thealpine-cache-local
stage, but can be also set todocker.io/moby/buildkit:${RELEASE}-alpine-cache
for reproducibility.