11# Build stage
2- FROM docker.io/library/golang:1.21-alpine3.18 AS build-env
2+ FROM docker.io/library/node:20-alpine3.18 AS build-frontend
3+
4+ ARG GITEA_VERSION
5+
6+ # Build deps
7+ RUN apk --no-cache add \
8+ build-base \
9+ git \
10+ && rm -rf /var/cache/apk/*
11+
12+ # Setup repo
13+ WORKDIR /usr/src/code.gitea.io/gitea
14+
15+ COPY Makefile .
16+
17+ # Download NPM Packages
18+ COPY package.json .
19+ COPY package-lock.json .
20+
21+ RUN make deps-frontend
22+
23+ # Copy source files
24+ COPY ./webpack.config.js .
25+ COPY ./assets ./assets
26+ COPY ./public ./public
27+ COPY ./web_src ./web_src
28+
29+ # Checkout version if set
30+ COPY ./.git ./.git
31+ RUN if [ -n "${GITEA_VERSION}" ]; then git checkout "${GITEA_VERSION}" ; fi
32+
33+ # Build frontend
34+ RUN make clean-all frontend
35+
36+ # Build stage
37+ FROM docker.io/library/golang:1.21-alpine3.18 AS build-backend
338
439ARG GOPROXY
540ENV GOPROXY ${GOPROXY:-direct}
@@ -13,8 +48,6 @@ ARG CGO_EXTRA_CFLAGS
1348RUN apk --no-cache add \
1449 build-base \
1550 git \
16- nodejs \
17- npm \
1851 && rm -rf /var/cache/apk/*
1952
2053# Setup repo
@@ -28,19 +61,35 @@ COPY go.sum .
2861
2962RUN make deps-backend
3063
31- # Download NPM Packages
32- COPY package.json .
33- COPY package-lock.json .
64+ # Copy source files
65+ COPY ./build ./build
66+ COPY ./cmd ./cmd
67+ COPY ./models ./models
68+ COPY ./modules ./modules
69+ COPY ./options ./options
70+ COPY ./routers ./routers
71+ COPY ./services ./services
72+ COPY ./templates ./templates
73+ COPY ./build.go .
74+ COPY ./main.go .
3475
35- RUN make deps-frontend
76+ # Checkout version if set
77+ COPY ./.git ./.git
78+ RUN if [ -n "${GITEA_VERSION}" ]; then git checkout "${GITEA_VERSION}" ; fi
3679
37- COPY . .
80+ # Clean directory
81+ RUN make clean-all
3882
39- # Checkout version if set
40- RUN if [ -n "${GITEA_VERSION}" ]; then git checkout "${GITEA_VERSION}" ; fi \
41- && make clean-all build
83+ # Copy frontend build artifacts
84+ COPY --from=build-frontend /usr/src/code.gitea.io/gitea/public ./public
85+
86+ # Build backend
87+ RUN make backend
4288
4389# Begin env-to-ini build
90+ COPY contrib/environment-to-ini/environment-to-ini.go contrib/environment-to-ini/environment-to-ini.go
91+ COPY ./custom ./custom
92+
4493RUN go build contrib/environment-to-ini/environment-to-ini.go
4594
4695FROM docker.io/library/alpine:3.18 AS gitea-base
@@ -57,8 +106,11 @@ RUN apk --no-cache add \
57106
58107RUN addgroup -S -g 1000 git
59108
109+ COPY --chmod=644 ./contrib/autocompletion/bash_autocomplete /etc/profile.d/gitea_bash_autocomplete.sh
110+ COPY --chmod=755 --from=build-backend /go/src/code.gitea.io/gitea/gitea /app/gitea/gitea
111+ COPY --chmod=755 --from=build-backend /go/src/code.gitea.io/gitea/environment-to-ini /usr/local/bin/environment-to-ini
112+
60113FROM gitea-base AS gitea-rootless
61- LABEL maintainer=
"[email protected] " 62114
63115EXPOSE 2222 3000
64116
@@ -80,10 +132,6 @@ RUN chown git:git /var/lib/gitea /etc/gitea
80132# Copy local files
81133COPY --chmod=755 docker/rootless /
82134
83- COPY --from=build-env --chmod=755 --chown=root:root /go/src/code.gitea.io/gitea/gitea /app/gitea/gitea
84- COPY --from=build-env --chmod=755 --chown=root:root /go/src/code.gitea.io/gitea/environment-to-ini /usr/local/bin/environment-to-ini
85- COPY --from=build-env --chmod=644 /go/src/code.gitea.io/gitea/contrib/autocompletion/bash_autocomplete /etc/profile.d/gitea_bash_autocomplete.sh
86-
87135# git:git
88136USER 1000:1000
89137ENV GITEA_WORK_DIR /var/lib/gitea
@@ -101,7 +149,6 @@ ENTRYPOINT ["/usr/bin/dumb-init", "--", "/usr/local/bin/docker-entrypoint.sh"]
101149CMD []
102150
103151FROM gitea-base AS gitea
104- LABEL maintainer=
"[email protected] " 105152
106153EXPOSE 22 3000
107154
@@ -131,7 +178,3 @@ ENTRYPOINT ["/usr/bin/entrypoint"]
131178CMD ["/bin/s6-svscan" , "/etc/s6" ]
132179
133180COPY --chmod=755 docker/root /
134-
135- COPY --from=build-env --chmod=755 /go/src/code.gitea.io/gitea/gitea /app/gitea/gitea
136- COPY --from=build-env --chmod=755 /go/src/code.gitea.io/gitea/environment-to-ini /usr/local/bin/environment-to-ini
137- COPY --from=build-env --chmod=644 /go/src/code.gitea.io/gitea/contrib/autocompletion/bash_autocomplete /etc/profile.d/gitea_bash_autocomplete.sh
0 commit comments