mirror of
https://github.com/hanzoai/forge.git
synced 2026-10-30 15:00:39 +00:00
9c069f0e2 fixed Dockerfile but left Dockerfile.rootless still doing
RUN --mount=type=bind,source=".git/",target=".git/" make backend
so the rootless image still fails on any context without VCS metadata:
"failed to compute cache key: /.git: not found". Both files already declare
ARG GIT_VERSION and both already COPY --exclude=.git/, so the mount was
excluding .git and then demanding it back.
Uses the exact shape from Dockerfile rather than a second variant: write VERSION
only when the arg is set, and fall back to 0.0.0+unknown only when there is
neither a .git directory nor an existing VERSION file. That preserves
`git describe` when the context IS a clone, which an unconditional write would
have clobbered.
Co-authored-by: Hanzo Dev <[email protected]>
102 lines
3.3 KiB
Docker
102 lines
3.3 KiB
Docker
# syntax=docker/dockerfile:1
|
|
# Build frontend on the native platform to avoid QEMU-related issues with nodejs ecosystem
|
|
FROM --platform=$BUILDPLATFORM docker.io/library/golang:1.26-alpine3.24 AS frontend-build
|
|
RUN apk --no-cache add build-base git nodejs pnpm
|
|
WORKDIR /src
|
|
COPY package.json pnpm-lock.yaml pnpm-workspace.yaml ./
|
|
RUN --mount=type=cache,target=/root/.local/share/pnpm/store pnpm install --frozen-lockfile
|
|
COPY --exclude=.git/ . .
|
|
RUN make frontend
|
|
|
|
# Build backend for each target platform
|
|
FROM docker.io/library/golang:1.26-alpine3.24 AS build-env
|
|
|
|
ARG GIT_VERSION
|
|
ARG TAGS=""
|
|
ENV TAGS="bindata timetzdata $TAGS"
|
|
ARG CGO_EXTRA_CFLAGS
|
|
|
|
# Build deps
|
|
RUN apk --no-cache add \
|
|
build-base \
|
|
git
|
|
|
|
WORKDIR ${GOPATH}/src/hanzo-git
|
|
# Sources private hanzoai modules (xorm, builder): mark them private
|
|
# (direct VCS fetch, no proxy/sumdb) and, when gh_token is mounted, rewrite
|
|
# github.com to an authenticated fetch so `go mod download` can read them. No-op
|
|
# without the token, so public-only builds still work. gh_token is the secret id
|
|
# the canonical hanzoai/ci reusable mounts (was GIT_AUTH_TOKEN, which ci never set).
|
|
ENV GOPRIVATE=github.com/hanzoai/*
|
|
COPY go.mod go.sum ./
|
|
RUN --mount=type=secret,id=gh_token \
|
|
if [ -s /run/secrets/gh_token ]; then \
|
|
git config --global url."https://x-access-token:$(cat /run/secrets/gh_token)@github.com/".insteadOf "https://github.com/"; \
|
|
fi && \
|
|
go mod download
|
|
# See the comments in Dockerfile
|
|
COPY --exclude=.git/ . .
|
|
COPY --from=frontend-build /src/public/assets public/assets
|
|
|
|
# Build gitd. Same as Dockerfile: the Makefile reads the VERSION file when it
|
|
# exists and falls back to `git describe` when it does not, so a build context
|
|
# without .git supplies the version through the ARG instead of the repository.
|
|
RUN --mount=type=cache,target="/root/.cache/go-build" \
|
|
if [ -n "${GIT_VERSION}" ]; then echo "${GIT_VERSION}" > VERSION; \
|
|
elif [ ! -d .git ] && [ ! -f VERSION ]; then echo "0.0.0+unknown" > VERSION; fi && \
|
|
make backend
|
|
|
|
COPY docker/rootless /tmp/local
|
|
|
|
# Set permissions for builds that made under windows which strips the executable bit from file
|
|
RUN chmod 755 /tmp/local/usr/local/bin/* \
|
|
/go/src/hanzo-git/gitd
|
|
|
|
FROM docker.io/library/alpine:3.24 AS hanzo-git-rootless
|
|
|
|
EXPOSE 2222 3000
|
|
|
|
RUN apk --no-cache add \
|
|
bash \
|
|
ca-certificates \
|
|
dumb-init \
|
|
gettext \
|
|
git \
|
|
curl \
|
|
gnupg \
|
|
openssh-keygen
|
|
|
|
RUN addgroup \
|
|
-S -g 1000 \
|
|
git && \
|
|
adduser \
|
|
-S -H -D \
|
|
-h /var/lib/gitea/git \
|
|
-s /bin/bash \
|
|
-u 1000 \
|
|
-G git \
|
|
git
|
|
|
|
RUN mkdir -p /var/lib/gitea /etc/gitea
|
|
RUN chown git:git /var/lib/gitea /etc/gitea
|
|
|
|
COPY --from=build-env /tmp/local /
|
|
COPY --from=build-env --chown=root:root /go/src/hanzo-git/gitd /app/git/gitd
|
|
|
|
# git:git
|
|
USER 1000:1000
|
|
ENV GIT_WORK_DIR=/var/lib/gitea
|
|
ENV GIT_CUSTOM=/var/lib/gitea/custom
|
|
ENV GIT_TEMP=/tmp/gitea
|
|
ENV TMPDIR=/tmp/gitea
|
|
|
|
# TODO add to docs the ability to define the ini to load (useful to test and revert a config)
|
|
ENV GIT_APP_INI=/etc/gitea/app.ini
|
|
ENV HOME="/var/lib/gitea/git"
|
|
VOLUME ["/var/lib/gitea", "/etc/gitea"]
|
|
WORKDIR /var/lib/gitea
|
|
|
|
# HINT: HEALTH-CHECK-ENDPOINT: don't use HEALTHCHECK, search this hint keyword for more information
|
|
ENTRYPOINT ["/usr/bin/dumb-init", "--", "/usr/local/bin/docker-entrypoint.sh"]
|
|
CMD []
|