From c4feaf9f83f352f386049ebfe67f4a07f33afac3 Mon Sep 17 00:00:00 2001 From: Konstantin Demin Date: Thu, 10 Oct 2024 00:23:55 +0300 Subject: [PATCH] image: cleanup layers a bit more mostly Python-related cleanup --- Dockerfile.base | 15 +++++++++++++++ Dockerfile.deps | 9 ++++++++- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/Dockerfile.base b/Dockerfile.base index 1b471c1..bba3987 100644 --- a/Dockerfile.base +++ b/Dockerfile.base @@ -211,14 +211,29 @@ RUN pip-env.sh pip list --format freeze \ RUN libpython="${PYTHON_SITE_PACKAGES%/*}" ; \ rm -rfv \ /usr/local/bin/idle* \ + /usr/local/bin/pydoc* \ "${libpython}/ensurepip/_bundled" \ "${libpython}/idlelib" \ + "${libpython}/pydoc.py" \ + "${libpython}/pydoc_data" \ "${libpython}/tkinter" \ "${libpython}/turtle.py" \ "${libpython}/turtledemo" \ ; \ + rm -rfv \ + "${PYTHON_SITE_PACKAGES}/pkg_resources/tests" \ + "${PYTHON_SITE_PACKAGES}/setuptools/tests" \ + "${PYTHON_SITE_PACKAGES}/setuptools/_distutils/tests" \ + "${PYTHON_SITE_PACKAGES}/setuptools/_vendor/importlib_resources/tests" \ + ; \ + find "${PYTHON_SITE_PACKAGES}/" -iname '*.exe' -ls -delete ; \ python-rm-cache.sh /usr/local +## adjust pip/certifi +RUN certifi_pem="${PYTHON_SITE_PACKAGES}/pip/_vendor/certifi/cacert.pem" ; \ + rm -f "${certifi_pem}" ; \ + ln -s /etc/ssl/certs/ca-certificates.crt "${certifi_pem}" + RUN find /usr/local/sbin/ ! -type d -ls -delete ; \ find /run/ -mindepth 1 -ls -delete || : ; \ install -d -m 01777 /run/lock diff --git a/Dockerfile.deps b/Dockerfile.deps index 72db77f..0c6fbef 100644 --- a/Dockerfile.deps +++ b/Dockerfile.deps @@ -41,12 +41,19 @@ RUN w=$(mktemp -d) ; : "${w:?}" ; \ echo ; \ find "${PYTHON_SITE_PACKAGES}/" -type f -name '*.so*' -printf '%p\0' \ | sed -zE '/rust/d' \ - | xargs -0r strip --verbose --strip-debug ; \ + | xargs -0r strip --verbose --strip-debug --strip-unneeded ; \ echo ; \ find "${PYTHON_SITE_PACKAGES}/" -type f -name '*.so*' -exec ls -l {} + ; \ apt-remove.sh build-essential ; \ apt-clean.sh +## avoid changing already present packages +RUN find "${PYTHON_SITE_PACKAGES}/" -mindepth 1 -maxdepth 1 -printf '%P\0' \ + | sed -zEn \ + -e '/^((pip|setuptools|wheel)-.+\.dist-info|distutils-precedence\.pth|_distutils_hack|pip|pkg_resources|setuptools|wheel)$/p' \ + | env -C "${PYTHON_SITE_PACKAGES}" xargs -0r \ + rm -rf + ## --- FROM base AS deps