From 877433ed605d861e0c9210fa97723abe20542509 Mon Sep 17 00:00:00 2001 From: silverwind Date: Sun, 8 Mar 2026 11:56:39 +0100 Subject: [PATCH 1/2] Optimize Docker build with dependency layer caching Copy dependency manifests (package.json, pnpm-lock.yaml, .npmrc for npm; go.mod, go.sum for Go) before the full source copy so that dependency installation gets its own cached layer. When only source code changes, the dependency layers are reused. Also remove the GOPROXY=direct override which was bypassing the Go module proxy, causing build failures when gitea.com was unreachable. The Go default (https://proxy.golang.org,direct) is now used instead. Co-Authored-By: Claude (Opus 4.6) --- Dockerfile | 11 ++++++----- Dockerfile.rootless | 11 ++++++----- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/Dockerfile b/Dockerfile index f71b13e8f3ca8..a4c3640b97240 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,14 +3,14 @@ FROM --platform=$BUILDPLATFORM docker.io/library/golang:1.26-alpine3.23 AS frontend-build RUN apk --no-cache add build-base git nodejs pnpm WORKDIR /src +COPY package.json pnpm-lock.yaml .npmrc ./ +RUN --mount=type=cache,target=/root/.local/share/pnpm/store pnpm install --frozen-lockfile COPY --exclude=.git/ . . -RUN --mount=type=cache,target=/root/.local/share/pnpm/store make frontend +RUN touch node_modules && make frontend # Build backend for each target platform FROM docker.io/library/golang:1.26-alpine3.23 AS build-env -ARG GOPROXY=direct - ARG GITEA_VERSION ARG TAGS="sqlite sqlite_unlock_notify" ENV TAGS="bindata timetzdata $TAGS" @@ -22,14 +22,15 @@ RUN apk --no-cache add \ git WORKDIR ${GOPATH}/src/code.gitea.io/gitea +COPY go.mod go.sum ./ +RUN go mod download # Use COPY instead of bind mount as read-only one breaks makefile state tracking and read-write one needs binary to be moved as it's discarded. # ".git" directory is mounted separately later only for version data extraction. COPY --exclude=.git/ . . COPY --from=frontend-build /src/public/assets public/assets # Build gitea, .git mount is required for version data -RUN --mount=type=cache,target=/go/pkg/mod \ - --mount=type=cache,target="/root/.cache/go-build" \ +RUN --mount=type=cache,target="/root/.cache/go-build" \ --mount=type=bind,source=".git/",target=".git/" \ make backend diff --git a/Dockerfile.rootless b/Dockerfile.rootless index bc210132c5377..4fdd66afb76c4 100644 --- a/Dockerfile.rootless +++ b/Dockerfile.rootless @@ -3,14 +3,14 @@ FROM --platform=$BUILDPLATFORM docker.io/library/golang:1.26-alpine3.23 AS frontend-build RUN apk --no-cache add build-base git nodejs pnpm WORKDIR /src +COPY package.json pnpm-lock.yaml .npmrc ./ +RUN --mount=type=cache,target=/root/.local/share/pnpm/store pnpm install --frozen-lockfile COPY --exclude=.git/ . . -RUN --mount=type=cache,target=/root/.local/share/pnpm/store make frontend +RUN touch node_modules && make frontend # Build backend for each target platform FROM docker.io/library/golang:1.26-alpine3.23 AS build-env -ARG GOPROXY=direct - ARG GITEA_VERSION ARG TAGS="sqlite sqlite_unlock_notify" ENV TAGS="bindata timetzdata $TAGS" @@ -22,13 +22,14 @@ RUN apk --no-cache add \ git WORKDIR ${GOPATH}/src/code.gitea.io/gitea +COPY go.mod go.sum ./ +RUN go mod download # See the comments in Dockerfile COPY --exclude=.git/ . . COPY --from=frontend-build /src/public/assets public/assets # Build gitea, .git mount is required for version data -RUN --mount=type=cache,target=/go/pkg/mod \ - --mount=type=cache,target="/root/.cache/go-build" \ +RUN --mount=type=cache,target="/root/.cache/go-build" \ --mount=type=bind,source=".git/",target=".git/" \ make backend From 03a4ad50b99ff5cd1c61b8a7be88b6dda05036b6 Mon Sep 17 00:00:00 2001 From: silverwind Date: Sun, 8 Mar 2026 12:00:56 +0100 Subject: [PATCH 2/2] Remove unnecessary touch node_modules The node_modules directory created by pnpm install always has a newer mtime than the pnpm-lock.yaml copied from the build context, so make already sees node_modules as up-to-date. Co-Authored-By: Claude (Opus 4.6) --- Dockerfile | 2 +- Dockerfile.rootless | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index a4c3640b97240..9922cee9c412e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -6,7 +6,7 @@ WORKDIR /src COPY package.json pnpm-lock.yaml .npmrc ./ RUN --mount=type=cache,target=/root/.local/share/pnpm/store pnpm install --frozen-lockfile COPY --exclude=.git/ . . -RUN touch node_modules && make frontend +RUN make frontend # Build backend for each target platform FROM docker.io/library/golang:1.26-alpine3.23 AS build-env diff --git a/Dockerfile.rootless b/Dockerfile.rootless index 4fdd66afb76c4..a1742e3d51f13 100644 --- a/Dockerfile.rootless +++ b/Dockerfile.rootless @@ -6,7 +6,7 @@ WORKDIR /src COPY package.json pnpm-lock.yaml .npmrc ./ RUN --mount=type=cache,target=/root/.local/share/pnpm/store pnpm install --frozen-lockfile COPY --exclude=.git/ . . -RUN touch node_modules && make frontend +RUN make frontend # Build backend for each target platform FROM docker.io/library/golang:1.26-alpine3.23 AS build-env