Skip to content

Commit d5d9374

Browse files
committed
Make python purge more robust
1 parent 4b36d93 commit d5d9374

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

python/3.11/Dockerfile

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,11 @@ COPY --from=py311 /tmp/${PYTHON_VERSION}-run-deps.txt /tmp/${PYTHON_VERSI
2828

2929
RUN set -eux; \
3030
apt-get update; \
31-
# Purge gdb from base image to remove conflicting Python libs
32-
apt-get purge gdb -y --autoremove; \
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; \
3336
\
3437
sort -u /tmp/${PYTHON_VERSION}-run-deps.txt \
3538
| awk 'NF && $1 !~ /^#/' \

python/3/Dockerfile

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,11 @@ COPY --from=py311 /tmp/3.11-run-deps.txt /tmp/3.11-run-deps.txt
6363

6464
RUN set -eux; \
6565
apt-get update; \
66-
# Purge gdb from base image to remove conflicting Python libs
67-
apt-get purge gdb -y --autoremove; \
66+
# Purge system Python binaries and libs
67+
PYTHON_PKGS="$(dpkg-query -W -f='${binary:Package}\n' \
68+
| awk '/^(python3($|[.:_-])|libpython3($|[.:_-]))/ {print}' \
69+
| sort -u)"; \
70+
printf '%s\n' "${PYTHON_PKGS}" | xargs -r apt-get purge --auto-remove -y; \
6871
\
6972
sort -u /tmp/*-run-deps.txt \
7073
| awk 'NF && $1 !~ /^#/' \

0 commit comments

Comments
 (0)