-
Notifications
You must be signed in to change notification settings - Fork 172
Expand file tree
/
Copy pathDockerfile.template
More file actions
289 lines (277 loc) · 8.78 KB
/
Dockerfile.template
File metadata and controls
289 lines (277 loc) · 8.78 KB
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
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
{{
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 -}}
; \
{{ if env.variant == "bookworm" then ( -}}
# 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; \
{{ ) else "" end -}}
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.19
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
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
set -- {{
[
"config", # database.yml created by the entrypoint and secret_token.rb if not using SECRET_KEY_BASE
"db", # schema.rb is created/edited during 'rake db:migrate'
"sqlite", # database dir when using sqlite
"tmp/pids", # pid file location
# from RedmineInstall instructions
"log",
"tmp",
"tmp/pdf",
"public/assets",
empty
| @sh
]
| sort
| join(" ")
}}; \
mkdir -p "$@"; \
chown -R redmine:redmine ./; \
# fix permissions for running as an arbitrary user
chmod -R ugo=rwX "$@"; \
find "$@" -type d -exec chmod 1777 '{}' +
{{ if is_alpine and IN(env.version; "6.0") 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",
"yaml-dev",
if IN(env.version; "6.0") then
"sqlite-dev",
"ttf2ufm",
"zlib-dev",
empty
else
# 6.1+ needs to compile some extensions on non-amd64-non-arm64 architectures
"cargo",
"clang19-dev", # TODO the dep needing libclang.so doesn't seem to care what version, so maybe there's a more generic dep we could use here?
empty
end,
empty
else
# debian packages
"default-libmysqlclient-dev",
"libpq-dev",
"libsqlite3-dev",
"libxml2-dev",
"libxslt-dev",
"libyaml-dev",
"pkgconf",
"xz-utils",
if IN(env.version; "6.0") then empty else
# 6.1+ needs to compile some extensions on non-amd64-non-arm64 architectures
"cargo",
"libclang-dev",
empty
end,
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 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 ' \
{{ if IN(env.version; "6.0") then "" else ( -}}
$1 == "libc.so" { next } \
{{ ) end -}}
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 -rt dpkg-query --search \
# https://manpages.debian.org/trixie/dpkg/dpkg-query.1.en.html#S (we ignore diversions and it'll be really unusual for more than one package to provide any given .so file)
| awk 'sub(":$", "", $1) { print $1 }' \
| 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"]