Repository navigation
fix(docker): keep the runtime layers cached across updates - #704
Open
jedrzejsieracki wants to merge 1 commit into
Open
jedrzejsieracki wants to merge 1 commit into
jedrzejsieracki wants to merge 1 commit into
Conversation
Owner
|
The cache analysis is correct. Please rebase on main (the Dockerfiles changed for the arm64 TARGETARCH fix) and re-run CI; I will review the Dockerfile diff after that. |
jedrzejsieracki
force-pushed
the
fix/dockerfile-build-cache
branch
from
December 2, 2026 12:04
1ad7422 to
1ee5bdd
Compare
The runtime stage declared ARTEX_VERSION and ARTEX_REVISION before its first RUN. A declared build argument is part of the cache key of every later RUN, and update.sh writes the new commit into .env, so every update rebuilt the whole stage: apt packages, bbot, Playwright. That cost 6 to 11 minutes per update and left another ~8 GB copy of the layers in the build cache. Declare the arguments and the LABEL that uses them at the end of the stage instead. Also keep the Go build cache, the Next.js build cache and the npm download cache between builds with BuildKit cache mounts, so a code change recompiles only what changed. The caches are not part of the image. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
jedrzejsieracki
force-pushed
the
fix/dockerfile-build-cache
branch
from
December 2, 2026 12:05
1ee5bdd to
0158dbd
Compare
Author
|
Rebased on main (including the arm64 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Every Docker update rebuilds the whole runtime stage, even when only Go code changed.
Since 869b44a the runtime stage declares
ARTEX_VERSIONandARTEX_REVISIONright afterFROM, before its firstRUN. A declared build argument is part of the cache key of everyRUNafter it, andupdate.shwrites the new commit into.envon every update. So each update reinstalls the apt packages, pip packages, Node, bbot and Playwright, which takes 6 to 11 minutes depending on the machine.It also costs disk. Each rebuild leaves another copy of about 8 GB of layers in the build cache (bbot 3.5 GB, Playwright 2.3 GB, apt 1.6 GB, tools 0.4 GB). On one 63 GB host, four such copies had piled up and BuildKit's cache cleanup kept evicting entries close to its minimum-free-space threshold.
Change
ARGs and theLABELthat uses them move to the end of the runtime stage. The image still carriesorg.opencontainers.image.version/revision, but a new value now only re-stamps the label./root/.cache/go-build), the Next.js build cache (/src/web/.next/cache) and the npm download cache (/root/.npm). A code change recompiles only the affected packages and pages. The caches are not part of the image. The Dockerfile already uses# syntax=docker/dockerfile:1, which supports--mount.go mod downloadkeeps its normal layer, so the module set still comes fromgo.mod/go.sumexactly as before.Testing
Measured with
docker compose build artexon two hosts. Each "new commit" build passes a differentARTEX_VERSION/ARTEX_REVISION, the wayupdate.shdoes. "Before" is the currentmainwith a warm cache.next build6.6s, was 22s)Host B is slower mainly because of image export and unpacking with the containerd image store (about 2 minutes for the 4.5 GB image before this change).
Also checked:
org.opencontainers.image.versionandrevisionlabels.-X main.version/main.revisionlinker flags are unchanged.The cache mounts total about 0.8 GB, which is within BuildKit's default 48h / ~920 MB budget for cache mounts. If the budget is exceeded, BuildKit drops the mount and the next build compiles from scratch, which is the same as today.
🤖 Generated with Claude Code