-
Notifications
You must be signed in to change notification settings - Fork 36
Expand file tree
/
Copy pathDockerfile-linux.template
More file actions
215 lines (208 loc) · 5.48 KB
/
Dockerfile-linux.template
File metadata and controls
215 lines (208 loc) · 5.48 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
{{
include "shared"
;
def is_slim:
env.variant
| startswith("slim-")
;
def lib_pypy:
if is_3 and minor >= 8 then
"/opt/pypy/lib/pypy" + env.version
else
"/opt/pypy/lib_pypy"
end
;
def cmd:
if is_3 then
"pypy3"
else
"pypy"
end
-}}
{{ if is_slim then ( -}}
FROM debian:{{ env.variant | ltrimstr("slim-") }}-slim
RUN set -eux; \
apt-get update; \
apt-get install -y --no-install-recommends ca-certificates; \
rm -rf /var/lib/apt/lists/*
{{ ) else ( -}}
FROM buildpack-deps:{{ env.variant }}
{{ if is_3 then ( -}}
# runtime dependencies
RUN set -eux; \
apt-get update; \
apt-get install -y --no-install-recommends \
tcl \
tk \
; \
rm -rf /var/lib/apt/lists/*
{{ ) else "" end -}}
{{ ) end -}}
# 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
# ensure local {{ cmd }} is preferred over distribution {{ cmd }}
ENV PATH /opt/pypy/bin:$PATH
# Python {{ .python.version }}
ENV PYPY_VERSION {{ .version }}
RUN set -eux; \
\
dpkgArch="$(dpkg --print-architecture)"; \
case "${dpkgArch##*-}" in \
{{
[
.arches | to_entries[]
| select(.key | index("-") | not)
| .key as $bashbrewArch
| (
{
arm32v5: "armel",
arm32v7: "armhf",
arm64v8: "arm64",
mips64le: "mips64el",
ppc64le: "ppc64el",
}
| .[$bashbrewArch] // $bashbrewArch
) as $dpkgArch
| .value
| (
-}}
{{ $dpkgArch | @sh }}) \
url={{ .url | @sh }}; \
sha256={{ .sha256 | @sh }}; \
;; \
{{
)
] | add
-}}
*) echo >&2 "error: current architecture ($dpkgArch) does not have a corresponding PyPy $PYPY_VERSION binary release"; exit 1 ;; \
esac; \
\
savedAptMark="$(apt-mark showmanual)"; \
apt-get update; \
apt-get install -y --no-install-recommends \
{{ if is_slim then ( -}}
bzip2 \
wget \
{{ ) else "" end -}}
# sometimes "{{ cmd }}" (or associated .so files) has dynamic links to different system libraries
# we install them here, and then use "ldd" further down to only keep what we actually need (which might even differ per architecture)
{{
{
"pypy": [
"libfreetype6",
empty
],
"pypy3": [
"libfontconfig1",
empty
],
}[cmd] | map(
-}}
{{ . }} \
{{ ) | add -}}
; \
\
wget -O pypy.tar.bz2 "$url" --progress=dot:giga; \
echo "$sha256 *pypy.tar.bz2" | sha256sum --check --strict -; \
mkdir /opt/pypy; \
tar -xjC /opt/pypy --strip-components=1 -f pypy.tar.bz2; \
find /opt/pypy/lib* -depth -type d -a \( -name test -o -name tests \) -exec rm -rf '{}' +; \
rm pypy.tar.bz2; \
\
# delete a few (sometimes) problematic bundled libraries
rm -v /opt/pypy/lib/libtk*.so /opt/pypy/lib/libz.so*; \
\
ln -sv {{ "/opt/pypy/bin/" + cmd | @sh }} /usr/local/bin/; \
\
# smoke test
{{ cmd }} --version; \
\
{{ if is_3 then ( -}}
# rebuild several cffi modules for compatibility
cd {{ lib_pypy }}; \
{{
[
{
file: "_gdbm_build.py",
deps: "libgdbm-dev",
},
{
comment: "https://github.com/docker-library/pypy/issues/24#issuecomment-409408657",
file: "_ssl_build.py",
deps: "libssl-dev",
},
{
comment: "https://github.com/docker-library/pypy/issues/42",
file: "_lzma_build.py",
deps: "liblzma-dev",
},
{
comment: "https://github.com/docker-library/pypy/issues/68",
file: "_sqlite3_build.py",
deps: "libsqlite3-dev",
},
{
file: "_tkinter/tklib_build.py",
deps: "tk-dev",
},
empty # trailing comma hack
] | map(
-}}
if [ -f {{ .file }} ]; then \
{{ if .comment then ( -}}
# {{ .comment }}
{{ ) else "" end -}}
{{
(
if is_slim then
"gcc libc6-dev " + .deps
elif .deps == "tk-dev" then
.deps
else "" end
) as $install
| if $install != "" then
( -}}
apt-get install -y --no-install-recommends {{ $install }}; \
{{ ) else "" end -}}
{{ cmd }} {{ .file }}; \
fi; \
{{ ) | join("") -}}
# TODO rebuild other cffi modules here too? (other _*_build.py files; see https://github.com/pypy/pypy/blob/0f013f041fff7fb9a23b22dae8437e82beb6a279/lib_pypy/pypy_tools/build_cffi_imports.py#L25-L40)
\
{{ ) else "" end -}}
apt-mark auto '.*' > /dev/null; \
[ -z "$savedAptMark" ] || apt-mark manual $savedAptMark > /dev/null; \
export shellPid="$$"; \
find /opt/pypy -type f -executable -exec ldd '{}' ';' \
{{ if is_slim or (is_3 | not) then ( -}}
| grep -vE 'lib(tcl|tk|X[a-z]*)[0-9]*[.]' \
{{ ) else "" end -}}
| awk '/not found/ { print >> "/dev/stderr"; system("kill -9 -$shellPid") } /=>/ { so = $(NF-1); if (index(so, "/usr/local/") == 1 || index(so, "/opt/pypy/") == 1) { next }; gsub("^/(usr/)?", "", so); printf "*%s\n", so }' \
| sort -u \
| xargs -rt dpkg-query --search \
# https://manpages.debian.org/bookworm/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; \
rm -rf /var/lib/apt/lists/*; \
# smoke test again, to be sure
{{ cmd }} --version; \
\
{{ cmd }} -m ensurepip --default-pip; \
pip --version; \
{{ if is_3 and minor >= 12 then "" else ( -}}
# https://github.com/docker-library/python/issues/952
# https://github.com/docker-library/python/issues/1023
pip install --disable-pip-version-check --no-cache-dir --no-compile 'wheel<0.46'; \
{{ ) end -}}
\
find /opt/pypy -depth \
\( \
\( -type d -a \( -name test -o -name tests \) \) \
-o \
\( -type f -a \( -name '*.pyc' -o -name '*.pyo' \) \) \
\) -exec rm -rf '{}' +
CMD {{ [ cmd ] | @json }}