1FROM --platform=$BUILDPLATFORM data.forgejo.org/oci/xx AS xx
2
3FROM --platform=$BUILDPLATFORM data.forgejo.org/oci/golang:1.24-alpine3.21 AS build-env
4
5ARG GOPROXY
6ENV GOPROXY=${GOPROXY:-direct}
7
8ARG RELEASE_VERSION
9ARG TAGS="sqlite sqlite_unlock_notify"
10ENV TAGS="bindata timetzdata $TAGS"
11ARG CGO_EXTRA_CFLAGS
12
13#
14# Transparently cross compile for the target platform
15#
16COPY --from=xx / /
17ARG TARGETPLATFORM
18RUN apk --no-cache add clang lld
19RUN xx-apk --no-cache add gcc musl-dev
20ENV CGO_ENABLED=1
21RUN xx-go --wrap
22#
23# for go generate and binfmt to find
24# without it the generate phase will fail with
25# #19 25.04 modules/public/public_bindata.go:8: running "go": exit status 1
26# #19 25.39 aarch64-binfmt-P: Could not open '/lib/ld-musl-aarch64.so.1': No such file or directory
27# why exactly is it needed? where is binfmt involved?
28#
29RUN cp /*-alpine-linux-musl*/lib/ld-musl-*.so.1 /lib || true
30
31RUN apk --no-cache add build-base git nodejs npm
32
33COPY . ${GOPATH}/src/forgejo.org
34WORKDIR ${GOPATH}/src/forgejo.org
35
36RUN make clean
37RUN make frontend
38RUN go build contrib/environment-to-ini/environment-to-ini.go && xx-verify environment-to-ini
39RUN LDFLAGS="-buildid=" make RELEASE_VERSION=$RELEASE_VERSION GOFLAGS="-trimpath" go-check generate-backend static-executable && xx-verify gitea
40
41# Copy local files
42COPY docker/root /tmp/local
43
44# Set permissions
45RUN chmod 755 /tmp/local/usr/bin/entrypoint \
46 /tmp/local/usr/local/bin/gitea \
47 /tmp/local/etc/s6/gitea/* \
48 /tmp/local/etc/s6/openssh/* \
49 /tmp/local/etc/s6/.s6-svscan/* \
50 /go/src/forgejo.org/gitea \
51 /go/src/forgejo.org/environment-to-ini
52RUN chmod 644 /go/src/forgejo.org/contrib/autocompletion/bash_autocomplete
53
54FROM data.forgejo.org/oci/alpine:3.21
55ARG RELEASE_VERSION
56LABEL maintainer="contact@forgejo.org" \
57 org.opencontainers.image.authors="Forgejo" \
58 org.opencontainers.image.url="https://forgejo.org" \
59 org.opencontainers.image.documentation="https://forgejo.org/download/#container-image" \
60 org.opencontainers.image.source="https://codeberg.org/forgejo/forgejo" \
61 org.opencontainers.image.version="${RELEASE_VERSION}" \
62 org.opencontainers.image.vendor="Forgejo" \
63 org.opencontainers.image.licenses="GPL-3.0-or-later" \
64 org.opencontainers.image.title="Forgejo. Beyond coding. We forge." \
65 org.opencontainers.image.description="Forgejo is a self-hosted lightweight software forge. Easy to install and low maintenance, it just does the job."
66
67EXPOSE 22 3000
68
69RUN apk --no-cache add \
70 bash \
71 ca-certificates \
72 curl \
73 gettext \
74 git \
75 linux-pam \
76 openssh \
77 s6 \
78 sqlite \
79 su-exec \
80 gnupg \
81 && rm -rf /var/cache/apk/*
82
83RUN addgroup \
84 -S -g 1000 \
85 git && \
86 adduser \
87 -S -H -D \
88 -h /data/git \
89 -s /bin/bash \
90 -u 1000 \
91 -G git \
92 git && \
93 echo "git:*" | chpasswd -e
94
95ENV USER=git
96ENV GITEA_CUSTOM=/data/gitea
97
98VOLUME ["/data"]
99
100ENTRYPOINT ["/usr/bin/entrypoint"]
101CMD ["/usr/bin/s6-svscan", "/etc/s6"]
102
103COPY --from=build-env /tmp/local /
104RUN cd /usr/local/bin ; ln -s gitea forgejo
105COPY --from=build-env /go/src/forgejo.org/gitea /app/gitea/gitea
106RUN ln -s /app/gitea/gitea /app/gitea/forgejo-cli
107COPY --from=build-env /go/src/forgejo.org/environment-to-ini /usr/local/bin/environment-to-ini
108COPY --from=build-env /go/src/forgejo.org/contrib/autocompletion/bash_autocomplete /etc/profile.d/gitea_bash_autocomplete.sh