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 <tayadwx@users.noreply.github.com>main
parent
e07a190219
commit
9a7aa48e44
|
|
@ -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 \
|
||||
|
|
|
|||
Loading…
Reference in New Issue