From 9a7aa48e449482f1d41caae6bae3b3862ea1bee7 Mon Sep 17 00:00:00 2001 From: tayadwx <42323260+tayadwx@users.noreply.github.com> Date: Fri, 16 Oct 2026 23:34:13 +0800 Subject: [PATCH] build(docker): mount the Go build cache when building the app image (#4320) The compile step sits after `COPY . .`, so every source change invalidates it. Without a build-cache mount each rebuild regenerates the whole Go compile cache inside that layer (~2.7 GB): it accumulates in the local builder cache, and since CI exports intermediate layers (cache-to: type=gha, mode=max) it is uploaded to the GitHub Actions cache whose per-repository storage limit is a hard 10 GB. Mounting /root/.cache/go-build keeps the cache outside the layer: repeated local builds reuse compiled objects instead of recompiling everything, and the cached/transferred layer shrinks from ~3 GB to ~265 MB (the compiled binary). Multi-stage output is unchanged - the final stage still copies only the binaries and assets it names. Co-authored-by: tayadwx --- docker/Dockerfile.app | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/docker/Dockerfile.app b/docker/Dockerfile.app index db5f307f..d9e205ff 100644 --- a/docker/Dockerfile.app +++ b/docker/Dockerfile.app @@ -86,8 +86,14 @@ RUN --mount=type=cache,target=/usr/local/cargo/registry \ ./scripts/build-anydoc-lib.sh; \ fi -# Build the application with version info +# Build the application with version info. Mount the Go build cache as well as +# the module cache: `COPY . .` invalidates this layer on every source change, +# and without the mount each rebuild regenerates the whole compile cache inside +# the layer (~2.7 GB), which occupies disk locally and is uploaded to the CI +# layer cache. Mounted, the cache lives outside the layer and repeated builds +# reuse compiled objects instead of recompiling from scratch. RUN --mount=type=cache,target=/go/pkg/mod \ + --mount=type=cache,target=/root/.cache/go-build \ if [ "$WITH_ANYDOC" = "1" ]; then \ make build-prod GO_BUILD_TAGS=anydoc; \ else \