Dockerfile: add ALPINE_CACHE image to lock apk versions#4238
Dockerfile: add ALPINE_CACHE image to lock apk versions#4238AkihiroSuda wants to merge 1 commit intomoby:masterfrom
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.
(This change is due to:
There was a problem hiding this comment.
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
...
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.
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 <[email protected]>
5d0f1bc to
0cbda2e
Compare
tonistiigi
left a comment
There was a problem hiding this comment.
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 gccPush: # 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-cacheRepro: 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_CACHEimage contains/etc/apk/cachefor apk files referred from the entire Dockerfile.All the
apk addcommands in the Dockerfile are now executed with the mount forALPINE_CACHEand with--no-network.The
ALPINE_CACHEimage defaults to thealpine-cache-localstage, but can be also set todocker.io/moby/buildkit:${RELEASE}-alpine-cachefor reproducibility.