-
Notifications
You must be signed in to change notification settings - Fork 30
/
Dockerfile
200 lines (177 loc) · 8.37 KB
/
Dockerfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
FROM openjdk:8-jre-slim
# add our user and group first to make sure their IDs get assigned consistently, regardless of whatever packages get added
RUN groupadd -r -g 8117 gitblit && useradd -r -M -g gitblit -u 8117 -d /opt/gitblit gitblit
ENV GITBLIT_VERSION 1.9.3
ENV GITBLIT_DOWNLOAD_SHA b79afa05fe1765c5657b01372498698a8b7c555700005802802fe66094428492
ENV GITBLIT_DOWNLOAD_URL https://github.com/gitblit-org/gitblit/releases/download/v${GITBLIT_VERSION}/gitblit-${GITBLIT_VERSION}.tar.gz
# Install fetch dependencies, and gsou to step down from root
RUN set -eux ; \
apt-get update && apt-get install -y --no-install-recommends \
wget \
gosu \
; \
rm -rf /var/lib/apt/lists/* ; \
# Download and install Gitblit
wget --progress=bar:force:noscroll -O gitblit.tar.gz ${GITBLIT_DOWNLOAD_URL} ; \
echo "${GITBLIT_DOWNLOAD_SHA} *gitblit.tar.gz" | sha256sum -c - ; \
mkdir -p /opt/gitblit ; \
tar xzf gitblit.tar.gz -C /opt/gitblit --strip-components 1 ; \
rm -f gitblit.tar.gz ; \
# Remove unneeded scripts.
rm -f /opt/gitblit/install-service-*.sh ; \
rm -r /opt/gitblit/service-*.sh ; \
\
# It is getting annoying not to have 'll' and colors when opening a bash in the container
echo "export LS_OPTIONS='--color=auto'" >> /root/.bashrc ; \
echo 'eval `dircolors -b`' >> /root/.bashrc ; \
echo "alias ls='"'ls $LS_OPTIONS'"'" >> /root/.bashrc ; \
echo "alias ll='"'ls $LS_OPTIONS -l'"'" >> /root/.bashrc ;
LABEL maintainer="James Moger <[email protected]>, Florian Zschocke <[email protected]>" \
org.label-schema.schema-version="1.0" \
org.label-schema.name="gitblit" \
org.label-schema.description="Gitblit is an open-source, pure Java stack for managing, viewing, and serving Git repositories." \
org.label-schema.url="http://gitblit.com" \
org.label-schema.version="${GITBLIT_VERSION}" \
org.opencontainers.image.title="gitblit" \
org.opencontainers.image.description="Gitblit is an open-source, pure Java stack for managing, viewing, and serving Git repositories." \
org.opencontainers.image.url="http://gitblit.com" \
org.opencontainers.image.source="https://github.com/gitblit-org/gitblit-docker" \
org.opencontainers.image.documentation="https://github.com/gitblit-org/gitblit-docker/blob/master/hub-readme.md" \
org.opencontainers.image.version="${GITBLIT_VERSION}"
ENV GITBLIT_VAR /var/opt/gitblit
# Move the data files to a separate directory and set some defaults
RUN set -eux ; \
mkdir -p -m 0775 $GITBLIT_VAR ; \
gbetc=$GITBLIT_VAR/etc ; \
gbsrv=$GITBLIT_VAR/srv ; \
mkdir -p -m 0775 $gbsrv ; \
mv /opt/gitblit/data/git $gbsrv ; \
ln -s $gbsrv/git /opt/gitblit/data/git ; \
mv /opt/gitblit/data $gbetc ; \
ln -s $gbetc /opt/gitblit/data ; \
\
# Make sure that the most current default properties file is available
# unedited to Gitblit.
mkdir -p /opt/gitblit/etc/ ; \
mv $gbetc/defaults.properties /opt/gitblit/etc ; \
printf "\
6 c\\\n\
\\\n\
\\\n\
""#\\\n\
""# DO NOT EDIT THIS FILE. IT CAN BE OVERWRITTEN BY UPDATES.\\\n\
""# FOR YOUR OWN CUSTOM SETTINGS USE THE FILE ${gbetc}/gitblit.properties\\\n\
""# THIS FILE IS ONLY FOR REFERENCE.\\\n\
""#\\\n\
\\\n\
\\\n\
\n\
/^# Base folder for repositories/,/^git.repositoriesFolder/d\n\
/^# The location to save the filestore blobs/,/^filestore.storageFolder/d\n\
/^# Specify the location of the Lucene Ticket index/,/^tickets.indexFolder/d\n\
/^# The destination folder for cached federation proposals/,/^federation.proposalsFolder/d\n\
/^# The temporary folder to decompress/,/^server.tempFolder/d\n\
s/^server.httpPort.*/#server.httpPort = 8080/\n\
s/^server.httpsPort.*/#server.httpsPort = 8443/\n\
s/^server.redirectToHttpsPort.*/#server.redirectToHttpsPort = true/\n\
" > /tmp/defaults.sed ; \
sed -f /tmp/defaults.sed /opt/gitblit/etc/defaults.properties > $gbetc/defaults.properties ; \
rm -f /tmp/defaults.sed ; \
# Check that removal worked
grep "^git.repositoriesFolder" $gbetc/defaults.properties && false ; \
grep "^filestore.storageFolder" $gbetc/defaults.properties && false ; \
grep "^tickets.indexFolder" $gbetc/defaults.properties && false ; \
grep "^federation.proposalsFolder" $gbetc/defaults.properties && false ; \
grep "^server.tempFolder" $gbetc/defaults.properties && false ; \
\
# Create a system.properties file that sets the defaults for this docker setup.
# This is not available outside and should not be changed.
echo "git.repositoriesFolder = ${gbsrv}/git" > /opt/gitblit/etc/system.properties ; \
echo "filestore.storageFolder = ${gbsrv}/lfs" >> /opt/gitblit/etc/system.properties ; \
echo "tickets.indexFolder = ${gbsrv}/tickets/lucene" >> /opt/gitblit/etc/system.properties ; \
echo "federation.proposalsFolder = ${gbsrv}/fedproposals" >> /opt/gitblit/etc/system.properties ; \
echo "server.tempFolder = ${GITBLIT_VAR}/temp/gitblit" >> /opt/gitblit/etc/system.properties ; \
echo "server.httpPort = 8080" >> /opt/gitblit/etc/system.properties ; \
echo "server.httpsPort = 8443" >> /opt/gitblit/etc/system.properties ; \
echo "server.redirectToHttpsPort = true" >> /opt/gitblit/etc/system.properties ; \
\
# Create a properties file for settings that can be set via environment variables from docker
printf '\
''#\n\
''# GITBLIT-DOCKER.PROPERTIES\n\
''#\n\
''# This file is used by the docker image to store settings that are defined\n\
''# via environment variables. The settings in this file are automatically changed,\n\
''# added or deleted.\n\
''#\n\
''# Do not define your custom settings in this file. Your overrides or\n\
''# custom settings should be defined in the "gitblit.properties" file.\n\
''#\n\
''# Do NOT change this include line. It makes sure that settings for this docker image are set.\n\
''#\n\
include = /opt/gitblit/etc/defaults.properties,/opt/gitblit/etc/system.properties\n\
\n' > $gbetc/gitblit-docker.properties ; \
\
# Comment out settings in defaults that we support to override in gitblit-docker.properties
sed -i -e 's/^\(web.enableRpcServlet.*\)/#\1/' \
-e 's/^\(web.enableRpcManagement.*\)/#\1/' \
-e 's/^\(web.enableRpcAdministration.*\)/#\1/' \
$gbetc/defaults.properties ; \
\
# Create the gitblit.properties file that the user can use for customization.
printf '\
''#\n\
''# GITBLIT.PROPERTIES\n\
''#\n\
''# Define your custom settings in this file and/or include settings defined in\n\
''# other properties files.\n\
''#\n\
\n\
''# NOTE: Gitblit will not automatically reload "included" properties. Gitblit\n\
''# only watches the "gitblit.properties" file for modifications.\n\
''#\n\
''# Paths may be relative to the ${baseFolder} or they may be absolute.\n\
''#\n\
''# ONLY append your custom settings files at the END of the "include" line.\n\
''# The present files define the default settings for the docker container. If you\n\
''# remove them or change the order, things may break.\n\
''#\n\
include = gitblit-docker.properties\n\
\n\
''#\n\
''# Define your overrides or custom settings below\n\
''#\n\
\n' > $gbetc/gitblit.properties ; \
\
\
# Change ownership to gitblit user for all files that the process needs to write
chown -R gitblit:gitblit $GITBLIT_VAR ; \
# Set file permissions so that gitblit can read all and others cannot mess up
# or read private data
chmod ug+rwxs $gbsrv $gbsrv/git ; \
chmod ug+rwxs $gbetc $gbetc/certs ; \
chmod go=r $gbetc/defaults.properties ; \
chmod 0664 $gbetc/gitblit-docker.properties ; \
chmod 0664 $gbetc/gitblit.properties ; \
\
# Now we make a backup of the etc files, so that we can copy them to mount bound
# volumes to make sure all needed files are present in them.
cp -a $gbetc /opt/gitblit/vog-etc ; \
cp -a $gbsrv/git/project.mkd /opt/gitblit/srv-project.mkd ;
# Provide script and data to migrate from earlier images to the new layout.
COPY migrate/migrate-data /usr/local/bin/
COPY migrate/non-etc-files migrate/defaults.* /usr/local/share/gitblit/
# Setup the Docker container environment
ARG GITBLIT_RPC
ENV GITBLIT_RPC ${GITBLIT_RPC:-on}
ENV PATH /opt/gitblit:$PATH
WORKDIR /opt/gitblit
VOLUME $GITBLIT_VAR
COPY docker-entrypoint.sh /usr/local/bin/
ENTRYPOINT ["docker-entrypoint.sh"]
# 8080: HTTP front-end and transport
# 8443: HTTPS front-end and transport
# 9418: Git protocol transport
# 29418: SSH transport
EXPOSE 8080 8443 9418 29418
CMD ["gitblit"]