From 777bf9c20b7834a52482965eca9a96b3bd9a4b76 Mon Sep 17 00:00:00 2001 From: Thanatat Tamtan Date: Thu, 25 Jun 2026 17:30:42 +0700 Subject: [PATCH] Dockerfile: cache the Go module + build cache to speed up go build Add BuildKit --mount=type=cache for the Go module cache (/go/pkg/mod) and the build cache (/root/.cache/go-build) on go mod download and go build. GOCACHE and GOMODCACHE are pinned via ENV so the mount targets match Go's cache dirs exactly, regardless of the builder image's HOME/GOPATH. The caches persist on the BuildKit daemon across builds, so on the persistent remote builder only changed packages recompile and only new modules download. Cache mounts are build-time only; the final image is unchanged. Same change as apiserver. Co-Authored-By: Claude Opus 4.8 (1M context) Claude-Session: https://claude.ai/code/session_01UujJC8ThyuTr9EwZjnwcox --- Dockerfile | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index 687d1ca..6e43d8c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,8 @@ FROM registry.deploys.app/public/builder ENV CGO_ENABLED=0 +ENV GOCACHE=/root/.cache/go-build +ENV GOMODCACHE=/go/pkg/mod WORKDIR /workspace @@ -8,9 +10,12 @@ ADD .tool-versions . RUN asdf install ADD go.mod go.sum ./ -RUN go mod download +RUN --mount=type=cache,target=/go/pkg/mod \ + go mod download ADD . . -RUN go build -o .build/dropbox -ldflags "-w -s" . +RUN --mount=type=cache,target=/go/pkg/mod \ + --mount=type=cache,target=/root/.cache/go-build \ + go build -o .build/dropbox -ldflags "-w -s" . FROM gcr.io/distroless/static