-
Notifications
You must be signed in to change notification settings - Fork 177
/
Copy pathDockerfile.template
256 lines (245 loc) · 8.05 KB
/
Dockerfile.template
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
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
{{
def is_alpine:
env.variant | startswith("alpine")
-}}
{{ if is_alpine then ( -}}
FROM ruby:{{ .ruby.version }}-{{ env.variant }}
{{ ) else ( -}}
FROM ruby:{{ .ruby.version }}-slim-{{ env.variant }}
{{ ) end -}}
# explicitly set uid/gid to guarantee that it won't change in the future
# the values 999:999 are identical to the current user/group id assigned
{{ if is_alpine then ( -}}
# alpine already has a gid 999, so we'll use the next id
RUN addgroup -S -g 1000 redmine && adduser -S -H -G redmine -u 999 redmine
{{ ) else ( -}}
RUN groupadd -r -g 999 redmine && useradd -r -g redmine -u 999 redmine
{{ ) end -}}
{{
[
# common packages
"ca-certificates",
"ghostscript", # for creating PDF thumbnails
"git",
"imagemagick",
"mercurial",
"openssh-client",
"subversion",
"tini", # grab tini for signal processing and zombie killing
"wget",
if is_alpine then
# alpine packages
"bash",
"breezy",
"findutils",
"ghostscript-fonts", # for generating PNGs of Gantt charts
"tzdata",
empty
else
# debian packages
"bzr",
"gsfonts", # for generating PNGs of Gantt charts
empty
end
] | sort | (
-}}
RUN set -eux; \
{{ if is_alpine then ( -}}
apk add --no-cache \
{{ map( -}}
{{ . }} \
{{ ) | add -}}
;
{{ ) else ( -}}
apt-get update; \
apt-get install -y --no-install-recommends \
{{ map( -}}
{{ . }} \
{{ ) | add -}}
; \
# allow imagemagick to use ghostscript for PDF -> PNG thumbnail conversion (4.1+)
sed -ri 's/(rights)="none" (pattern="PDF")/\1="read" \2/' /etc/ImageMagick-6/policy.xml; \
rm -rf /var/lib/apt/lists/*
{{ ) end -}}
{{ ) -}}
# grab gosu for easy step-down from root
# https://github.com/tianon/gosu/releases
ENV GOSU_VERSION 1.17
RUN set -eux; \
\
{{ if is_alpine then ( -}}
apk add --no-cache --virtual .gosu-deps \
dpkg \
gnupg \
; \
{{ ) else ( -}}
savedAptMark="$(apt-mark showmanual)"; \
apt-get update; \
apt-get install -y --no-install-recommends \
gnupg \
; \
rm -rf /var/lib/apt/lists/*; \
{{ ) end -}}
\
dpkgArch="$(dpkg --print-architecture | awk -F- '{ print $NF }')"; \
wget -O /usr/local/bin/gosu "https://github.com/tianon/gosu/releases/download/$GOSU_VERSION/gosu-$dpkgArch"; \
wget -O /usr/local/bin/gosu.asc "https://github.com/tianon/gosu/releases/download/$GOSU_VERSION/gosu-$dpkgArch.asc"; \
export GNUPGHOME="$(mktemp -d)"; \
gpg --batch --keyserver hkps://keys.openpgp.org --recv-keys B42F6819007F00F88E364FD4036A9C25BF357DD4; \
gpg --batch --verify /usr/local/bin/gosu.asc /usr/local/bin/gosu; \
gpgconf --kill all; \
rm -rf "$GNUPGHOME" /usr/local/bin/gosu.asc; \
\
{{ if is_alpine then ( -}}
apk del --no-network .gosu-deps; \
{{ ) else ( -}}
apt-mark auto '.*' > /dev/null; \
apt-mark manual $savedAptMark > /dev/null; \
apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false; \
{{ ) end -}}
\
# smoke test
chmod +x /usr/local/bin/gosu; \
gosu --version; \
gosu nobody true
{{ if is_alpine and (env.version | IN("5.0", "5.1")) then ( -}}
RUN set -eux; ln -svf gosu /usr/local/bin/su-exec; su-exec nobody true # backwards compatibility (removed in Redmine 5.2+)
{{ ) else "" end -}}
ENV RAILS_ENV production
WORKDIR /usr/src/redmine
# https://github.com/docker-library/redmine/issues/138#issuecomment-438834176
# (bundler needs this for running as an arbitrary user)
ENV HOME /home/redmine
RUN set -eux; \
[ ! -d "$HOME" ]; \
mkdir -p "$HOME"; \
chown redmine:redmine "$HOME"; \
chmod 1777 "$HOME"
ENV REDMINE_VERSION {{ .version }}
ENV REDMINE_DOWNLOAD_URL {{ .downloadUrl }}
ENV REDMINE_DOWNLOAD_SHA256 {{ .sha256 }}
ENV RAILS_LOG_TO_STDOUT true
RUN set -eux; \
wget -O redmine.tar.gz "$REDMINE_DOWNLOAD_URL"; \
echo "$REDMINE_DOWNLOAD_SHA256 *redmine.tar.gz" | sha256sum -c -; \
tar -xf redmine.tar.gz --strip-components=1; \
rm redmine.tar.gz files/delete.me log/delete.me; \
# https://www.redmine.org/projects/redmine/wiki/RedmineInstall#Step-8-File-system-permissions
mkdir -p log public/assets public/plugin_assets sqlite tmp/pdf tmp/pids; \
chown -R redmine:redmine ./; \
# fix permissions for running as an arbitrary user
chmod -R ugo=rwX config db sqlite; \
find log tmp -type d -exec chmod 1777 '{}' +
{{ if is_alpine then ( -}}
# build for musl-libc, not glibc (see https://github.com/sparklemotion/nokogiri/issues/2075, https://github.com/rubygems/rubygems/issues/3174)
ENV BUNDLE_FORCE_RUBY_PLATFORM 1
{{ ) else "" end -}}
{{
[
# common packages
"freetds-dev",
"gcc",
"make",
"patch",
if is_alpine then
# alpine packages
"coreutils", # required because "chmod +X" in busybox will remove +x on files (and coreutils leaves files alone with +X)
"mariadb-dev",
"musl-dev",
"postgresql-dev",
"sqlite-dev",
"ttf2ufm",
"yaml-dev",
"zlib-dev",
empty
else
# debian packages
"default-libmysqlclient-dev",
"libpq-dev",
"libsqlite3-dev",
"libxml2-dev",
"libxslt-dev",
"libyaml-dev",
"pkgconf",
"xz-utils",
empty
end
] | sort | (
-}}
RUN set -eux; \
{{ if is_alpine then ( -}}
apk add --no-cache --virtual .build-deps \
{{ map( -}}
{{ . }} \
{{ ) | add -}}
; \
{{ ) else ( -}}
savedAptMark="$(apt-mark showmanual)"; \
apt-get update; \
apt-get install -y --no-install-recommends \
{{ map( -}}
{{ . }} \
{{ ) | add -}}
; \
rm -rf /var/lib/apt/lists/*; \
{{ ) end -}}
{{ ) -}}
\
gosu redmine bundle config --local without 'development test'; \
# https://github.com/redmine/redmine/commit/23dc108e70a0794f444803ac827a690085dcd557
# ("gem puma" already exists in the Gemfile, but under "group :test" and we want it all the time)
puma="$(grep -E "^[[:space:]]*gem [:'\"]puma['\",[:space:]].*\$" Gemfile)"; \
{ echo; echo "$puma"; } | sed -re 's/^[[:space:]]+//' >> Gemfile; \
# fill up "database.yml" with bogus entries so the redmine Gemfile will pre-install all database adapter dependencies
# https://github.com/redmine/redmine/blob/e9f9767089a4e3efbd73c35fc55c5c7eb85dd7d3/Gemfile#L50-L79
echo '# the following entries only exist to force `bundle install` to pre-install all database adapter dependencies -- they can be safely removed/ignored' > ./config/database.yml; \
for adapter in mysql2 postgresql sqlserver sqlite3; do \
echo "$adapter:" >> ./config/database.yml; \
echo " adapter: $adapter" >> ./config/database.yml; \
done; \
{{ if env.version == "5.0" and is_alpine and env.variant != "alpine3.20" then ( -}}
# Fix incompatibility with sqlite 1.4 in alpine 3.21
grep -q 'sqlite3", "~> 1.4.0"' Gemfile; \
sed -i -e 's/"sqlite3", "~> 1.4.0"/"sqlite3", "~> 1.5.0"/g' Gemfile; \
{{ ) else "" end -}}
{{ if is_alpine then "" else ( -}}
# nokogiri's vendored libxml2 + libxslt do not build on mips64le, so use the apt packages when building
gosu redmine bundle config build.nokogiri --use-system-libraries; \
{{ ) end -}}
gosu redmine bundle install --jobs "$(nproc)"; \
rm ./config/database.yml; \
# fix permissions for running as an arbitrary user
chmod -R ugo=rwX Gemfile.lock "$GEM_HOME"; \
rm -rf ~redmine/.bundle; \
\
{{ if is_alpine then ( -}}
# https://github.com/naitoh/rbpdf/issues/31
rm /usr/local/bundle/gems/rbpdf-font-1.19.*/lib/fonts/ttf2ufm/ttf2ufm; \
\
runDeps="$( \
scanelf --needed --nobanner --format '%n#p' --recursive /usr/local/bundle/gems \
| tr ',' '\n' \
| sort -u \
| awk 'system("[ -e /usr/local/lib/" $1 " ]") == 0 { next } { print "so:" $1 }' \
)"; \
apk add --no-network --virtual .redmine-rundeps $runDeps; \
apk del --no-network .build-deps
{{ ) else ( -}}
# reset apt-mark's "manual" list so that "purge --auto-remove" will remove all build dependencies
apt-mark auto '.*' > /dev/null; \
[ -z "$savedAptMark" ] || apt-mark manual $savedAptMark; \
find /usr/local -type f -executable -exec ldd '{}' ';' \
| awk '/=>/ { so = $(NF-1); if (index(so, "/usr/local/") == 1) { next }; gsub("^/(usr/)?", "", so); printf "*%s\n", so }' \
| sort -u \
| xargs -r dpkg-query --search \
| cut -d: -f1 \
| sort -u \
| xargs -r apt-mark manual \
; \
apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false
{{ ) end -}}
VOLUME /usr/src/redmine/files
COPY docker-entrypoint.sh /
ENTRYPOINT ["/docker-entrypoint.sh"]
EXPOSE 3000
CMD ["rails", "server", "-b", "0.0.0.0"]