chore(docker): bake Go module cache into the test-runner image
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.
This commit is contained in:
@@ -42,6 +42,12 @@ RUN --mount=type=cache,target=/root/go/pkg/mod \
|
|||||||
--mount=type=cache,target=/root/.cache/go-build \
|
--mount=type=cache,target=/root/.cache/go-build \
|
||||||
CGO_ENABLED=0 GOOS=linux go build -installsuffix cgo -o main ./cmd/server
|
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
|
# Test runner stage - includes Go runtime and test dependencies
|
||||||
# This stage is ONLY used for running tests, never deployed to production
|
# This stage is ONLY used for running tests, never deployed to production
|
||||||
FROM golang:1.26-alpine AS test-runner
|
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 everything from builder (includes compiled binary, source code, and dependencies)
|
||||||
COPY --from=builder /app ./
|
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
|
# Install kepubify for conversion tests
|
||||||
RUN wget -O /usr/bin/kepubify https://github.com/pgaskin/kepubify/releases/latest/download/kepubify-linux-64bit \
|
RUN wget -O /usr/bin/kepubify https://github.com/pgaskin/kepubify/releases/latest/download/kepubify-linux-64bit \
|
||||||
&& chmod +x /usr/bin/kepubify
|
&& chmod +x /usr/bin/kepubify
|
||||||
|
|||||||
Reference in New Issue
Block a user