Skip to content

Commit 3987808

Browse files
committed
Create docker controlled settings files.
Set some defaults in properties files that are controlled by docker. The /opt/gitblit/system.properties file is out of reach for the user. It can be sued to set defaults specific to the docker image and defaults for new settings that get introduced in later versions. The /opt/gitblit/data/gitblit-docker.properties file is in preparation of being able to control certain settings by environment variables. I don't believe that the docker image should set defaults that need to be edited by the user, but instead the common practice of controlling certain behaviour via env variables should be used. These can then be reflected by settings in this file, which gets written by some docker mechanism, e.g. an entry point script. Of course, Gitblit could itself read from env variables, but that is a larger change.
1 parent 90f9797 commit 3987808

File tree

3 files changed

+107
-19
lines changed

3 files changed

+107
-19
lines changed

Dockerfile

Lines changed: 50 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,57 @@ RUN set -eux ; \
2121
echo "${GITBLIT_DOWNLOAD_SHA} *gitblit.tar.gz" | sha256sum -c - ; \
2222
mkdir -p /opt/gitblit ; \
2323
tar xzf gitblit.tar.gz -C /opt/gitblit --strip-components 1 ; \
24-
rm -f gitblit.tar.gz ; \
25-
mv /opt/gitblit/data /opt/gitblit-data ; \
24+
rm -f gitblit.tar.gz ;
25+
26+
27+
# Move the data files to a separate directory and set some defaults
28+
RUN mv /opt/gitblit/data /opt/gitblit-data ; \
2629
ln -s /opt/gitblit-data /opt/gitblit/data ; \
27-
echo "server.httpPort=8080" >> /opt/gitblit-data/gitblit.properties ; \
28-
echo "server.httpsPort=8443" >> /opt/gitblit-data/gitblit.properties ; \
29-
echo "server.redirectToHttpsPort=true" >> /opt/gitblit-data/gitblit.properties ; \
30-
echo "web.enableRpcManagement=true" >> /opt/gitblit-data/gitblit.properties ; \
31-
echo "web.enableRpcAdministration=true" >> /opt/gitblit-data/gitblit.properties
30+
# Create a system.properties file that sets the defaults for this docker setup.
31+
echo "server.httpPort=8080" >> /opt/gitblit/system.properties ; \
32+
echo "server.httpsPort=8443" >> /opt/gitblit/system.properties ; \
33+
echo "server.redirectToHttpsPort=true" >> /opt/gitblit/system.properties ; \
34+
# Create a properties file for settings that can be set via environment variables from docker
35+
printf '\
36+
''#\n\
37+
''# GITBLIT-DOCKER.PROPERTIES\n\
38+
''#\n\
39+
''# This file is used by the docker image to store settings that are defined\n\
40+
''# via environment variables. The settings in this file are automatically changed,\n\
41+
''# added or deleted.\n\
42+
''#\n\
43+
''# Do not define your custom settings in this file. Your overrides or\n\
44+
''# custom settings should be defined in the "gitblit.properties" file.\n\
45+
''#\n\
46+
\n' > /opt/gitblit-data/gitblit-docker.properties ; \
47+
# Currently RPC is enabled by default
48+
echo "web.enableRpcManagement=true" >> /opt/gitblit-data/gitblit-docker.properties ; \
49+
echo "web.enableRpcAdministration=true" >> /opt/gitblit-data/gitblit-docker.properties ; \
50+
# Create the gitblit.properties file that the user can use for customization.
51+
printf '\
52+
''#\n\
53+
''# GITBLIT.PROPERTIES\n\
54+
''#\n\
55+
''# Define your custom settings in this file and/or include settings defined in\n\
56+
''# other properties files.\n\
57+
''#\n\
58+
\n\
59+
''# NOTE: Gitblit will not automatically reload "included" properties. Gitblit\n\
60+
''# only watches the "gitblit.properties" file for modifications.\n\
61+
''#\n\
62+
''# Paths may be relative to the ${baseFolder} or they may be absolute.\n\
63+
''#\n\
64+
''# ONLY append more files at the END of the "include" line.\n\
65+
''# The present files define the default settings for the docker container. If you\n\
66+
''# remove them or change the order, things may break,\n\
67+
''#\n\
68+
include = defaults.properties,/opt/gitblit/system.properties,gitblit-docker.properties\n\
69+
\n\
70+
''#\n\
71+
''# Define your overrides or custom settings below\n\
72+
''#\n\
73+
\n' > /opt/gitblit-data/gitblit.properties
74+
3275

3376
# Setup the Docker container environment
3477
WORKDIR /opt/gitblit

Dockerfile.alpine

Lines changed: 55 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,67 @@ LABEL maintainer="James Moger <james.moger@gitblit.com>, Florian Zschocke <f.zsc
1111

1212
ENV GITBLIT_DOWNLOAD_URL https://github.com/gitblit/gitblit/releases/download/v${GITBLIT_VERSION}/gitblit-${GITBLIT_VERSION}.tar.gz
1313

14-
# Download and Install Gitblit & Move the data files to a separate directory
14+
15+
16+
17+
18+
# Download and install Gitblit
1519
RUN set -eux; \
1620
wget -nv -O gitblit.tar.gz ${GITBLIT_DOWNLOAD_URL} ; \
1721
echo "${GITBLIT_DOWNLOAD_SHA} *gitblit.tar.gz" | sha256sum -c - ; \
1822
mkdir -p /opt/gitblit ; \
1923
tar xzf gitblit.tar.gz -C /opt/gitblit --strip-components 1 ; \
20-
rm -f gitblit.tar.gz ; \
21-
mv /opt/gitblit/data /opt/gitblit-data ; \
24+
rm -f gitblit.tar.gz ;
25+
26+
27+
# Move the data files to a separate directory and set some defaults
28+
RUN mv /opt/gitblit/data /opt/gitblit-data ; \
2229
ln -s /opt/gitblit-data /opt/gitblit/data ; \
23-
echo "server.httpPort=8080" >> /opt/gitblit-data/gitblit.properties ; \
24-
echo "server.httpsPort=8443" >> /opt/gitblit-data/gitblit.properties ; \
25-
echo "server.redirectToHttpsPort=true" >> /opt/gitblit-data/gitblit.properties ; \
26-
echo "web.enableRpcManagement=true" >> /opt/gitblit-data/gitblit.properties ; \
27-
echo "web.enableRpcAdministration=true" >> /opt/gitblit-data/gitblit.properties
30+
# Create a system.properties file that sets the defaults for this docker setup.
31+
echo "server.httpPort=8080" >> /opt/gitblit/system.properties ; \
32+
echo "server.httpsPort=8443" >> /opt/gitblit/system.properties ; \
33+
echo "server.redirectToHttpsPort=true" >> /opt/gitblit/system.properties ; \
34+
# Create a properties file for settings that can be set via environment variables from docker
35+
printf '\
36+
''#\n\
37+
''# GITBLIT-DOCKER.PROPERTIES\n\
38+
''#\n\
39+
''# This file is used by the docker image to store settings that are defined\n\
40+
''# via environment variables. The settings in this file are automatically changed,\n\
41+
''# added or deleted.\n\
42+
''#\n\
43+
''# Do not define your custom settings in this file. Your overrides or\n\
44+
''# custom settings should be defined in the "gitblit.properties" file.\n\
45+
''#\n\
46+
\n' > /opt/gitblit-data/gitblit-docker.properties ; \
47+
# Currently RPC is enabled by default
48+
echo "web.enableRpcManagement=true" >> /opt/gitblit-data/gitblit-docker.properties ; \
49+
echo "web.enableRpcAdministration=true" >> /opt/gitblit-data/gitblit-docker.properties ; \
50+
# Create the gitblit.properties file that the user can use for customization.
51+
printf '\
52+
''#\n\
53+
''# GITBLIT.PROPERTIES\n\
54+
''#\n\
55+
''# Define your custom settings in this file and/or include settings defined in\n\
56+
''# other properties files.\n\
57+
''#\n\
58+
\n\
59+
''# NOTE: Gitblit will not automatically reload "included" properties. Gitblit\n\
60+
''# only watches the "gitblit.properties" file for modifications.\n\
61+
''#\n\
62+
''# Paths may be relative to the ${baseFolder} or they may be absolute.\n\
63+
''#\n\
64+
''# ONLY append more files at the END of the "include" line.\n\
65+
''# The present files define the default settings for the docker container. If you\n\
66+
''# remove them or change the order, things may break,\n\
67+
''#\n\
68+
include = defaults.properties,/opt/gitblit/system.properties,gitblit-docker.properties\n\
69+
\n\
70+
''#\n\
71+
''# Define your overrides or custom settings below\n\
72+
''#\n\
73+
\n' > /opt/gitblit-data/gitblit.properties
74+
2875

2976
# Setup the Docker container environment
3077
WORKDIR /opt/gitblit

README.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ These instructions assume you are running Linux and you have already [installed
88
You can use the official [Gitblit Docker image](https://hub.docker.com/r/gitblit/gitblit).
99

1010
```
11-
sudo docker pull gitblit/gitblit
12-
sudo docker run -d --name gitblit -p 8443:8443 -p 8080:8080 -p 9418:9418 -p 29418:29418 gitblit/gitblit
11+
sudo docker pull gitblit/gitblit:rpc
12+
sudo docker run -d --name gitblit -p 8443:8443 -p 8080:8080 -p 9418:9418 -p 29418:29418 gitblit/gitblit:rpc
1313
```
1414

1515
The followings commands should retrieve and execute the Gitblit image and launch Gitblit in a Docker container that serves the web UI on ports 8080 and 8443. Your repositories will also be accessible via ssh, http, https, and the git procotol. The RPC administration interface has also been enabled so that you may use the Gitblit Manager to configure settings, manage repositories, or manage users.
@@ -28,8 +28,6 @@ sudo docker start gitblit
2828

2929
## Build Instructions
3030

31-
Thanks to [Nicola Paolucci](https://blogs.atlassian.com/2013/11/docker-all-the-things-at-atlassian-automation-and-wiring/) at [Atlassian](https://atlassian.com) for the terrific [Stash](https://www.atlassian.com/stash) example.
32-
3331
### Clone this Repository
3432
```
3533
git clone https://github.com/gitblit/gitblit-docker.git

0 commit comments

Comments
 (0)