From f945fe1f7b1c4b652761b67a09fe3e41c06bd38e Mon Sep 17 00:00:00 2001 From: mayeut Date: Sun, 28 Apr 2019 15:25:42 +0200 Subject: [PATCH] Reduce image size Not only strip python but also custom built tools Build git without gettext/tcltk support remove precompiled pyc and pyo files after last checks done using python Overall, 42MB saved --- docker/build_scripts/build.sh | 16 +++++++++------- docker/build_scripts/build_utils.sh | 2 +- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/docker/build_scripts/build.sh b/docker/build_scripts/build.sh index c5bbee725..1106788ef 100755 --- a/docker/build_scripts/build.sh +++ b/docker/build_scripts/build.sh @@ -183,13 +183,8 @@ find /opt/_internal -name '*.a' -print0 | xargs -0 rm -f # *everything*, including non-ELF files: find /opt/_internal -type f -print0 \ | xargs -0 -n1 strip --strip-unneeded 2>/dev/null || true - -# We do not need the Python test suites, or indeed the precompiled .pyc and -# .pyo files. Partially cribbed from: -# https://github.com/docker-library/python/blob/master/3.4/slim/Dockerfile -find /opt/_internal -depth \ - \( -type d -a -name test -o -name tests \) \ - -o \( -type f -a -name '*.pyc' -o -name '*.pyo' \) | xargs rm -rf +find /usr/local -type f -print0 \ + | xargs -0 -n1 strip --strip-unneeded 2>/dev/null || true for PYTHON in /opt/python/*/bin/python; do # Smoke test to make sure that our Pythons work, and do indeed detect as @@ -199,6 +194,13 @@ for PYTHON in /opt/python/*/bin/python; do $PYTHON $MY_DIR/ssl-check.py done +# We do not need the Python test suites, or indeed the precompiled .pyc and +# .pyo files. Partially cribbed from: +# https://github.com/docker-library/python/blob/master/3.4/slim/Dockerfile +find /opt/_internal -depth \ + \( -type d -a -name test -o -name tests \) \ + -o \( -type f -a -name '*.pyc' -o -name '*.pyo' \) | xargs rm -rf + # Fix libc headers to remain compatible with C99 compilers. find /usr/include/ -type f -exec sed -i 's/\bextern _*inline_*\b/extern __inline __attribute__ ((__gnu_inline__))/g' {} + diff --git a/docker/build_scripts/build_utils.sh b/docker/build_scripts/build_utils.sh index c84ed8cb5..d9cfea1e3 100755 --- a/docker/build_scripts/build_utils.sh +++ b/docker/build_scripts/build_utils.sh @@ -167,7 +167,7 @@ function build_git { fetch_source v${git_fname}.tar.gz ${GIT_DOWNLOAD_URL} check_sha256sum v${git_fname}.tar.gz ${git_sha256} tar -xzf v${git_fname}.tar.gz - (cd git-${git_fname} && make install prefix=/usr/local LDFLAGS="-L/usr/local/ssl/lib -ldl" CFLAGS="-I/usr/local/ssl/include" > /dev/null) + (cd git-${git_fname} && make install prefix=/usr/local NO_GETTEXT=1 NO_TCLTK=1 LDFLAGS="-L/usr/local/ssl/lib -ldl" CFLAGS="-I/usr/local/ssl/include" > /dev/null) rm -rf git-${git_fname} v${git_fname}.tar.gz }