1- # Python image for AMP containers including Python 3.10, 3.11 (default) and 3.12
1+ # Python image for AMP containers including Python 3.10, 3.11 (default) and 3.12 from upstream
22# ghcr.io/cubecoders/amp:python-3
33
44FROM python:3.10-slim-bookworm AS py310
5+
6+ ENV DEBIAN_FRONTEND="noninteractive"
7+
8+ ARG PYTHON_VERSION="3.10"
9+
10+ COPY scripts/python/find-deps.sh /usr/local/bin/find-deps.sh
11+ RUN chmod +x /usr/local/bin/find-deps.sh
12+
13+ RUN set -eux; \
14+ /usr/local/bin/find-deps.sh ${PYTHON_VERSION} >/tmp/${PYTHON_VERSION}-run-deps.txt
15+
16+ FROM python:3.11-slim-bookworm AS py311
17+
18+ ENV DEBIAN_FRONTEND="noninteractive"
19+
20+ ARG PYTHON_VERSION="3.11"
21+
22+ COPY scripts/python/find-deps.sh /usr/local/bin/find-deps.sh
23+ RUN chmod +x /usr/local/bin/find-deps.sh
24+
25+ RUN set -eux; \
26+ /usr/local/bin/find-deps.sh ${PYTHON_VERSION} >/tmp/${PYTHON_VERSION}-run-deps.txt
27+
528FROM python:3.12-slim-bookworm AS py312
629
7- FROM ghcr.io/cubecoders/amp:python-3.11
30+ ENV DEBIAN_FRONTEND="noninteractive"
31+
32+ ARG PYTHON_VERSION="3.12"
33+
34+ COPY scripts/python/find-deps.sh /usr/local/bin/find-deps.sh
35+ RUN chmod +x /usr/local/bin/find-deps.sh
36+
37+ RUN set -eux; \
38+ /usr/local/bin/find-deps.sh ${PYTHON_VERSION} >/tmp/${PYTHON_VERSION}-run-deps.txt
39+
40+ FROM ghcr.io/cubecoders/amp:debian
841LABEL org.opencontainers.image.licenses=MIT
942
43+ ENV PIP_DISABLE_PIP_VERSION_CHECK="1"
1044ENV DEBIAN_FRONTEND="noninteractive"
1145
46+ ARG PYTHON_DEFAULT="3.11"
47+ ARG PYTHON_NON_DEFAULT="3.10 3.12"
48+
1249# Drop in upstream Python 3.10
13- COPY --from=py310 /usr/local/bin/python3.10 /usr/local/bin/
14- COPY --from=py310 /usr/local/bin/pip3.10 /usr/local/bin/
15- COPY --from=py310 /usr/local/lib/python3.10/ /usr/local/lib/python3.10/
16- COPY --from=py310 /usr/local/lib/libpython3.10* /usr/local/lib/
50+ COPY --from=py310 /usr/local/ /usr/local/
51+
52+ COPY --from=py310 /tmp/3.10-run-deps.txt /tmp/3.10-run-deps.txt
1753
1854# Drop in upstream Python 3.12
19- COPY --from=py312 /usr/local/bin/python3.12 /usr/local/bin/
20- COPY --from=py312 /usr/local/bin/pip3.12 /usr/local/bin/
21- COPY --from=py312 /usr/local/lib/python3.12/ /usr/local/lib/python3.12/
22- COPY --from=py312 /usr/local/lib/libpython3.12* /usr/local/lib/
55+ COPY --from=py312 /usr/local/ /usr/local/
56+
57+ COPY --from=py312 /tmp/3.12-run-deps.txt /tmp/3.12-run-deps.txt
58+
59+ # Drop in upstream Python 3.11 (default last)
60+ COPY --from=py311 /usr/local/ /usr/local/
61+
62+ COPY --from=py311 /tmp/3.11-run-deps.txt /tmp/3.11-run-deps.txt
2363
24- # Clean up
2564RUN set -eux; \
26- python3.10 -m pip --no-cache-dir install --upgrade pip setuptools wheel; \
27- python3.12 -m pip --no-cache-dir install --upgrade pip setuptools wheel; \
28- for shim in python3.10 python3.12 pip3.10 pip3.12; do \
65+ apt-get update; \
66+ # Purge gdb from base image to remove conflicting Python libs
67+ apt-get purge gdb -y --autoremove; \
68+ \
69+ sort -u /tmp/*-run-deps.txt \
70+ | awk 'NF && $1 !~ /^#/' \
71+ | xargs -r apt-get install -o APT::Keep-Downloaded-Packages="false" -y --no-install-recommends; \
72+ apt-get clean; \
73+ rm -rf /var/lib/apt/lists/* /tmp/*-run-deps.txt; \
74+ \
75+ for v in ${PYTHON_NON_DEFAULT}; do \
76+ python${v} -m pip install --no-cache-dir --upgrade pip setuptools wheel; \
77+ for shim in python${v} pip${v}; do \
78+ [ -x "/usr/local/bin/${shim}" ] && ln -sf "/usr/local/bin/${shim}" "/usr/bin/${shim}" ; \
79+ done; \
80+ done; \
81+ python${PYTHON_DEFAULT} -m pip install --no-cache-dir --upgrade pip setuptools wheel; \
82+ for shim in python python3 python${PYTHON_DEFAULT} pip pip3 pip${PYTHON_DEFAULT}; do \
2983 ln -sf "/usr/local/bin/${shim}" "/usr/bin/${shim}" ; \
3084 done
0 commit comments