Dockerfile.next 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. FROM golang:alpine3.22 AS binarybuilder
  2. RUN apk --no-cache --no-progress add --virtual \
  3. build-deps \
  4. build-base \
  5. git \
  6. linux-pam-dev
  7. WORKDIR /gogs.io/gogs
  8. COPY . .
  9. RUN ./docker/build/install-task.sh
  10. RUN TAGS="cert pam" task build
  11. FROM alpine:3.22
  12. # Create git user and group with fixed UID/GID at build time for better K8s security context support.
  13. # Using 1000:1000 as it's a common non-root UID/GID that works well with most volume permission setups.
  14. ARG GOGS_UID=1000
  15. ARG GOGS_GID=1000
  16. RUN addgroup -g ${GOGS_GID} -S git && \
  17. adduser -u ${GOGS_UID} -G git -H -D -g 'Gogs Git User' -h /data/git -s /bin/sh git
  18. RUN apk --no-cache --no-progress add \
  19. bash \
  20. ca-certificates \
  21. git \
  22. linux-pam \
  23. openssh-keygen
  24. ENV GOGS_CUSTOM=/data/gogs
  25. WORKDIR /app/gogs
  26. COPY --from=binarybuilder /gogs.io/gogs/gogs .
  27. # Create data directories and set ownership
  28. RUN mkdir -p /data/gogs /data/git /backup && \
  29. chown -R git:git /app/gogs /data /backup
  30. # Configure Docker Container
  31. VOLUME ["/data", "/backup"]
  32. EXPOSE 22 3000
  33. HEALTHCHECK CMD (curl -o /dev/null -sS http://localhost:3000/healthcheck) || exit 1
  34. # Run as non-root user by default for better K8s security context support.
  35. USER git:git
  36. ENTRYPOINT ["/app/gogs/gogs"]
  37. CMD ["web"]