Repository navigation
Fetch all sources in a download stage ahead of the build - #840
Dummgelaufen007 wants to merge 2 commits into
Conversation
wader
left a comment
There was a problem hiding this comment.
Interesting idea. Some things that makes me a bit reluctant:
- Added complexity of the Dockerfile
- Does any of the changes require modern docker version?
- How big is the problem with failed downloads in practice?
| ARG APK_OPTS="" | ||
| RUN apk add --no-cache $APK_OPTS bash wget git | ||
| COPY --from=downloads / /downloads/ | ||
| ARG DOCKERFILE=Dockerfile |
There was a problem hiding this comment.
This would break if Dockerfile was named something else? if so is there way to know the name somehow? thinking about the case where ppl copy and rename it
There was a problem hiding this comment.
Yes, that is the one catch, and I found no way around it: Docker does not pass the name given with -f into the build. It is the price of the inline solution: the download stage reads the ARGs from the Dockerfile itself, so that every library keeps them next to its recipe instead of in a second list, and for that it needs the file's name. A renamed copy is built with -f <name> --build-arg DOCKERFILE=<name>.
If the build arg is forgotten, the build does not go on blindly. The download stage names the file it reads in its first log line, and stops before the first download if that file has no download stage. If there is no file of that name at all, the build stops right at the start with "/Dockerfile": not found.
Research and wording by Claude (Anthropic), directed and reviewed by me.
| # bump: alpine /ALPINE_VERSION=alpine:([\d.]+)/ docker:alpine|^3 | ||
| # bump: alpine link "Release notes" https://alpinelinux.org/posts/Alpine-$LATEST-released.html | ||
| ARG ALPINE_VERSION=alpine:3.24.2 | ||
| FROM scratch AS downloads |
There was a problem hiding this comment.
not sure i follow here, what's the use of the downloads target? the copy below copies no files (scratch) i think and even further down downloaded files are copied from the downloader image
There was a problem hiding this comment.
You're right, in a normal build it did nothing. It was there for an optional local cache of the sources, which made the PR more complicated than it needed to be and is of no use in CI, so I have taken it out.
Research and wording by Claude (Anthropic), directed and reviewed by me.
…e the first download
|
Thanks for looking at it, and you were right about the complexity. That was my fault: the first version did too much at once. I have reworked the download stage along KISS (Keep It Smart and Simple) and removed everything it did not need, so that it only fetches the sources. Added complexity. The PR moves code more than it adds any: the download step that every recipe wrote out by hand now exists once, and the recipes start where they unpack or enter their source. A new library only needs its In lines:
vmaf as an example, before: ARG VMAF_VERSION=3.2.1
ARG VMAF_URL="https://github.com/Netflix/vmaf/archive/refs/tags/v$VMAF_VERSION.tar.gz"
ARG VMAF_SHA256=5df7386911bc15fd1ca783132528748d219768ae4fc5f8e0b61184f041648092
RUN \
wget $WGET_OPTS -O vmaf.tar.gz "$VMAF_URL" && \
echo "$VMAF_SHA256 vmaf.tar.gz" | sha256sum -c - && \
tar $TAR_OPTS vmaf.tar.gz && cd vmaf-*/libvmaf && \
meson setup build \With the file name in ARG VMAF_VERSION=3.2.1
ARG VMAF_URL="https://github.com/Netflix/vmaf/archive/refs/tags/v$VMAF_VERSION.tar.gz"
ARG VMAF_FILE="vmaf.$VMAF_VERSION.tar.gz"
ARG VMAF_SHA256=5df7386911bc15fd1ca783132528748d219768ae4fc5f8e0b61184f041648092
RUN \
wget $WGET_OPTS -O "$VMAF_FILE" "$VMAF_URL" && \
echo "$VMAF_SHA256 $VMAF_FILE" | sha256sum -c - && \
tar $TAR_OPTS $VMAF_FILE && cd vmaf-*/libvmaf && \
meson setup build \So these two lines are the same for every archive, and the download stage runs them once for all of them. After: ARG VMAF_VERSION=3.2.1
ARG VMAF_URL="https://github.com/Netflix/vmaf/archive/refs/tags/v$VMAF_VERSION.tar.gz"
ARG VMAF_FILE="vmaf.$VMAF_VERSION.tar.gz"
ARG VMAF_SHA256=5df7386911bc15fd1ca783132528748d219768ae4fc5f8e0b61184f041648092
RUN \
tar $TAR_OPTS $VMAF_FILE && cd vmaf-*/libvmaf && \
meson setup build \Docker version. A plain Failed downloads in practice. They happen regularly, and today they show up late, after part of the build has already run. With the download stage, nothing is compiled until every source is downloaded and verified, so a failed download shows up after about 1.5 minutes. The stage does not make failures rarer, and it does not make the build slower: it runs alongside the builder's I went through the failed CI and Multi arch runs whose logs are still kept, from 2026-07-14 to 2026-10-15: 21 of them failed on a download.
These jobs ran for up to 29 minutes before they failed. Research and wording by Claude (Anthropic), directed and reviewed by me. |
|
Closing in favour of #841. Research and wording by Claude (Anthropic), directed and reviewed by me. |
52 recipes today start by fetching their own source:
wgetandsha256sumfor 47 archives,git cloneandgit checkoutfor 5 git sources. These lines go away from the recipes, so there is less code, and one step at the start of the build fetches all sources at once. The layout of the Dockerfile stays as it is: each recipe keeps itsARGs and starts where it unpacks or enters its source.Why
Every source is fetched and verified before anything is compiled. A server that is down or an archive that fails its checksum stops the build in its first minutes, not midway through the compile steps.
One download step that works the same for every recipe only has to be right once. Today every recipe has its own, and a typo in one of them shows up when the build reaches that recipe and then has to be found. Now it shows up before the first download, with the file and line to look at.
Every library keeps its arguments in one place
No
ARGmoves to the top of the file and there is no second list of sources. Version, URL, checksum and bump lines stay with their recipe, as they are today:The download stage works its way through the Dockerfile being built and finds its work there: every
<NAME>_URL, together with<NAME>_FILEand<NAME>_SHA256for an archive, or<NAME>_COMMITand<NAME>_DIRfor a git source. A new library needs nothing in the download stage; itsARGs next to the recipe are enough. A bump touches the same lines as before.How it works
COPY $DOCKERFILE /DockerfileARGs where they standdownloaderstageARGs a download needs and walks over every<NAME>_URL. With a<NAME>_FILEit is an archive: fetched and checked against<NAME>_SHA256. Without one it is a git source: cloned treeless and checked out at<NAME>_COMMITinto<NAME>_DIR; a commit that is not a full hash is an error. fdk-aac is skipped unlessENABLE_FDKAACis setCOPY --from=downloader /downloads/ /Mistakes show up before the first download
A wrong setup should cost seconds, not a build, and the message should say where to look. Whoever adds a library or bumps one by hand learns within a second whether its
ARGs are complete, instead of after the build has reached its recipe.-finto the build, so someone who builds a renamed copy and forgets--build-arg DOCKERFILE=<name>would otherwise get the downloads of whatever file is calledDockerfile. The download stage therefore names the file it reads in its first log line, and stops at once if that file has no download stage.ARGs. A new library with a<NAME>_URLbut no checksum yet, or a git source without its commit, would fail somewhere insidewget,sha256sumorgit, with a message that does not say which recipe is wrong. All sources are checked before the first download, and each incomplete one is reported as<file>:<line>: ARGs of <NAME> incomplete, with the line of its<NAME>_URL.Changes
Dockerfiledownloaderstage added beforebuilder, and theCOPY --from=downloaderafter the builder'sapk addDockerfileARG <NAME>_FILElines added, one per archive, each named<name>.<version>.<ext>, with the extension of its URL; thetarline unpacks$<NAME>_FILEDockerfileARG <NAME>_DIRlines added, one per git source, each named<repository>-<commit>; the recipe changes into it instead of a directory name written into itscdDockerfilewgetandsha256sumremoved from 47 recipes,git cloneandgit checkoutfrom 5.<NAME>_URL,<NAME>_SHA256,<NAME>_VERSIONand the bump lines are unchangedDockerfileX264_VERSIONrenamed toX264_COMMIT, in its bump line and inversions.jsontoo: it holds a commit, and every other git source names that<NAME>_COMMITDockerfile--filter=tree:0 --no-checkoutinstead of in full: every commit is still there, so a version counted from the history (x264version.sh) stays the same, only the trees of older commits are left out. A server that does not support the filter, like git.ffmpeg.org overgit://, ignores it and sends the full cloneDockerfileWGET_OPTSgains--progress=dot:mega: all downloads now share one stepThe checksum is now checked the same way for every archive.
Build args
DOCKERFILEDockerfile-fTested
Alpine 3.24.2, the download stage on its own (
--target downloader) withENABLE_FDKAAC=1: fetched and verified all 47 archives, fdk-aac included, and cloned the 5 git sources at their commits.Both checks were tried on broken copies of the Dockerfile: a renamed file built without
--build-arg DOCKERFILE, and sources with a missing checksum, commit, directory or file name, or with nothing but a URL. Each stopped the build before the first download. The first named the file it had read, the others the file and line of the source's<NAME>_URL.Research and wording by Claude (Anthropic), directed and reviewed by me.