forked from docker-library/ruby
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile.template
299 lines (291 loc) · 7.41 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
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
290
291
292
293
294
295
296
297
298
299
{{
def is_alpine:
env.variant | startswith("alpine")
;
def is_slim:
env.variant | startswith("slim-")
-}}
{{ if is_alpine then ( -}}
FROM alpine:{{ env.variant | ltrimstr("alpine") }}
{{ ) elif is_slim then ( -}}
FROM debian:{{ env.variant | ltrimstr("slim-") }}-slim
{{ ) else ( -}}
FROM buildpack-deps:{{ env.variant }}
{{ ) end -}}
{{ if is_alpine then ( -}}
RUN set -eux; \
apk add --no-cache \
bzip2 \
ca-certificates \
gmp-dev \
libffi-dev \
procps \
yaml-dev \
zlib-dev \
;
{{ ) elif is_slim then ( -}}
RUN set -eux; \
apt-get update; \
apt-get install -y --no-install-recommends \
bzip2 \
ca-certificates \
libffi-dev \
libgmp-dev \
libssl-dev \
libyaml-dev \
procps \
zlib1g-dev \
; \
rm -rf /var/lib/apt/lists/*
{{ ) else "" end -}}
# skip installing gem documentation
RUN set -eux; \
mkdir -p /usr/local/etc; \
{ \
echo 'install: --no-document'; \
echo 'update: --no-document'; \
} >> /usr/local/etc/gemrc
ENV LANG C.UTF-8
# https://www.ruby-lang.org/{{ .post | ltrimstr("/") }}
ENV RUBY_VERSION {{ .version }}
ENV RUBY_DOWNLOAD_URL {{ .url.xz }}
ENV RUBY_DOWNLOAD_SHA256 {{ .sha256.xz }}
# some of ruby's build scripts are written in ruby
# we purge system ruby later to make sure our final image uses what we just built
RUN --mount=type=bind,source=ruby.tar.xz,target=ruby.tar.xz \
set -eux; \
\
{{ if is_alpine then ( -}}
apk add --no-cache --virtual .ruby-builddeps \
autoconf \
{{ if env.version | rtrimstr("-rc") | IN("3.1", "3.2") then ( -}}
{{ # https://github.com/docker-library/ruby/pull/438 -}}
bison \
{{ ) else "" end -}}
bzip2 \
bzip2-dev \
ca-certificates \
coreutils \
dpkg-dev dpkg \
g++ \
gcc \
gdbm-dev \
glib-dev \
libc-dev \
libffi-dev \
libxml2-dev \
libxslt-dev \
linux-headers \
make \
ncurses-dev \
openssl \
openssl-dev \
patch \
procps \
{{ if env.version | rtrimstr("-rc") | IN("3.1", "3.2") then ( -}}
readline-dev \
{{ ) else "" end -}}
ruby \
tar \
xz \
yaml-dev \
zlib-dev \
; \
{{ ) else ( -}}
savedAptMark="$(apt-mark showmanual)"; \
apt-get update; \
apt-get install -y --no-install-recommends \
{{ if env.version | rtrimstr("-rc") | IN("3.1", "3.2") then ( -}}
{{ # https://github.com/docker-library/ruby/pull/438 -}}
bison \
{{ ) else "" end -}}
dpkg-dev \
libgdbm-dev \
ruby \
{{ if is_slim then ( -}}
autoconf \
g++ \
gcc \
libbz2-dev \
libgdbm-compat-dev \
libglib2.0-dev \
libncurses-dev \
{{ if env.version | rtrimstr("-rc") | IN("3.1", "3.2") then ( -}}
libreadline-dev \
{{ ) else "" end -}}
libxml2-dev \
libxslt-dev \
make \
wget \
xz-utils \
{{ ) else "" end -}}
; \
rm -rf /var/lib/apt/lists/*; \
{{ ) end -}}
{{ if .rust.version then ( -}}
\
rustArch=; \
{{ def archVar: if is_alpine then "apkArch" else "dpkgArch" end -}}
{{ archVar }}="$({{ if is_alpine then "apk --print-arch" else "dpkg --print-architecture" end }})"; \
case "${{ archVar }}" in \
{{
(
.rustup.arches
| (if is_alpine then "musl" else "glibc" end) as $libcKey
| to_entries
| map(
.key as $bashbrewArch
| (
if is_alpine then
{
amd64: "x86_64",
arm32v6: "armhf",
arm32v7: "armv7",
arm64v8: "aarch64",
i386: "x86",
ppc64le: "ppc64le",
riscv64: "riscv64",
s390x: "s390x",
}
else
{
amd64: "amd64",
arm32v5: "armel",
arm32v7: "armhf",
arm64v8: "arm64",
i386: "i386",
mips64le: "mips64el",
ppc64le: "ppc64el",
riscv64: "riscv64",
s390x: "s390x",
}
end
)[$bashbrewArch] as $distroArch
| select($distroArch)
| .value
| select(has($libcKey))
| .[$libcKey]
| (
-}}
{{ $distroArch | @sh }}) rustArch={{ .arch | @sh }}; rustupUrl={{ .url | @sh }}; rustupSha256={{ .sha256 | @sh }} ;; \
{{
)
)
| join("")
)
-}}
esac; \
\
if [ -n "$rustArch" ]; then \
mkdir -p /tmp/rust; \
\
wget -O /tmp/rust/rustup-init "$rustupUrl"; \
echo "$rustupSha256 */tmp/rust/rustup-init" | sha256sum --check --strict; \
chmod +x /tmp/rust/rustup-init; \
\
export RUSTUP_HOME='/tmp/rust/rustup' CARGO_HOME='/tmp/rust/cargo'; \
export PATH="$CARGO_HOME/bin:$PATH"; \
/tmp/rust/rustup-init -y --no-modify-path --profile minimal --default-toolchain {{ .rust.version | @sh }} --default-host "$rustArch"; \
\
rustc --version; \
cargo --version; \
fi; \
{{ ) else "" end -}}
\
echo "$RUBY_DOWNLOAD_SHA256 *ruby.tar.xz" | sha256sum --check --strict; \
\
mkdir -p /usr/src/ruby; \
tar -xJf ruby.tar.xz -C /usr/src/ruby --strip-components=1; \
\
cd /usr/src/ruby; \
\
{{ if is_alpine then ( -}}
# https://github.com/docker-library/ruby/issues/196
# https://bugs.ruby-lang.org/issues/14387#note-13 (patch source)
# https://bugs.ruby-lang.org/issues/14387#note-16 ("Therefore ncopa's patch looks good for me in general." -- only breaks glibc which doesn't matter here)
wget -O 'thread-stack-fix.patch' 'https://raw.githubusercontent.com/docker-ruby-nightly/ruby/master/thread-stack-fix.patch'; \
echo '3ab628a51d92fdf0d2b5835e93564857aea73e0c1de00313864a94a6255cb645 *thread-stack-fix.patch' | sha256sum --check --strict; \
patch -p1 -i thread-stack-fix.patch; \
rm thread-stack-fix.patch; \
\
# the configure script does not detect isnan/isinf as macros
export ac_cv_func_isnan=yes ac_cv_func_isinf=yes; \
\
{{ ) else "" end -}}
# hack in "ENABLE_PATH_CHECK" disabling to suppress:
# warning: Insecure world writable dir
{ \
echo '#define ENABLE_PATH_CHECK 0'; \
echo; \
cat file.c; \
} > file.c.new; \
mv file.c.new file.c; \
\
autoconf; \
gnuArch="$(dpkg-architecture --query DEB_BUILD_GNU_TYPE)"; \
./configure \
--build="$gnuArch" \
--disable-install-doc \
--enable-shared \
{{ if .rust.version then ( -}}
${rustArch:+--enable-yjit} \
{{ ) else "" end -}}
; \
make -j "$(nproc)"; \
make install; \
\
{{ if .rust.version then ( -}}
rm -rf /tmp/rust; \
{{ ) else "" end -}}
{{ if is_alpine then ( -}}
runDeps="$( \
scanelf --needed --nobanner --format '%n#p' --recursive /usr/local \
| tr ',' '\n' \
| sort -u \
| awk 'system("[ -e /usr/local/lib/" $1 " ]") == 0 { next } { print "so:" $1 }' \
)"; \
apk add --no-network --virtual .ruby-rundeps $runDeps; \
apk del --no-network .ruby-builddeps; \
{{ ) else ( -}}
apt-mark auto '.*' > /dev/null; \
apt-mark manual $savedAptMark > /dev/null; \
find /usr/local -type f -executable -not \( -name '*tkinter*' \) -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 -}}
\
cd /; \
rm -r /usr/src/ruby; \
# verify we have no "ruby" packages installed
{{ if is_alpine then ( -}}
if \
apk --no-network list --installed \
| grep -v '^[.]ruby-rundeps' \
| grep -i ruby \
; then \
exit 1; \
fi; \
{{ ) else ( -}}
if dpkg -l | grep -i ruby; then exit 1; fi; \
{{ ) end -}}
[ "$(command -v ruby)" = '/usr/local/bin/ruby' ]; \
# rough smoke test
ruby --version; \
gem --version; \
bundle --version
# don't create ".bundle" in all our apps
ENV GEM_HOME /usr/local/bundle
ENV BUNDLE_SILENCE_ROOT_WARNING=1 \
BUNDLE_APP_CONFIG="$GEM_HOME"
ENV PATH $GEM_HOME/bin:$PATH
RUN set -eux; \
mkdir "$GEM_HOME"; \
# adjust permissions of GEM_HOME for running "gem install" as an arbitrary user
chmod 1777 "$GEM_HOME"
CMD [ "irb" ]