forgejo/Dockerfile.ci

106 lines
3.0 KiB
Docker
Raw Normal View History

2022-12-07 21:26:24 +00:00
FROM --platform=$BUILDPLATFORM golang:1.19 AS build-env
2022-12-07 16:40:58 +00:00
ARG BUILDPLATFORM
ARG GOPROXY
ENV GOPROXY ${GOPROXY:-direct}
2022-12-07 19:36:57 +00:00
ARG TAG
ENV TAG ${TAG:-main}
2022-12-07 16:40:58 +00:00
ARG CI_COMMIT_SHA
ARG CI_REPO_CLONE_URL
# Shorthands for easy use and ease of replacement
ARG OUT "/out-bins"
ARG DR "/docker/root"
# Check vars and create directories
RUN test -n "$CI_COMMIT_SHA" || (echo "CI_COMMIT_SHA is required but not set" >&2 && exit 1) && \
test -n "$CI_REPO_CLONE_URL" || (echo "CI_REPO_CLONE_URL is required but not set" >&2 && exit 1) && \
echo "Running prep for ${CI_REPO_CLONE_URL} commit ${CI_COMMIT_SHA}" && \
mkdir -p "${OUT}/linux/amd64" && \
mkdir -p "${OUT}/linux/arm64" && \
mkdir /build && \
mkdir -p "${DR}"
# Copying the arch specific binaries to the path easily accessible in the next step and rename them to gitea
2022-12-07 21:10:38 +00:00
COPY --chmod=755 tmp-bin/release/forgejo-$TAG-linux-amd64 "${OUT}/linux/amd64/gitea"
COPY --chmod=755 tmp-bin/release/forgejo-$TAG-linux-arm64 "${OUT}/linux/arm64/gitea"
2022-12-07 16:40:58 +00:00
WORKDIR /build
RUN echo "setting up git" && \
# quiet down git
git config --global init.defaultBranch dummy && \
git config --global advice.detachedHead false && \
git init && \
git remote add origin ${CI_REPO_CLONE_URL} && \
# shallow clone as we just need the current data, keeps the "clone" really small
git fetch --depth 1 origin ${CI_COMMIT_SHA} && \
git checkout FETCH_HEAD && \
export ENV2INI="environment-to-ini" && \
export GOFILE="contrib/$ENV2INI/$ENV2INI.go" && \
echo "compiling for linux/amd64" && \
GOOS=linux GOARCH=amd64 go build -o "${OUT}/linux/amd64/$ENV2INI" "${GOFILE}" && \
echo "compiling for linux/arm64" && \
GOOS=linux GOARCH=arm64 go build -o "${OUT}/linux/arm64/$ENV2INI "${GOFILE}" && \
cd / && \
echo "Copying future root addons" && \
cp -r /build"${DR}/* "${DR}/ && \
echo "Fixing permissions" && \
chmod 755 "${DR}/usr/bin/entrypoint "${DR}/usr/local/bin/gitea "${DR}/etc/s6/gitea/* "${DR}/etc/s6/openssh/* "${DR}/etc/s6/.s6-svscan/* && \
echo "removing git repo" && \
rm -Rf /build
# Main build
2022-12-07 21:26:24 +00:00
FROM alpine:3.17.0
2022-12-07 16:40:58 +00:00
LABEL maintainer="contact@forgejo.org"
ARG TARGETPLATFORM
ENV TARGETPLATFORM=${TARGETPLATFORM:-linux/amd64}
EXPOSE 22 3000
RUN apk --no-cache add \
bash \
ca-certificates \
curl \
gettext \
git \
linux-pam \
openssh \
s6 \
sqlite \
su-exec \
gnupg \
tzdata
RUN addgroup \
-S -g 1000 \
git && \
adduser \
-S -H -D \
-h /data/git \
-s /bin/bash \
-u 1000 \
-G git \
git && \
echo "git:*" | chpasswd -e
ENV USER git
ENV GITEA_CUSTOM /data/gitea
VOLUME ["/data"]
ENTRYPOINT ["/usr/bin/entrypoint"]
CMD ["/bin/s6-svscan", "/etc/s6"]
ARG OUT "/out-bins"
ARG DR "/docker/root"
COPY --from=build-env "${DR}" /
COPY --from=build-env --chmod=755 "${OUT}/$TARGETPLATFORM/*" /app/gitea/
# unsure it it's better to just use 2 copys and bring it to the correct place
# or ln -s (had mixed results usually ln -s makes a smaller end result)
RUN ln -s /app/gitea/environment-to-ini /usr/local/bin/environment-to-ini