Newer
Older
dockerfiles / gitbucket.dockerfile
# A minimal GitBucket.
#
# Volumes:
#   /gitbucket_data - GitBucket persistent data.  Precreate to prevent Docker creating with root privs.
#   /opt/gitbucket - location of gitbucket.war (parent directory). Plugins should reside in a 'plugins' directory inside this directory.
#
# Build with:
# > docker build .
#
# Run with:
# > docker run --detach --publish 8080:8080 --volume data_location:/gitbucket_data --volume war_location:/opt/gitbucket --env GITBUCKET_PREFIX=/prefix
#
# Configuration changes can be made via environment variables, so override by supplying --env parameters (or an env file).


# start with the Alpine Adoptium base
FROM eclipse-temurin:17-jdk-alpine as jre-build

# Java module dependencies found by unzipping WAR and running:
# jdeps --class-path 'WEB-INF/classes,WEB-INF/lib/*,.' -recursive -summary .

# jdeps currently requires objc from binutils
RUN apk add --no-cache binutils

# generate a minimal JRE that includes only the necessary modules
RUN $JAVA_HOME/bin/jlink \
         --add-modules java.base,java.desktop,java.instrument,java.logging,java.management,java.naming,java.security.jgss,java.sql,java.xml \
         --strip-debug \
         --no-man-pages \
         --no-header-files \
         --compress=2 \
         --output /jre

FROM alpine:3.15

### COPY GENERATED JRE ###

ENV JAVA_HOME=/opt/java/openjdk
ENV PATH "${JAVA_HOME}/bin:${PATH}"
COPY --from=jre-build /jre $JAVA_HOME

### INSTALL DEPENDENCIES ###

# font support needed for generating avatar icons, curl needed for healthcheck, graphviz needed by plantuml plugin
RUN apk add --no-cache graphviz fontconfig ttf-opensans curl

RUN \
	addgroup gitbucket && \
	adduser --disabled-password -G gitbucket gitbucket && \
	mkdir /home/gitbucket/tmp

USER gitbucket

# These are variables that GitBucket looks for. Override when starting container (--env on Docker) if needed.
# See:  https://github.com/gitbucket/gitbucket/wiki/Basic-configurations
ENV \
	GITBUCKET_HOME="/gitbucket/gitbucket_data" \
	GITBUCKET_PORT=8080 \
	GITBUCKET_PREFIX="" \
	GITBUCKET_PLUGINDIR="/opt/gitbucket/plugins" \
	GITBUCKET_TEMPDIR="/home/gitbucket/tmp"

EXPOSE 8080/tcp

HEALTHCHECK --interval=5m --timeout=5s CMD curl --fail http://localhost:8080/ || exit 1

CMD ["/opt/java/openjdk/bin/java", "-Xms128m", "-Xms512m", "-jar", "/opt/gitbucket/gitbucket.war"]