1+ # Python image for AMP containers using Python 3.10 from upstream
2+ # ghcr.io/cubecoders/amp:python-3.10
3+
4+ FROM 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 ghcr.io/cubecoders/amp:debian
17+ LABEL org.opencontainers.image.licenses=MIT
18+
19+ ENV PIP_DISABLE_PIP_VERSION_CHECK="1"
20+ ENV DEBIAN_FRONTEND="noninteractive"
21+
22+ ARG PYTHON_VERSION="3.10"
23+
24+ # Drop in upstream Python 3.10
25+ COPY --from=py310 /usr/local/ /usr/local/
26+
27+ COPY --from=py310 /tmp/${PYTHON_VERSION}-run-deps.txt /tmp/${PYTHON_VERSION}-run-deps.txt
28+
29+ RUN set -eux; \
30+ apt-get update; \
31+ # Purge system Python binaries and libs
32+ PYTHON_PKGS="$(dpkg-query -W -f='${binary:Package}\n ' \
33+ | awk '/^(python3($|[.:_-])|libpython3($|[.:_-]))/ {print}' \
34+ | sort -u)" ; \
35+ printf '%s\n ' "${PYTHON_PKGS}" | xargs -r apt-get purge --auto-remove -y; \
36+ \
37+ sort -u /tmp/${PYTHON_VERSION}-run-deps.txt \
38+ | awk 'NF && $1 !~ /^#/' \
39+ | xargs -r apt-get install -o APT::Keep-Downloaded-Packages="false" -y --no-install-recommends; \
40+ apt-get clean; \
41+ rm -rf /var/lib/apt/lists/* /tmp/${PYTHON_VERSION}-run-deps.txt; \
42+ \
43+ python${PYTHON_VERSION} -m pip install --no-cache-dir --upgrade pip setuptools wheel; \
44+ for shim in python python3 python${PYTHON_VERSION} pip pip3 pip${PYTHON_VERSION}; do \
45+ ln -sf "/usr/local/bin/${shim}" "/usr/bin/${shim}" ; \
46+ done
0 commit comments