diff --git a/Dockerfile b/Dockerfile index 1e1e3d0cae..01b2a352d9 100644 --- a/Dockerfile +++ b/Dockerfile @@ -56,6 +56,17 @@ RUN --mount=type=cache,target=/root/.cache/uv \ RUN rm -rf "${VIRTUAL_ENV}"/lib/python*/site-packages/docs \ "${VIRTUAL_ENV}"/lib/python*/site-packages/examples +# Most wheels ship their compiled extensions unstripped, carrying symbol tables and debug info that nothing needs at runtime. +# Stripping them here keeps ~130 MB out of the runtime image, which copies only the result of this stage. +# --strip-unneeded leaves everything that dynamic linking uses, so the extensions stay loadable. +# binutils only reaches this stage as a transitive of the gcc install above, so check for strip explicitly: +# the trailing `|| true` is there for individual files strip cannot handle, and would otherwise hide a missing binutils. +RUN command -v strip > /dev/null || { \ + echo "strip not found: the builder stage needs binutils" >&2; exit 1; \ + }; \ + find "${VIRTUAL_ENV}" \( -name '*.so' -o -name '*.so.*' \) -type f \ + -exec strip --strip-unneeded {} + 2>/dev/null || true + # Use a separate runtime image to run the code FROM python:${PYTHON_VERSION}-slim-${DEBIAN_VERSION} AS runtime diff --git a/documentation/changelog.rst b/documentation/changelog.rst index 70a4767d86..aa9d8f298b 100644 --- a/documentation/changelog.rst +++ b/documentation/changelog.rst @@ -13,7 +13,7 @@ New features Infrastructure / Support ------------------------- -* Shrink the Docker image by excluding dev-only dependencies and pruning stray ``docs``/``examples`` payloads bundled by ``sktime``/``scikit-base`` (issue: https://github.com/sktime/sktime/issues/10891) [see `PR #2438 `_] +* Shrink the Docker image by excluding dev-only dependencies, pruning stray ``docs``/``examples`` payloads bundled by ``sktime``/``scikit-base`` (issue: https://github.com/sktime/sktime/issues/10891), and stripping the symbol tables that the compiled extensions ship with [see `PR #2438 `_ and `PR #2439 `_] Bugfixes -----------