Skip to content

Commit 05fc3d8

Browse files
committed
feat(python): switch to official builds for all
1 parent a20188d commit 05fc3d8

File tree

4 files changed

+180
-13
lines changed

4 files changed

+180
-13
lines changed

python/3.10/Dockerfile

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# Python image for AMP containers using Python 3.10
2+
# ghcr.io/cubecoders/amp:python-3.10
3+
4+
FROM python:3.10-slim-bookworm AS py310
5+
6+
RUN set -eux; \
7+
V=3.10; \
8+
P=/usr/local/bin/python$V; \
9+
D=/usr/local/lib/python$V/lib-dynload; \
10+
{ ldd "$P"; find "$D" -type f -name '*.so' -print0 | xargs -0 -n1 ldd; } \
11+
| awk '/=> \//{print $(NF-1)} /^\//{print $1}' \
12+
| awk 'index($0,"/usr/local/")!=1 && $0 ~ "^/(usr/)?lib"' \
13+
| sed -E 's,^/(usr/)?,,g' | sort -u > /tmp/paths-$V.txt; \
14+
xargs -r dpkg-query --search < /tmp/paths-$V.txt \
15+
| awk -F: 'NF{print $1}' | sort -u > /tmp/deps-$V.txt; \
16+
echo "Runtime packages:" && cat /tmp/deps-$V.txt
17+
18+
FROM ghcr.io/cubecoders/amp:debian
19+
LABEL org.opencontainers.image.licenses=MIT
20+
21+
ENV PIP_DISABLE_PIP_VERSION_CHECK=1
22+
23+
ARG DEBIAN_FRONTEND=noninteractive
24+
25+
COPY --from=py310 /tmp/deps-3.10.txt /deps/3.10.txt
26+
27+
RUN set -eux; \
28+
apt-get update; \
29+
apt-get purge -y --auto-remove python3\*; \
30+
RUNTIME_DEPS="$(cat /deps/3.10.txt)"; \
31+
apt-get install -y --no-install-recommends $RUNTIME_DEPS; \
32+
apt-get clean; \
33+
rm -rf /var/lib/apt/lists/*
34+
35+
COPY --from=py310 /usr/local/ /usr/local/
36+
37+
RUN set -eux; \
38+
for src in idle3 pip3 pydoc3 python3 python3-config; do \
39+
dst="$(echo "$src" | tr -d 3)"; \
40+
[ -e "/usr/local/bin/$dst" ] || ln -s "/usr/local/bin/$src" "/usr/local/bin/$dst"; \
41+
done; \
42+
for shim in python3.10 python3 pip3.10 pip3 pip; do \
43+
ln -sf "/usr/local/bin/$shim" "/usr/bin/$shim"; \
44+
done

python/3.11/Dockerfile

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,44 @@
11
# Python image for AMP containers using Python 3.11
22
# ghcr.io/cubecoders/amp:python-3.11
33

4+
FROM python:3.11-slim-bookworm AS py311
5+
6+
RUN set -eux; \
7+
V=3.11; \
8+
P=/usr/local/bin/python$V; \
9+
D=/usr/local/lib/python$V/lib-dynload; \
10+
{ ldd "$P"; find "$D" -type f -name '*.so' -print0 | xargs -0 -n1 ldd; } \
11+
| awk '/=> \//{print $(NF-1)} /^\//{print $1}' \
12+
| awk 'index($0,"/usr/local/")!=1 && $0 ~ "^/(usr/)?lib"' \
13+
| sed -E 's,^/(usr/)?,,g' | sort -u > /tmp/paths-$V.txt; \
14+
xargs -r dpkg-query --search < /tmp/paths-$V.txt \
15+
| awk -F: 'NF{print $1}' | sort -u > /tmp/deps-$V.txt; \
16+
echo "Runtime packages:" && cat /tmp/deps-$V.txt
17+
418
FROM ghcr.io/cubecoders/amp:debian
519
LABEL org.opencontainers.image.licenses=MIT
620

721
ENV PIP_DISABLE_PIP_VERSION_CHECK=1
822

923
ARG DEBIAN_FRONTEND=noninteractive
1024

11-
# System Python (3.11) from Debian
25+
COPY --from=py311 /tmp/deps-3.11.txt /deps/3.11.txt
26+
1227
RUN set -eux; \
1328
apt-get update; \
14-
apt-get install -y --no-install-recommends \
15-
python3.11 python3-pip python3.11-venv; \
29+
apt-get purge -y --auto-remove python3\*; \
30+
RUNTIME_DEPS="$(cat /deps/3.11.txt)"; \
31+
apt-get install -y --no-install-recommends $RUNTIME_DEPS; \
1632
apt-get clean; \
17-
rm -rf /var/lib/apt/lists/*
33+
rm -rf /var/lib/apt/lists/*
34+
35+
COPY --from=py311 /usr/local/ /usr/local/
36+
37+
RUN set -eux; \
38+
for src in idle3 pip3 pydoc3 python3 python3-config; do \
39+
dst="$(echo "$src" | tr -d 3)"; \
40+
[ -e "/usr/local/bin/$dst" ] || ln -s "/usr/local/bin/$src" "/usr/local/bin/$dst"; \
41+
done; \
42+
for shim in python3.11 python3 pip3.11 pip3 pip; do \
43+
ln -sf "/usr/local/bin/$shim" "/usr/bin/$shim"; \
44+
done

python/3.12/Dockerfile

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# Python image for AMP containers using Python 3.12
2+
# ghcr.io/cubecoders/amp:python-3.12
3+
4+
FROM python:3.12-slim-bookworm AS py312
5+
6+
RUN set -eux; \
7+
V=3.12; \
8+
P=/usr/local/bin/python$V; \
9+
D=/usr/local/lib/python$V/lib-dynload; \
10+
{ ldd "$P"; find "$D" -type f -name '*.so' -print0 | xargs -0 -n1 ldd; } \
11+
| awk '/=> \//{print $(NF-1)} /^\//{print $1}' \
12+
| awk 'index($0,"/usr/local/")!=1 && $0 ~ "^/(usr/)?lib"' \
13+
| sed -E 's,^/(usr/)?,,g' | sort -u > /tmp/paths-$V.txt; \
14+
xargs -r dpkg-query --search < /tmp/paths-$V.txt \
15+
| awk -F: 'NF{print $1}' | sort -u > /tmp/deps-$V.txt; \
16+
echo "Runtime packages:" && cat /tmp/deps-$V.txt
17+
18+
FROM ghcr.io/cubecoders/amp:debian
19+
LABEL org.opencontainers.image.licenses=MIT
20+
21+
ENV PIP_DISABLE_PIP_VERSION_CHECK=1
22+
23+
ARG DEBIAN_FRONTEND=noninteractive
24+
25+
COPY --from=py312 /tmp/deps-3.12.txt /deps/3.12.txt
26+
27+
RUN set -eux; \
28+
apt-get update; \
29+
apt-get purge -y --auto-remove python3\*; \
30+
RUNTIME_DEPS="$(cat /deps/3.12.txt)"; \
31+
apt-get install -y --no-install-recommends $RUNTIME_DEPS; \
32+
apt-get clean; \
33+
rm -rf /var/lib/apt/lists/*
34+
35+
COPY --from=py312 /usr/local/ /usr/local/
36+
37+
RUN set -eux; \
38+
for src in idle3 pip3 pydoc3 python3 python3-config; do \
39+
dst="$(echo "$src" | tr -d 3)"; \
40+
[ -e "/usr/local/bin/$dst" ] || ln -s "/usr/local/bin/$src" "/usr/local/bin/$dst"; \
41+
done; \
42+
for shim in python3.12 python3 pip3.12 pip3 pip; do \
43+
ln -sf "/usr/local/bin/$shim" "/usr/bin/$shim"; \
44+
done

python/3/Dockerfile

Lines changed: 61 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,65 @@
1-
# Python image for AMP containers including Python 3.10, 3.11 and 3.12
1+
# Python image for AMP containers including Python 3.10, 3.11 (default) and 3.12
22
# ghcr.io/cubecoders/amp:python-3
33

44
FROM python:3.10-slim-bookworm AS py310
5+
6+
RUN set -eux; \
7+
V=3.10; \
8+
P=/usr/local/bin/python$V; \
9+
D=/usr/local/lib/python$V/lib-dynload; \
10+
{ ldd "$P"; find "$D" -type f -name '*.so' -print0 | xargs -0 -n1 ldd; } \
11+
| awk '/=> \//{print $(NF-1)} /^\//{print $1}' \
12+
| awk 'index($0,"/usr/local/")!=1 && $0 ~ "^/(usr/)?lib"' \
13+
| sed -E 's,^/(usr/)?,,g' | sort -u > /tmp/paths-$V.txt; \
14+
xargs -r dpkg-query --search < /tmp/paths-$V.txt \
15+
| awk -F: 'NF{print $1}' | sort -u > /tmp/deps-$V.txt; \
16+
echo "Runtime packages:" && cat /tmp/deps-$V.txt
17+
18+
FROM python:3.11-slim-bookworm AS py311
19+
20+
RUN set -eux; \
21+
V=3.11; \
22+
P=/usr/local/bin/python$V; \
23+
D=/usr/local/lib/python$V/lib-dynload; \
24+
{ ldd "$P"; find "$D" -type f -name '*.so' -print0 | xargs -0 -n1 ldd; } \
25+
| awk '/=> \//{print $(NF-1)} /^\//{print $1}' \
26+
| awk 'index($0,"/usr/local/")!=1 && $0 ~ "^/(usr/)?lib"' \
27+
| sed -E 's,^/(usr/)?,,g' | sort -u > /tmp/paths-$V.txt; \
28+
xargs -r dpkg-query --search < /tmp/paths-$V.txt \
29+
| awk -F: 'NF{print $1}' | sort -u > /tmp/deps-$V.txt; \
30+
echo "Runtime packages:" && cat /tmp/deps-$V.txt
31+
532
FROM python:3.12-slim-bookworm AS py312
633

34+
RUN set -eux; \
35+
V=3.12; \
36+
P=/usr/local/bin/python$V; \
37+
D=/usr/local/lib/python$V/lib-dynload; \
38+
{ ldd "$P"; find "$D" -type f -name '*.so' -print0 | xargs -0 -n1 ldd; } \
39+
| awk '/=> \//{print $(NF-1)} /^\//{print $1}' \
40+
| awk 'index($0,"/usr/local/")!=1 && $0 ~ "^/(usr/)?lib"' \
41+
| sed -E 's,^/(usr/)?,,g' | sort -u > /tmp/paths-$V.txt; \
42+
xargs -r dpkg-query --search < /tmp/paths-$V.txt \
43+
| awk -F: 'NF{print $1}' | sort -u > /tmp/deps-$V.txt; \
44+
echo "Runtime packages:" && cat /tmp/deps-$V.txt
45+
746
FROM ghcr.io/cubecoders/amp:debian
847
LABEL org.opencontainers.image.licenses=MIT
948

1049
ENV PIP_DISABLE_PIP_VERSION_CHECK=1
1150

1251
ARG DEBIAN_FRONTEND=noninteractive
1352

14-
# System Python (3.11) from Debian
53+
COPY --from=py310 /tmp/deps-3.10.txt /deps/3.10.txt
54+
COPY --from=py311 /tmp/deps-3.11.txt /deps/3.11.txt
55+
COPY --from=py312 /tmp/deps-3.12.txt /deps/3.12.txt
56+
1557
RUN set -eux; \
1658
apt-get update; \
17-
apt-get install -y --no-install-recommends \
18-
python3.11 python3-pip python3.11-venv; \
59+
apt-get purge -y --auto-remove python3\*; \
60+
awk '{ if (!($0 in seen)) { print; seen[$0] } }' /deps/*.txt > /deps/all.txt; \
61+
sort -u -o /deps/all.txt /deps/all.txt; \
62+
xargs -r apt-get install -y --no-install-recommends < /deps/all.txt; \
1963
apt-get clean; \
2064
rm -rf /var/lib/apt/lists/*
2165

@@ -27,8 +71,16 @@ COPY --from=py310 /usr/local/bin/ /usr/local/bin/
2771
COPY --from=py312 /usr/local/lib/ /usr/local/lib/
2872
COPY --from=py312 /usr/local/bin/ /usr/local/bin/
2973

30-
# Make explicit version shims available in /usr/bin
31-
RUN ln -sf /usr/local/bin/python3.10 /usr/bin/python3.10 && \
32-
ln -sf /usr/local/bin/python3.12 /usr/bin/python3.12 && \
33-
ln -sf /usr/local/bin/pip3.10 /usr/bin/pip3.10 && \
34-
ln -sf /usr/local/bin/pip3.12 /usr/bin/pip3.12
74+
# Drop in Python 3.11
75+
COPY --from=py311 /usr/local/lib/ /usr/local/lib/
76+
COPY --from=py311 /usr/local/bin/ /usr/local/bin/
77+
78+
# Make explicit version shims available in /usr/bin, and make 3.11 default
79+
RUN set -eux; \
80+
for src in idle3 pip3 pydoc3 python3 python3-config; do \
81+
dst="$(echo "$src" | tr -d 3)"; \
82+
[ -e "/usr/local/bin/$dst" ] || ln -s "/usr/local/bin/$src" "/usr/local/bin/$dst"; \
83+
done; \
84+
for shim in python3.11 python3.10 python3.12 python3 pip3.11 pip3.10 pip3.12 pip3 pip; do \
85+
ln -sf "/usr/local/bin/$shim" "/usr/bin/$shim"; \
86+
done

0 commit comments

Comments
 (0)