Skip to content

Commit 1aa245f

Browse files
committed
exclude git from container build
It's not required and grows over time. Also exclude containerfiles from the copy so changes in them won't trigger layer invalidation if it's not needed
1 parent 1218db2 commit 1aa245f

File tree

3 files changed

+12
-71
lines changed

3 files changed

+12
-71
lines changed

.dockerignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,8 @@ cpu.out
7474
/VERSION
7575
/.air
7676
/.go-licenses
77-
77+
Dockerfile
78+
Dockerfile.rootless
7879
# Files and folders that were previously generated
7980
/public/assets/img/webpack
8081

Dockerfile

Lines changed: 5 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# syntax=docker/dockerfile:1
12
# Build stage
23
FROM docker.io/library/golang:1.25-alpine3.22 AS build-env
34

@@ -16,46 +17,15 @@ RUN apk --no-cache add \
1617
pnpm
1718

1819
WORKDIR ${GOPATH}/src/code.gitea.io/gitea
19-
20-
COPY Makefile .
21-
22-
# Fetch go dependencies
23-
COPY go.mod go.sum ./
24-
RUN --mount=type=cache,target=/go/pkg/mod \
25-
go mod download
26-
27-
# Fetch pnpm dependencies
28-
COPY package.json pnpm-lock.yaml ./
29-
RUN --mount=type=cache,target=/root/.local/share/pnpm/store \
30-
pnpm install --frozen-lockfile --prod
31-
32-
COPY ./webpack.config.ts tailwind.config.ts ./
33-
COPY ./assets ./assets
34-
COPY ./public ./public
35-
COPY ./web_src ./web_src
36-
37-
RUN make frontend
38-
39-
# Copy source files
40-
COPY ./build ./build
41-
COPY ./cmd ./cmd
42-
COPY ./models ./models
43-
COPY ./modules ./modules
44-
COPY ./options ./options
45-
COPY ./routers ./routers
46-
COPY ./services ./services
47-
COPY ./templates ./templates
48-
COPY ./build.go .
49-
COPY ./main.go .
50-
COPY contrib/environment-to-ini/environment-to-ini.go contrib/environment-to-ini/environment-to-ini.go
51-
COPY ./custom ./custom
20+
COPY --exclude=.git/ . .
5221

5322
# Checkout version if set
5423
RUN --mount=type=cache,target=/go/pkg/mod \
5524
--mount=type=cache,target="/root/.cache/go-build" \
56-
--mount=type=bind,source=".git",target="${GOPATH}/src/code.gitea.io/gitea/.git" \
25+
--mount=type=cache,target=/root/.local/share/pnpm/store \
26+
--mount=type=bind,source=".git/",target=".git/" \
5727
if [ -n "${GITEA_VERSION}" ]; then git checkout "${GITEA_VERSION}"; fi \
58-
&& make backend
28+
&& make
5929

6030
# Begin env-to-ini build
6131
RUN --mount=type=cache,target=/go/pkg/mod \

Dockerfile.rootless

Lines changed: 5 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# syntax=docker/dockerfile:1
12
# Build stage
23
FROM docker.io/library/golang:1.25-alpine3.22 AS build-env
34

@@ -16,46 +17,15 @@ RUN apk --no-cache add \
1617
pnpm
1718

1819
WORKDIR ${GOPATH}/src/code.gitea.io/gitea
19-
20-
COPY Makefile .
21-
22-
# Fetch go dependencies
23-
COPY go.mod go.sum ./
24-
RUN --mount=type=cache,target=/go/pkg/mod \
25-
go mod download
26-
27-
# Fetch pnpm dependencies
28-
COPY package.json pnpm-lock.yaml ./
29-
RUN --mount=type=cache,target=/root/.local/share/pnpm/store \
30-
pnpm install --frozen-lockfile --prod
31-
32-
COPY ./webpack.config.ts tailwind.config.ts ./
33-
COPY ./assets ./assets
34-
COPY ./public ./public
35-
COPY ./web_src ./web_src
36-
37-
RUN make frontend
38-
39-
# Copy source files
40-
COPY ./build ./build
41-
COPY ./cmd ./cmd
42-
COPY ./models ./models
43-
COPY ./modules ./modules
44-
COPY ./options ./options
45-
COPY ./routers ./routers
46-
COPY ./services ./services
47-
COPY ./templates ./templates
48-
COPY ./build.go .
49-
COPY ./main.go .
50-
COPY contrib/environment-to-ini/environment-to-ini.go contrib/environment-to-ini/environment-to-ini.go
51-
COPY ./custom ./custom
20+
COPY --exclude=.git/ . .
5221

5322
# Checkout version if set
5423
RUN --mount=type=cache,target=/go/pkg/mod \
5524
--mount=type=cache,target="/root/.cache/go-build" \
56-
--mount=type=bind,source=".git",target="${GOPATH}/src/code.gitea.io/gitea/.git" \
25+
--mount=type=cache,target=/root/.local/share/pnpm/store \
26+
--mount=type=bind,source=".git/",target=".git/" \
5727
if [ -n "${GITEA_VERSION}" ]; then git checkout "${GITEA_VERSION}"; fi \
58-
&& make backend
28+
&& make
5929

6030
# Begin env-to-ini build
6131
RUN --mount=type=cache,target=/go/pkg/mod \

0 commit comments

Comments
 (0)