From b128b4d11e2ca6b931b4128c3cfc3eba3ef08e10 Mon Sep 17 00:00:00 2001 From: ShukeBta <272197458+ShukeBta@users.noreply.github.com> Date: Wed, 17 Jun 2026 20:06:09 +0800 Subject: [PATCH] Improve Docker build caching --- .dockerignore | 2 ++ Dockerfile | 9 ++++++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/.dockerignore b/.dockerignore index b56ac1e..1b6a607 100644 --- a/.dockerignore +++ b/.dockerignore @@ -45,6 +45,8 @@ password.* .idea/ .vscode/ .workbuddy/ +.dev-cache/ +.dev-data/ node_modules/ **/node_modules/ web/dist/ diff --git a/Dockerfile b/Dockerfile index 6ac0f78..cae4285 100644 --- a/Dockerfile +++ b/Dockerfile @@ -19,7 +19,8 @@ FROM --platform=$BUILDPLATFORM node:20-alpine AS frontend ARG NPM_CONFIG_REGISTRY=https://registry.npmjs.org/ WORKDIR /app/web COPY web/package*.json ./ -RUN npm ci --registry="${NPM_CONFIG_REGISTRY}" +RUN --mount=type=cache,target=/root/.npm \ + npm ci --registry="${NPM_CONFIG_REGISTRY}" COPY web/ . RUN npm run build @@ -31,10 +32,12 @@ ARG GOPROXY=https://proxy.golang.org,direct ENV GOPROXY=${GOPROXY} WORKDIR /app COPY go.mod go.sum ./ -RUN go mod download +RUN --mount=type=cache,target=/go/pkg/mod \ + go mod download COPY . . COPY --from=frontend /app/web/dist ./web/dist -RUN CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} \ +RUN --mount=type=cache,target=/go/pkg/mod \ + CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} \ go build -trimpath -ldflags="-s -w" -o mediastation-go ./cmd/server # ---- Stage 3: runtime ------------------------------------------------------