From 3147c5638fafc912a116d2ba188a85e1fde416e8 Mon Sep 17 00:00:00 2001 From: Geoff Bourne Date: Sun, 26 Jun 2016 22:40:11 -0500 Subject: [PATCH] [gb] Option to auto-create and push existing content For #85 --- gitblit/README.md | 17 ++++++++++++----- gitblit/start.sh | 48 ++++++++++++++++++++++++++++++++--------------- 2 files changed, 45 insertions(+), 20 deletions(-) diff --git a/gitblit/README.md b/gitblit/README.md index 6e06e61b..90004275 100644 --- a/gitblit/README.md +++ b/gitblit/README.md @@ -1,4 +1,4 @@ -Provides a ready-to-use instance of [GitBlit](http://gitblit.com/). +Provides a ready-to-use instance of [GitBlit](http://gitblit.com/). ## Basic usage @@ -6,7 +6,7 @@ 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 +Access its web interface at the mapped HTTP (80) or HTTPS (443) port of the Docker host. Login with the default credentials __admin__ / __admin__ . @@ -18,14 +18,21 @@ In order to allow for future upgrades, run the container with a volume mount of ## 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/)), +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 +## Create repositories with content + +In addition to the approach above, you can push repostories with existing +content by attaching them to sub-directories of `/repos`, such as + + docker run -v $HOME/git/example:/repos/example ... + ## Custom configuration You can add or override any of the `*.properties` files for configuring GitBlit, @@ -34,6 +41,6 @@ typically `gitblit.properties`, by placing those files in a volume attached at -v $(pwd)/extra-config:/config -The property files in that configuration directory will be renamed with the +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 4b104e79..71f05b77 100755 --- a/gitblit/start.sh +++ b/gitblit/start.sh @@ -18,23 +18,13 @@ APPLYING configuration file $p 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 +create_repo() { + local repo_dir=$GITBLIT_BASE_FOLDER/git/$1.git mkdir -p $repo_dir cd $repo_dir git init --bare - + echo " [gitblit] description = @@ -60,7 +50,34 @@ CREATING initial repository '$GITBLIT_INITIAL_REPO' with: git config --replace-all core.logallrefupdates false - cd $GITBLIT_PATH + echo " +CREATING repository '$1' with: +* read/clone access for all +* push access for authenticated users" + + RET="file://$repo_dir" +} + +apply_repos() { + for rdir in /repos/*; do + if [ -d $rdir/.git ]; then + r=$(basename $rdir) + create_repo $r + local url=$RET + cd $rdir + echo "* pushed existing content" + git push --all $url + fi + + done +} + +create_initial_repo() { + if [ -d $GITBLIT_INITIAL_REPO ]; then + return + fi + + create_repo $GITBLIT_INITIAL_REPO } shopt -s nullglob @@ -73,8 +90,9 @@ fi if [[ -n $GITBLIT_INITIAL_REPO ]]; then create_initial_repo fi +apply_repos +cd $GITBLIT_PATH $JAVA_HOME/bin/java -jar $GITBLIT_PATH/gitblit.jar \ --httpsPort $GITBLIT_HTTPS_PORT --httpPort $GITBLIT_HTTP_PORT \ --baseFolder $GITBLIT_BASE_FOLDER -