From 077afaca563991d55f363a2db7b306bac790b1e3 Mon Sep 17 00:00:00 2001 From: John O'Keefe Date: Mon, 21 Sep 2026 18:10:17 -0400 Subject: [PATCH] chore(docker): bake Go module cache into the test-runner image MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The test-runner stage copied only /app from the builder, but the Go module cache lives in /go/pkg/mod (GOMODCACHE) — the cache mounts used by the builder target /root/go/pkg/mod, which the go tool ignores, so those mounts never held anything. Every `compose run tests` / make test-integration invocation therefore re-downloaded all dependencies from the network, making integration runs slow and timeout-prone. The builder now materializes /go/pkg/mod into an image layer (go-module-cache) after the binary build, and the test-runner stage restores it to /go/pkg/mod before running tests. Test-only stage; the production final stage is unaffected. --- Dockerfile | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/Dockerfile b/Dockerfile index 1b7c8d9..92dc257 100644 --- a/Dockerfile +++ b/Dockerfile @@ -42,6 +42,12 @@ RUN --mount=type=cache,target=/root/go/pkg/mod \ --mount=type=cache,target=/root/.cache/go-build \ CGO_ENABLED=0 GOOS=linux go build -installsuffix cgo -o main ./cmd/server +# Materialize the Go module cache into an image layer so the test-runner +# stage can restore it. GOMODCACHE is /go/pkg/mod; cache mounts elsewhere are +# ignored by the go tool, and without this copy `go test` in the tests +# container re-downloads every dependency on each invocation. +RUN cp -r /go/pkg/mod /app/go-module-cache + # Test runner stage - includes Go runtime and test dependencies # This stage is ONLY used for running tests, never deployed to production FROM golang:1.26-alpine AS test-runner @@ -53,6 +59,9 @@ WORKDIR /app # Copy everything from builder (includes compiled binary, source code, and dependencies) COPY --from=builder /app ./ +# Restore the materialized Go module cache so `go test` works offline. +RUN mkdir -p /go/pkg/mod && cp -r /app/go-module-cache/. /go/pkg/mod/ && rm -rf /app/go-module-cache + # Install kepubify for conversion tests RUN wget -O /usr/bin/kepubify https://github.com/pgaskin/kepubify/releases/latest/download/kepubify-linux-64bit \ && chmod +x /usr/bin/kepubify