-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDockerfile
399 lines (345 loc) · 11.5 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
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
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
FROM ubuntu:noble AS base
LABEL \
maintainer="César Román <[email protected]>" \
repository="https://github.com/coatl-dev/docker-six" \
vendor="coatl.dev"
ENV DEBIAN_FRONTEND=noninteractive
# http://bugs.python.org/issue19846
# > At the moment, setting "LANG=C" on a Linux system *fundamentally breaks Python 3*, and that's not OK.
ENV LANG=C.UTF-8
ENV PYTHON_ROOT=/opt/python
# https://github.com/docker-library/python/issues/147
ENV PYTHONIOENCODING=UTF-8
ENV PIP_NO_CACHE_DIR=1
ENV PIP_NO_PYTHON_VERSION_WARNING=1
ENV PIP_ROOT_USER_ACTION=ignore
# install base dependencies
RUN set -eux; \
\
apt-get update --quiet; \
apt-get upgrade --yes; \
apt-get install --yes --no-install-recommends \
apt-utils \
build-essential \
ca-certificates \
curl \
git-man \
libcurl3t64-gnutls \
liberror-perl \
libexpat1 \
libsqlite3-0 \
netbase \
sudo \
tzdata \
wget \
; \
rm -rf /var/lib/apt/lists/*
# >============================================================================<
FROM base AS builder
RUN set -eux; \
\
apt-get update --quiet; \
apt-get install --yes --no-install-recommends \
libbluetooth-dev \
libbz2-dev \
libc6-dev \
libcurl4-gnutls-dev \
libdb-dev \
libexpat1-dev \
libffi-dev \
libgdbm-dev \
liblzma-dev \
libncursesw5-dev \
libreadline-dev \
libsqlite3-dev \
libssl-dev \
libvips-dev \
packaging-dev \
tk-dev \
uuid-dev \
xz-utils \
zlib1g-dev \
; \
rm -rf /var/lib/apt/lists/*
# >============================================================================<
FROM builder AS git-builder
ENV GIT_VERSION=2.48.1
WORKDIR /tmp
RUN set -eux; \
\
wget -q "https://github.com/git/git/archive/refs/tags/v${GIT_VERSION}.tar.gz"; \
tar -zxf "v${GIT_VERSION}.tar.gz"
WORKDIR "/tmp/git-${GIT_VERSION}"
RUN set -eux; \
\
make configure; \
./configure --prefix=/usr/local; \
make all; \
make install
# >============================================================================<
FROM builder AS python27-builder
ENV PYTHON217_VERSION=2.7.18
WORKDIR /tmp
RUN set -eux; \
\
wget -q "https://www.python.org/ftp/python/${PYTHON217_VERSION%%[a-z]*}/Python-${PYTHON217_VERSION}.tgz"; \
tar -zxf "Python-${PYTHON217_VERSION}.tgz"
WORKDIR "/tmp/Python-${PYTHON217_VERSION}"
SHELL ["/bin/bash", "-o", "pipefail", "-c"]
RUN set -eux; \
\
gnuArch="$(dpkg-architecture --query DEB_BUILD_GNU_TYPE)"; \
./configure \
--build="$gnuArch" \
--prefix="${PYTHON_ROOT}/2.7/" \
--enable-optimizations \
--enable-option-checking=fatal \
--enable-shared \
--enable-unicode=ucs4 \
; \
make --jobs="$(nproc)" \
# setting PROFILE_TASK makes "--enable-optimizations" reasonable: https://bugs.python.org/issue36044 / https://github.com/docker-library/python/issues/160#issuecomment-509426916
PROFILE_TASK='-m test.regrtest --pgo \
test_array \
test_base64 \
test_binascii \
test_binhex \
test_binop \
test_bytes \
test_c_locale_coercion \
test_class \
test_cmath \
test_codecs \
test_compile \
test_complex \
test_csv \
test_decimal \
test_dict \
test_float \
test_fstring \
test_hashlib \
test_io \
test_iter \
test_json \
test_long \
test_math \
test_memoryview \
test_pickle \
test_re \
test_set \
test_slice \
test_struct \
test_threading \
test_time \
test_traceback \
test_unicode \
' \
; \
\
make altinstall; \
\
echo "${PYTHON_ROOT}/2.7/lib" | tee /etc/ld.so.conf.d/python2.7.conf; \
ldconfig; \
\
find "${PYTHON_ROOT}" -depth \
\( \
\( -type d -a \( -name test -o -name tests -o -name idle_test \) \) \
-o \
\( -type f -a \( -name '*.pyc' -o -name '*.pyo' \) \) \
\) -exec rm -rf '{}' + \
;
# https://github.com/pypa/get-pip
ENV PYTHON_GET_PIP_URL=https://raw.githubusercontent.com/pypa/get-pip/HEAD/public/2.7/get-pip.py
RUN set -eux; \
\
wget -q "$PYTHON_GET_PIP_URL"; \
\
"${PYTHON_ROOT}/2.7/bin/python${PYTHON217_VERSION%.*}" get-pip.py \
--disable-pip-version-check
# add some soft links for comfortable usage
WORKDIR "${PYTHON_ROOT}/2.7/bin"
RUN set -eux; \
\
ln -svT idle idle2; \
ln -svT "python${PYTHON217_VERSION%.*}" python2; \
ln -svT "python${PYTHON217_VERSION%.*}" python; \
ln -svT "python${PYTHON217_VERSION%.*}-config" python-config
# >============================================================================<
FROM builder AS python312-builder
ENV PYTHON312_VERSION=3.12.8
WORKDIR /tmp
RUN set -eux; \
\
wget -q "https://www.python.org/ftp/python/${PYTHON312_VERSION%%[a-z]*}/Python-${PYTHON312_VERSION}.tgz"; \
tar -zxf "Python-${PYTHON312_VERSION}.tgz"
WORKDIR "/tmp/Python-${PYTHON312_VERSION}"
SHELL ["/bin/bash", "-o", "pipefail", "-c"]
RUN set -eux; \
\
gnuArch="$(dpkg-architecture --query DEB_BUILD_GNU_TYPE)"; \
./configure \
--build="$gnuArch" \
--prefix="${PYTHON_ROOT}/3.12/" \
--enable-loadable-sqlite-extensions \
--enable-optimizations \
--enable-option-checking=fatal \
--enable-shared \
--with-lto \
--with-system-expat \
--without-ensurepip \
; \
nproc="$(nproc)"; \
EXTRA_CFLAGS="$(dpkg-buildflags --get CFLAGS)"; \
LDFLAGS="$(dpkg-buildflags --get LDFLAGS)"; \
LDFLAGS="${LDFLAGS:--Wl},--strip-all"; \
make --jobs="$nproc" \
"EXTRA_CFLAGS=${EXTRA_CFLAGS:-}" \
"LDFLAGS=${LDFLAGS:-}" \
"PROFILE_TASK=${PROFILE_TASK:-}" \
; \
\
# https://github.com/docker-library/python/issues/784
# prevent accidental usage of a system installed libpython of the same version
rm python; \
make --jobs="$nproc" \
"EXTRA_CFLAGS=${EXTRA_CFLAGS:-}" \
"LDFLAGS=${LDFLAGS:--Wl},-rpath='\$\$ORIGIN/../lib'" \
"PROFILE_TASK=${PROFILE_TASK:-}" \
python \
; \
make altinstall; \
\
echo "${PYTHON_ROOT}/3.12/lib" | tee /etc/ld.so.conf.d/python3.12.conf; \
ldconfig; \
\
find "${PYTHON_ROOT}" -depth \
\( \
\( -type d -a \( -name test -o -name tests -o -name idle_test \) \) \
-o \( -type f -a \( -name '*.pyc' -o -name '*.pyo' -o -name 'libpython*.a' \) \) \
\) -exec rm -rf '{}' + \
;
# if this is called "PIP_VERSION", pip explodes with "ValueError: invalid truth value '<VERSION>'"
ENV PYTHON312_PIP_VERSION=24.3.1
# https://github.com/pypa/get-pip
ENV PYTHON_GET_PIP_URL=https://raw.githubusercontent.com/pypa/get-pip/HEAD/public/get-pip.py
RUN set -eux; \
\
wget -q "$PYTHON_GET_PIP_URL"; \
\
export PYTHONDONTWRITEBYTECODE=1; \
\
"${PYTHON_ROOT}/3.12/bin/python${PYTHON312_VERSION%.*}" get-pip.py \
--disable-pip-version-check \
--no-cache-dir \
--no-compile \
"pip==$PYTHON312_PIP_VERSION"
# add some soft links for comfortable usage
WORKDIR "${PYTHON_ROOT}/3.12/bin"
RUN set -eux; \
\
ln -svT "2to3-${PYTHON312_VERSION%.*}" 2to3; \
ln -svT "idle${PYTHON312_VERSION%.*}" idle3; \
ln -svT "idle${PYTHON312_VERSION%.*}" idle; \
ln -svT "pydoc${PYTHON312_VERSION%.*}" pydoc; \
ln -svT "python${PYTHON312_VERSION%.*}" python3; \
ln -svT "python${PYTHON312_VERSION%.*}" python; \
ln -svT "python${PYTHON312_VERSION%.*}-config" python-config
# >============================================================================<
FROM builder AS python-builder
ENV PYTHON_VERSION=3.13.1
WORKDIR /tmp
RUN set -eux; \
\
wget -q "https://www.python.org/ftp/python/${PYTHON_VERSION%%[a-z]*}/Python-${PYTHON_VERSION}.tgz"; \
tar -zxf "Python-${PYTHON_VERSION}.tgz"
WORKDIR "/tmp/Python-${PYTHON_VERSION}"
SHELL ["/bin/bash", "-o", "pipefail", "-c"]
RUN set -eux; \
\
gnuArch="$(dpkg-architecture --query DEB_BUILD_GNU_TYPE)"; \
./configure \
--build="$gnuArch" \
--prefix="${PYTHON_ROOT}/" \
--enable-loadable-sqlite-extensions \
--enable-optimizations \
--enable-option-checking=fatal \
--enable-shared \
--with-lto \
--with-system-expat \
--without-ensurepip \
; \
nproc="$(nproc)"; \
EXTRA_CFLAGS="$(dpkg-buildflags --get CFLAGS)"; \
LDFLAGS="$(dpkg-buildflags --get LDFLAGS)"; \
LDFLAGS="${LDFLAGS:--Wl},--strip-all"; \
make --jobs="$nproc" \
"EXTRA_CFLAGS=${EXTRA_CFLAGS:-}" \
"LDFLAGS=${LDFLAGS:-}" \
"PROFILE_TASK=${PROFILE_TASK:-}" \
; \
\
# https://github.com/docker-library/python/issues/784
# prevent accidental usage of a system installed libpython of the same version
rm python; \
make --jobs="$nproc" \
"EXTRA_CFLAGS=${EXTRA_CFLAGS:-}" \
"LDFLAGS=${LDFLAGS:--Wl},-rpath='\$\$ORIGIN/../lib'" \
"PROFILE_TASK=${PROFILE_TASK:-}" \
python \
; \
make altinstall; \
\
echo "${PYTHON_ROOT}/lib" | tee /etc/ld.so.conf.d/python.conf; \
ldconfig; \
\
find "${PYTHON_ROOT}" -depth \
\( \
\( -type d -a \( -name test -o -name tests -o -name idle_test \) \) \
-o \( -type f -a \( -name '*.pyc' -o -name '*.pyo' -o -name 'libpython*.a' \) \) \
\) -exec rm -rf '{}' + \
;
# if this is called "PIP_VERSION", pip explodes with "ValueError: invalid truth value '<VERSION>'"
ENV PYTHON_PIP_VERSION=24.3.1
# https://github.com/pypa/get-pip
ENV PYTHON_GET_PIP_URL=https://raw.githubusercontent.com/pypa/get-pip/HEAD/public/get-pip.py
RUN set -eux; \
\
wget -q "$PYTHON_GET_PIP_URL"; \
\
export PYTHONDONTWRITEBYTECODE=1; \
\
"${PYTHON_ROOT}/bin/python${PYTHON_VERSION%.*}" get-pip.py \
--disable-pip-version-check \
--no-cache-dir \
--no-compile \
"pip==$PYTHON_PIP_VERSION"
# add some soft links for comfortable usage
WORKDIR "${PYTHON_ROOT}/bin"
RUN set -eux; \
\
ln -svT "idle${PYTHON_VERSION%.*}" idle3; \
ln -svT "idle${PYTHON_VERSION%.*}" idle; \
ln -svT "pydoc${PYTHON_VERSION%.*}" pydoc; \
ln -svT "python${PYTHON_VERSION%.*}" python3; \
ln -svT "python${PYTHON_VERSION%.*}" python; \
ln -svT "python${PYTHON_VERSION%.*}-config" python-config
# >============================================================================<
FROM base AS final
COPY --from=git-builder /usr/local /usr/local
COPY --from=python27-builder ${PYTHON_ROOT}/2.7/ ${PYTHON_ROOT}/2.7/
COPY --from=python27-builder /etc/ld.so.conf.d/python2.7.conf /etc/ld.so.conf.d/python2.7.conf
COPY --from=python312-builder ${PYTHON_ROOT}/3.12/ ${PYTHON_ROOT}/3.12/
COPY --from=python312-builder /etc/ld.so.conf.d/python3.12.conf /etc/ld.so.conf.d/python3.12.conf
COPY --from=python-builder ${PYTHON_ROOT}/ ${PYTHON_ROOT}/
COPY --from=python-builder /etc/ld.so.conf.d/python.conf /etc/ld.so.conf.d/python.conf
# ensure local python is preferred over distribution python
ENV PATH="${PYTHON_ROOT}/bin:${PYTHON_ROOT}/3.12/bin:${PYTHON_ROOT}/2.7/bin:$PATH"
# link Python libraries
RUN set -eux; \
\
ldconfig
# git config "hack"
RUN set -eux; \
\
git config --system --add safe.directory '*'
CMD ["/bin/bash"]