This is an automated email from the ASF dual-hosted git repository.
klesh pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/devlake.git
The following commit(s) were added to refs/heads/main by this push:
new e32a6e7e9 build(backend): cache Go modules and build output in
Dockerfile.local (#9249)
e32a6e7e9 is described below
commit e32a6e7e97ed84fb4b4a68d07c62ec4d35f67351
Author: Dirk <[email protected]>
AuthorDate: Mon Oct 26 17:31:48 2026 +0100
build(backend): cache Go modules and build output in Dockerfile.local
(#9249)
Download modules in a separate layer keyed on go.mod/go.sum and use
BuildKit cache mounts for the module and build caches in the
mock/swag/plugin/server steps, so a source change no longer re-downloads
all modules and rebuilds every plugin from scratch.
Signed-off-by: DoDiODev <[email protected]>
---
backend/Dockerfile.local | 27 +++++++++++++++++++++------
1 file changed, 21 insertions(+), 6 deletions(-)
diff --git a/backend/Dockerfile.local b/backend/Dockerfile.local
index 68412503e..8651900d5 100644
--- a/backend/Dockerfile.local
+++ b/backend/Dockerfile.local
@@ -51,21 +51,36 @@ RUN go install github.com/vektra/mockery/[email protected]
RUN go install github.com/swaggo/swag/cmd/[email protected]
WORKDIR /app
+
+# Cache Go module downloads in a separate layer (only re-runs when
go.mod/go.sum change)
+COPY go.mod go.sum ./
+RUN --mount=type=cache,target=/go/pkg/mod \
+ go mod download
+
+# Now copy the rest of the source
COPY . /app
ENV GOBIN=/app/bin
ARG TAG=
ARG SHA=
-# Generate mocks and swagger
-RUN make mock
-RUN make swag
+# Generate mocks and swagger (use build cache to speed up swag)
+RUN --mount=type=cache,target=/root/.cache/go-build \
+ --mount=type=cache,target=/go/pkg/mod \
+ make mock
+RUN --mount=type=cache,target=/root/.cache/go-build \
+ --mount=type=cache,target=/go/pkg/mod \
+ make swag
-# Build plugins
-RUN make build-plugin
+# Build plugins (parallel, with persistent Go build cache)
+RUN --mount=type=cache,target=/root/.cache/go-build \
+ --mount=type=cache,target=/go/pkg/mod \
+ make build-plugin
# Build server
-RUN VERSION=${TAG}@${SHA} make build-server
+RUN --mount=type=cache,target=/root/.cache/go-build \
+ --mount=type=cache,target=/go/pkg/mod \
+ VERSION=${TAG}@${SHA} make build-server
FROM debian:bookworm-slim