From 63035c347bb9f134d04ebdfbbd2548d7c120acb7 Mon Sep 17 00:00:00 2001 From: Geoff Bourne Date: Sat, 11 Jun 2016 18:18:17 -0500 Subject: [PATCH] [gitblit] Upgrade to latest version and add repo init feature --- gitblit/Dockerfile | 30 ++++++++--------- gitblit/README.md | 38 ++++++++++++++++++++-- gitblit/start.sh | 80 +++++++++++++++++++++++++++++++++++++++++++--- 3 files changed, 124 insertions(+), 24 deletions(-) diff --git a/gitblit/Dockerfile b/gitblit/Dockerfile index 6c56759e..7cb80fe9 100644 --- a/gitblit/Dockerfile +++ b/gitblit/Dockerfile @@ -1,30 +1,26 @@ -FROM itzg/ubuntu-openjdk-7 +FROM java:8 MAINTAINER itzg -ENV APT_GET_UPDATE 2014-07-19 +ENV GITBLIT_VERSION 1.7.1 -RUN apt-get update -RUN apt-get -y install wget tar +RUN wget -qO /tmp/gitblit.tgz http://dl.bintray.com/gitblit/releases/gitblit-$GITBLIT_VERSION.tar.gz -ENV GITBLIT_VERSION 1.6.0 - -RUN wget -O /tmp/gitblit.tgz http://dl.bintray.com/gitblit/releases/gitblit-$GITBLIT_VERSION.tar.gz - -RUN mkdir /opt/gitblit -RUN tar -C /opt/gitblit -xvf /tmp/gitblit.tgz -RUN rm /tmp/gitblit.tgz +RUN tar -C /opt -xvf /tmp/gitblit.tgz && \ + rm /tmp/gitblit.tgz VOLUME ["/data"] ADD start.sh /start -WORKDIR /opt/gitblit -ENV GITBLIT_PATH /opt/gitblit -ENV GITBLIT_HTTPS_PORT 443 -ENV GITBLIT_HTTP_PORT 80 -ENV GITBLIT_BASE_FOLDER /data +ENV GITBLIT_PATH=/opt/gitblit-${GITBLIT_VERSION} \ + GITBLIT_HTTPS_PORT=443 \ + GITBLIT_HTTP_PORT=80 \ + GITBLIT_BASE_FOLDER=/data \ + GITBLIT_ADMIN_USER=admin \ + GITBLIT_INITIAL_REPO= +WORKDIR $GITBLIT_PATH EXPOSE 80 443 -CMD ["/start"] +ENTRYPOINT ["/start"] diff --git a/gitblit/README.md b/gitblit/README.md index 32bb1fe4..6cb91635 100644 --- a/gitblit/README.md +++ b/gitblit/README.md @@ -1,5 +1,39 @@ -Provides a ready-to-use instance of [GitBlit](http://gitblit.com/). In order to allow for -future upgrades run the container with a volume mount of `/data`, such as: +Provides a ready-to-use instance of [GitBlit](http://gitblit.com/). + +## Basic usage + +Start the GitBlit container using + + docker run -d -p 80:80 p 443:443 --name gitblit itzg/gitblit + +Access its web interface at the mapped HTTP (80) or HTTPS (443) port of the +Docker host. Login with the default credentials __admin__ / __admin__ . + + +## Data volume + +In order to allow for future upgrades, run the container with a volume mount of `/data`, such as: docker run -d -p 80:80 p 443:443 -v /tmp/gitblit-data:/data --name gitblit itzg/gitblit +## Initial repository creation + +As a convenience for cluster configuration management with git +(such as with [Spring Cloud Config](https://cloud.spring.io/spring-cloud-config/)), +you may specify the name of an initial repository to be owned by the 'admin' user. +This can be enabled by passing the name of that repository via the environment +variable `GITBLIT_INITIAL_REPO`, such as + + -e GITBLIT_INITIAL_REPO=default + +## Custom configuration + +You can add or override any of the `*.properties` files for configuring GitBlit, +typically `gitblit.properties`, by placing those files in a volume attached at +`/config`, such as + + -v $(pwd)/extra:/config + +The property files in that configuration directory will be renamed with the +suffix `.applied` to avoid overwriting manually modified configuration on +the next container startup. diff --git a/gitblit/start.sh b/gitblit/start.sh index 35575675..4b104e79 100755 --- a/gitblit/start.sh +++ b/gitblit/start.sh @@ -1,10 +1,80 @@ -#!/bin/sh +#!/bin/bash -contents=`ls $GITBLIT_BASE_FOLDER|wc -l` +apply_base_data() { + contents=`ls $GITBLIT_BASE_FOLDER|wc -l` -if [ $contents = "0" ]; then - cp -r $GITBLIT_PATH/data/* $GITBLIT_BASE_FOLDER + if [ $contents = "0" ]; then + cp -r $GITBLIT_PATH/data/* $GITBLIT_BASE_FOLDER + fi +} + +apply_config() { + for p in /config/*.properties; do + echo " +APPLYING configuration file $p +" + cp $p $GITBLIT_BASE_FOLDER + mv $p ${p}.applied + done +} + +create_initial_repo() { + if [ -d $GITBLIT_INITIAL_REPO ]; then + return + fi + + echo " +CREATING initial repository '$GITBLIT_INITIAL_REPO' with: +* read/clone access for all +* push access for authenticated users +" + + local repo_dir=$GITBLIT_BASE_FOLDER/git/${GITBLIT_INITIAL_REPO}.git + mkdir -p $repo_dir + cd $repo_dir + + git init --bare + + echo " +[gitblit] + description = + originRepository = + owner = $GITBLIT_ADMIN_USER + acceptNewPatchsets = true + acceptNewTickets = true + mergeTo = master + useIncrementalPushTags = false + allowForks = true + accessRestriction = PUSH + authorizationControl = AUTHENTICATED + verifyCommitter = false + showRemoteBranches = false + isFrozen = false + skipSizeCalculation = false + skipSummaryMetrics = false + federationStrategy = FEDERATE_THIS + isFederated = false + gcThreshold = + gcPeriod = 0 +" >> config + + git config --replace-all core.logallrefupdates false + + cd $GITBLIT_PATH +} + +shopt -s nullglob +apply_base_data + +if [ -d /config ]; then + apply_config fi -$JAVA_HOME/bin/java -jar $GITBLIT_PATH/gitblit.jar --httpsPort $GITBLIT_HTTPS_PORT --httpPort $GITBLIT_HTTP_PORT --baseFolder $GITBLIT_BASE_FOLDER +if [[ -n $GITBLIT_INITIAL_REPO ]]; then + create_initial_repo +fi + +$JAVA_HOME/bin/java -jar $GITBLIT_PATH/gitblit.jar \ + --httpsPort $GITBLIT_HTTPS_PORT --httpPort $GITBLIT_HTTP_PORT \ + --baseFolder $GITBLIT_BASE_FOLDER