1
+ FROM buildpack-deps:bookworm
2
+
3
+ LABEL \
4
+ maintainer="César Román <cesar@coatl.dev>" \
5
+ repository="https://github.com/coatl-dev/docker-python" \
6
+ vendor="coatl.dev"
7
+
8
+ ENV DEBIAN_FRONTEND=noninteractive
9
+
10
+ ENV PIP_NO_CACHE_DIR=1
11
+ ENV PIP_NO_PYTHON_VERSION_WARNING=1
12
+ ENV PIP_ROOT_USER_ACTION=ignore
13
+
14
+ # ensure local python is preferred over distribution python
15
+ ENV PATH=/usr/local/bin:$PATH
16
+
17
+ # cannot remove LANG even though https://bugs.python.org/issue19846 is fixed
18
+ # last attempted removal of LANG broke many users:
19
+ # https://github.com/docker-library/python/pull/570
20
+ ENV LANG=C.UTF-8
21
+ # https://github.com/docker-library/python/issues/147
22
+ ENV PYTHONIOENCODING=UTF-8
23
+
24
+ # runtime dependencies
25
+ RUN set -eux; \
26
+ \
27
+ apt-get update --quiet; \
28
+ apt-get upgrade --yes; \
29
+ apt-get install --yes --no-install-recommends \
30
+ tk-dev \
31
+ ; \
32
+ rm -rf /var/lib/apt/lists/*
33
+
34
+ ENV PYTHON_VERSION=2.7.18
35
+ ENV PYTHON_TAR_SHA256=b62c0e7937551d0cc02b8fd5cb0f544f9405bafc9a54d3808ed4594812edef43
36
+
37
+ SHELL ["/bin/bash" , "-o" , "pipefail" , "-c" ]
38
+ # hadolint ignore=DL3003
39
+ RUN set -eux; \
40
+ \
41
+ wget -q -O python.tar.xz "https://www.python.org/ftp/python/${PYTHON_VERSION%%[a-z]*}/Python-$PYTHON_VERSION.tar.xz" ; \
42
+ echo "$PYTHON_TAR_SHA256 *python.tar.xz" | sha256sum --check --strict -; \
43
+ mkdir -p /usr/src/python; \
44
+ tar --extract --directory /usr/src/python --strip-components=1 --file python.tar.xz; \
45
+ rm python.tar.xz; \
46
+ \
47
+ cd /usr/src/python; \
48
+ gnuArch="$(dpkg-architecture --query DEB_BUILD_GNU_TYPE)" ; \
49
+ ./configure \
50
+ --build="$gnuArch" \
51
+ --enable-optimizations \
52
+ --enable-option-checking=fatal \
53
+ --enable-shared \
54
+ --enable-unicode=ucs4 \
55
+ ; \
56
+ make -s -j "$(nproc)" \
57
+ # setting PROFILE_TASK makes "--enable-optimizations" reasonable: https://bugs.python.org/issue36044 / https://github.com/docker-library/python/issues/160#issuecomment-509426916
58
+ PROFILE_TASK='-m test.regrtest --pgo \
59
+ test_array \
60
+ test_base64 \
61
+ test_binascii \
62
+ test_binhex \
63
+ test_binop \
64
+ test_bytes \
65
+ test_c_locale_coercion \
66
+ test_class \
67
+ test_cmath \
68
+ test_codecs \
69
+ test_compile \
70
+ test_complex \
71
+ test_csv \
72
+ test_decimal \
73
+ test_dict \
74
+ test_float \
75
+ test_fstring \
76
+ test_hashlib \
77
+ test_io \
78
+ test_iter \
79
+ test_json \
80
+ test_long \
81
+ test_math \
82
+ test_memoryview \
83
+ test_pickle \
84
+ test_re \
85
+ test_set \
86
+ test_slice \
87
+ test_struct \
88
+ test_threading \
89
+ test_time \
90
+ test_traceback \
91
+ test_unicode \
92
+ ' \
93
+ ; \
94
+ make install; \
95
+ ldconfig; \
96
+ \
97
+ cd /; \
98
+ rm -rf /usr/src/python; \
99
+ \
100
+ find /usr/local -depth \
101
+ \( \
102
+ \( -type d -a \( -name test -o -name tests -o -name idle_test \) \) \
103
+ -o \( -type f -a \( -name '*.pyc' -o -name '*.pyo' -o -name 'libpython*.a' \) \) \
104
+ \) -exec rm -rf '{}' + \
105
+ ; \
106
+ \
107
+ python2 --version
108
+
109
+ # if this is called "PIP_VERSION", pip explodes with "ValueError: invalid truth value '<VERSION>'"
110
+ ENV PYTHON_PIP_VERSION=20.3.4
111
+ ENV PYTHON_SETUPTOOLS_VERSION=44.1.1
112
+ ENV PYTHON_WHEEL_VERSION=0.37.1
113
+ # https://github.com/pypa/get-pip
114
+ ENV PYTHON_GET_PIP_URL=https://raw.githubusercontent.com/pypa/get-pip/HEAD/public/2.7/get-pip.py
115
+ ENV PYTHON_GET_PIP_SHA256=40ee07eac6674b8d60fce2bbabc148cf0e2f1408c167683f110fd608b8d6f416
116
+
117
+
118
+ RUN set -ex; \
119
+ \
120
+ wget -q -O get-pip.py "$PYTHON_GET_PIP_URL" ; \
121
+ echo "$PYTHON_GET_PIP_SHA256 *get-pip.py" | sha256sum --check --strict -; \
122
+ \
123
+ python get-pip.py \
124
+ --disable-pip-version-check \
125
+ --no-cache-dir \
126
+ "pip==$PYTHON_PIP_VERSION" \
127
+ ; \
128
+ pip --version; \
129
+ \
130
+ find /usr/local -depth \
131
+ \( \
132
+ \( -type d -a \( -name test -o -name tests -o -name idle_test \) \) \
133
+ -o \
134
+ \( -type f -a \( -name '*.pyc' -o -name '*.pyo' \) \) \
135
+ \) -exec rm -rf '{}' +; \
136
+ rm -f get-pip.py
137
+
138
+ # install "virtualenv", since the vast majority of users of this image will want it
139
+ RUN python -m pip install virtualenv==20.15.1
140
+
141
+ CMD ["python2" ]
0 commit comments