diff --git a/.dockerignore b/.dockerignore index 8e0d6b3666..16a13794bf 100644 --- a/.dockerignore +++ b/.dockerignore @@ -74,7 +74,8 @@ cpu.out /VERSION /.air /.go-licenses - +Dockerfile +Dockerfile.rootless # Files and folders that were previously generated /public/assets/img/webpack diff --git a/Dockerfile b/Dockerfile index d069f8a4da..a8415e8a18 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,3 +1,4 @@ +# syntax=docker/dockerfile:1 # Build stage FROM docker.io/library/golang:1.25-alpine3.22 AS build-env @@ -16,46 +17,15 @@ RUN apk --no-cache add \ pnpm WORKDIR ${GOPATH}/src/code.gitea.io/gitea - -COPY Makefile . - -# Fetch go dependencies -COPY go.mod go.sum ./ -RUN --mount=type=cache,target=/go/pkg/mod \ - go mod download - -# Fetch pnpm dependencies -COPY package.json pnpm-lock.yaml ./ -RUN --mount=type=cache,target=/root/.local/share/pnpm/store \ - pnpm install --frozen-lockfile --prod - -COPY ./webpack.config.ts tailwind.config.ts ./ -COPY ./assets ./assets -COPY ./public ./public -COPY ./web_src ./web_src - -RUN make frontend - -# Copy source files -COPY ./build ./build -COPY ./cmd ./cmd -COPY ./models ./models -COPY ./modules ./modules -COPY ./options ./options -COPY ./routers ./routers -COPY ./services ./services -COPY ./templates ./templates -COPY ./build.go . -COPY ./main.go . -COPY contrib/environment-to-ini/environment-to-ini.go contrib/environment-to-ini/environment-to-ini.go -COPY ./custom ./custom +COPY --exclude=.git/ . . # Checkout version if set RUN --mount=type=cache,target=/go/pkg/mod \ --mount=type=cache,target="/root/.cache/go-build" \ - --mount=type=bind,source=".git",target="${GOPATH}/src/code.gitea.io/gitea/.git" \ + --mount=type=cache,target=/root/.local/share/pnpm/store \ + --mount=type=bind,source=".git/",target=".git/" \ if [ -n "${GITEA_VERSION}" ]; then git checkout "${GITEA_VERSION}"; fi \ - && make backend + && make # Begin env-to-ini build RUN --mount=type=cache,target=/go/pkg/mod \ diff --git a/Dockerfile.rootless b/Dockerfile.rootless index 637c529abd..2360c0741e 100644 --- a/Dockerfile.rootless +++ b/Dockerfile.rootless @@ -1,3 +1,4 @@ +# syntax=docker/dockerfile:1 # Build stage FROM docker.io/library/golang:1.25-alpine3.22 AS build-env @@ -16,46 +17,15 @@ RUN apk --no-cache add \ pnpm WORKDIR ${GOPATH}/src/code.gitea.io/gitea - -COPY Makefile . - -# Fetch go dependencies -COPY go.mod go.sum ./ -RUN --mount=type=cache,target=/go/pkg/mod \ - go mod download - -# Fetch pnpm dependencies -COPY package.json pnpm-lock.yaml ./ -RUN --mount=type=cache,target=/root/.local/share/pnpm/store \ - pnpm install --frozen-lockfile --prod - -COPY ./webpack.config.ts tailwind.config.ts ./ -COPY ./assets ./assets -COPY ./public ./public -COPY ./web_src ./web_src - -RUN make frontend - -# Copy source files -COPY ./build ./build -COPY ./cmd ./cmd -COPY ./models ./models -COPY ./modules ./modules -COPY ./options ./options -COPY ./routers ./routers -COPY ./services ./services -COPY ./templates ./templates -COPY ./build.go . -COPY ./main.go . -COPY contrib/environment-to-ini/environment-to-ini.go contrib/environment-to-ini/environment-to-ini.go -COPY ./custom ./custom +COPY --exclude=.git/ . . # Checkout version if set RUN --mount=type=cache,target=/go/pkg/mod \ --mount=type=cache,target="/root/.cache/go-build" \ - --mount=type=bind,source=".git",target="${GOPATH}/src/code.gitea.io/gitea/.git" \ + --mount=type=cache,target=/root/.local/share/pnpm/store \ + --mount=type=bind,source=".git/",target=".git/" \ if [ -n "${GITEA_VERSION}" ]; then git checkout "${GITEA_VERSION}"; fi \ - && make backend + && make # Begin env-to-ini build RUN --mount=type=cache,target=/go/pkg/mod \