Skip to content

Instantly share code, notes, and snippets.

@entrofi
Created September 26, 2017 06:13
Show Gist options
  • Save entrofi/f9d9fbb0ded9dc0514f8608171e9718c to your computer and use it in GitHub Desktop.
Save entrofi/f9d9fbb0ded9dc0514f8608171e9718c to your computer and use it in GitHub Desktop.
Simple Basic Ubuntu Based Gerrit Docker File
FROM ubuntu:16.04
LABEL "author"="Hasan Comak"
ENV GERRIT_VERSION="2.13.9"
ENV GERRIT_RELEASE=1
ENV GERRIT_HOME /var/gerrit
ENV GERRIT_SITE ${GERRIT_HOME}/review_site
ENV GERRIT_USER gerrit
# DB setup parameters for MySql
ENV DB_HOSTNAME "10.100.32.90"
ENV DB_PORT 3306
ENV DB_MYSQL_DB gerrit_test
ENV DB_MYSQL_USER gerrit_db_usr
ENV DB_MYSQL_PASSWORD password
# Add Gerrit packages to repository
RUN echo "deb mirror://mirrorlist.gerritforge.com/deb gerrit contrib" > /etc/apt/sources.list.d/GerritForge.list
RUN apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 1871F775
# Allow remote connectivity and sudo
RUN apt-get update
RUN apt-key update
RUN apt-get -y install openssh-client sudo
# Install OpenJDK and Gerrit in two subsequent transactions
# (pre-trans Gerrit script needs to have access to the Java command)
RUN apt-get -y install openjdk-8-jdk
RUN apt-get -y install gerrit=$GERRIT_VERSION-$GERRIT_RELEASE && rm -f ${GERRIT_HOME}/logs/*
# Add our user and group first to make sure their IDs get assigned consistently,
# regardless of whatever dependencies get added
# RUN useradd -d "${GERRIT_HOME}" -s /sbin/nologin "${GERRIT_USER}"
RUN adduser "${GERRIT_USER}" sudo
USER ${GERRIT_USER}
# Create the directory for gerrit beforehand and give the ownership to the new user.
RUN sudo -u ${GERRIT_USER} mkdir -p $GERRIT_SITE
# Add database section to gerrit configuration
RUN sudo -u ${GERRIT_USER} git config -f "${GERRIT_HOME}/etc/gerrit.config" database.type 'MYSQL'
RUN sudo -u ${GERRIT_USER} git config -f "${GERRIT_HOME}/etc/gerrit.config" database.hostname ${DB_HOSTNAME}
RUN sudo -u ${GERRIT_USER} git config -f "${GERRIT_HOME}/etc/gerrit.config" database.port ${DB_PORT}
RUN sudo -u ${GERRIT_USER} git config -f "${GERRIT_HOME}/etc/gerrit.config" database.database ${DB_MYSQL_DB}
RUN sudo -u ${GERRIT_USER} git config -f "${GERRIT_HOME}/etc/gerrit.config" database.username ${DB_MYSQL_USER}
RUN sudo -u ${GERRIT_USER} git config -f "${GERRIT_HOME}/etc/gerrit.config" database.password ${DB_MYSQL_PASSWORD}
RUN sudo -u ${GERRIT_USER} cat "${GERRIT_HOME}/etc/gerrit.config"
RUN java -jar ${GERRIT_HOME}/bin/gerrit.war init --batch --install-all-plugins -d ${GERRIT_HOME}
# Allow incoming traffic
EXPOSE 29418 8080
VOLUME ["${GERRIT_HOME}/git", "${GERRIT_HOME}/index", "${GERRIT_HOME}/cache", "${GERRIT_HOME}/db", "${GERRIT_HOME}/etc"]
# Start Gerrit
CMD sudo -u ${GERRIT_USER} ${GERRIT_HOME}/bin/gerrit.sh start && tail -f ${GERRIT_HOME}/logs/error_log
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment