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