Dockerfile.next 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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. curl \
  22. git \
  23. linux-pam \
  24. openssh-keygen
  25. ENV GOGS_CUSTOM=/data/gogs
  26. WORKDIR /app/gogs
  27. COPY --from=binarybuilder /gogs.io/gogs/gogs .
  28. # Create data directories and set ownership
  29. RUN mkdir -p /data/gogs /data/git /backup && \
  30. chown -R git:git /app/gogs /data /backup
  31. # Configure Docker Container
  32. VOLUME ["/data", "/backup"]
  33. EXPOSE 22 3000
  34. HEALTHCHECK CMD (curl -o /dev/null -sS http://localhost:3000/healthcheck) || exit 1
  35. # Run as non-root user by default for better K8s security context support.
  36. USER git:git
  37. ENTRYPOINT ["/app/gogs/gogs"]
  38. CMD ["web"]