From a256ad19147b76a41eb4aa551d914d24ca73162a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9mence=20Lesn=C3=A9?= Date: Thu, 24 Oct 2024 18:22:31 +0200 Subject: [PATCH] perf: Lower images sizes --- src/docker/Dockerfile-bookworm | 7 +++++-- src/docker/Dockerfile-bullseye | 7 +++++-- src/docker/Dockerfile-focal | 7 +++++-- src/docker/Dockerfile-jammy | 7 +++++-- src/docker/Dockerfile-noble | 7 +++++-- src/docker/Dockerfile-ubi8 | 7 +++++-- src/docker/Dockerfile-ubi9 | 7 +++++-- src/docker/Dockerfile-win-ltsc2019 | 11 ++++++++--- src/docker/Dockerfile-win-ltsc2022 | 11 ++++++++--- 9 files changed, 51 insertions(+), 20 deletions(-) diff --git a/src/docker/Dockerfile-bookworm b/src/docker/Dockerfile-bookworm index d1d8b0e4..14bee7b7 100644 --- a/src/docker/Dockerfile-bookworm +++ b/src/docker/Dockerfile-bookworm @@ -107,6 +107,7 @@ RUN --mount=target=/var/lib/apt/lists,type=cache,sharing=locked --mount=target=/ zlib1g-dev \ && curl -LsSf --retry 8 --retry-all-errors https://www.python.org/ftp/python/${PYTHON_VERSION}/Python-${PYTHON_VERSION}.tgz -o python.tgz \ && tar -xzf python.tgz \ + && rm python.tgz \ && cd Python-${PYTHON_VERSION} \ && ./configure \ --enable-optimizations \ @@ -114,9 +115,11 @@ RUN --mount=target=/var/lib/apt/lists,type=cache,sharing=locked --mount=target=/ --with-lto \ && make -j$(nproc) \ && make install \ - && find / -depth -type d -name __pycache__ -exec rm -rf {} \; 2> /dev/null \ + && cd .. \ + && rm -rf Python-${PYTHON_VERSION} \ && python3 --version \ - && python3 -m pip --version + && python3 -m pip --version \ + && find / -depth -type d -name __pycache__ -exec rm -rf {} \; 2> /dev/null FROM base diff --git a/src/docker/Dockerfile-bullseye b/src/docker/Dockerfile-bullseye index 8ba1981e..a84b0e36 100644 --- a/src/docker/Dockerfile-bullseye +++ b/src/docker/Dockerfile-bullseye @@ -105,6 +105,7 @@ RUN --mount=target=/var/lib/apt/lists,type=cache,sharing=locked --mount=target=/ zlib1g-dev \ && curl -LsSf --retry 8 --retry-all-errors https://www.python.org/ftp/python/${PYTHON_VERSION}/Python-${PYTHON_VERSION}.tgz -o python.tgz \ && tar -xzf python.tgz \ + && rm python.tgz \ && cd Python-${PYTHON_VERSION} \ && ./configure \ --enable-optimizations \ @@ -112,9 +113,11 @@ RUN --mount=target=/var/lib/apt/lists,type=cache,sharing=locked --mount=target=/ --with-lto \ && make -j$(nproc) \ && make install \ - && find / -depth -type d -name __pycache__ -exec rm -rf {} \; 2> /dev/null \ + && cd .. \ + && rm -rf Python-${PYTHON_VERSION} \ && python3 --version \ - && python3 -m pip --version + && python3 -m pip --version \ + && find / -depth -type d -name __pycache__ -exec rm -rf {} \; 2> /dev/null FROM base diff --git a/src/docker/Dockerfile-focal b/src/docker/Dockerfile-focal index 0325dd8e..1f69d802 100644 --- a/src/docker/Dockerfile-focal +++ b/src/docker/Dockerfile-focal @@ -104,6 +104,7 @@ RUN --mount=target=/var/lib/apt/lists,type=cache,sharing=locked --mount=target=/ zlib1g-dev \ && curl -LsSf --retry 8 https://www.python.org/ftp/python/${PYTHON_VERSION}/Python-${PYTHON_VERSION}.tgz -o python.tgz \ && tar -xzf python.tgz \ + && rm python.tgz \ && cd Python-${PYTHON_VERSION} \ && ./configure \ --enable-optimizations \ @@ -111,9 +112,11 @@ RUN --mount=target=/var/lib/apt/lists,type=cache,sharing=locked --mount=target=/ --with-lto \ && make -j$(nproc) \ && make install \ - && find / -depth -type d -name __pycache__ -exec rm -rf {} \; 2> /dev/null \ + && cd .. \ + && rm -rf Python-${PYTHON_VERSION} \ && python3 --version \ - && python3 -m pip --version + && python3 -m pip --version \ + && find / -depth -type d -name __pycache__ -exec rm -rf {} \; 2> /dev/null FROM base diff --git a/src/docker/Dockerfile-jammy b/src/docker/Dockerfile-jammy index e99acdb6..952ba94d 100644 --- a/src/docker/Dockerfile-jammy +++ b/src/docker/Dockerfile-jammy @@ -104,6 +104,7 @@ RUN --mount=target=/var/lib/apt/lists,type=cache,sharing=locked --mount=target=/ zlib1g-dev \ && curl -LsSf --retry 8 --retry-all-errors https://www.python.org/ftp/python/${PYTHON_VERSION}/Python-${PYTHON_VERSION}.tgz -o python.tgz \ && tar -xzf python.tgz \ + && rm python.tgz \ && cd Python-${PYTHON_VERSION} \ && ./configure \ --enable-optimizations \ @@ -111,9 +112,11 @@ RUN --mount=target=/var/lib/apt/lists,type=cache,sharing=locked --mount=target=/ --with-lto \ && make -j$(nproc) \ && make install \ - && find / -depth -type d -name __pycache__ -exec rm -rf {} \; 2> /dev/null \ + && cd .. \ + && rm -rf Python-${PYTHON_VERSION} \ && python3 --version \ - && python3 -m pip --version + && python3 -m pip --version \ + && find / -depth -type d -name __pycache__ -exec rm -rf {} \; 2> /dev/null FROM base diff --git a/src/docker/Dockerfile-noble b/src/docker/Dockerfile-noble index c7cdcb4a..694e5d10 100644 --- a/src/docker/Dockerfile-noble +++ b/src/docker/Dockerfile-noble @@ -107,6 +107,7 @@ RUN --mount=target=/var/lib/apt/lists,type=cache,sharing=locked --mount=target=/ zlib1g-dev \ && curl -LsSf --retry 8 --retry-all-errors https://www.python.org/ftp/python/${PYTHON_VERSION}/Python-${PYTHON_VERSION}.tgz -o python.tgz \ && tar -xzf python.tgz \ + && rm python.tgz \ && cd Python-${PYTHON_VERSION} \ && ./configure \ --enable-optimizations \ @@ -114,9 +115,11 @@ RUN --mount=target=/var/lib/apt/lists,type=cache,sharing=locked --mount=target=/ --with-lto \ && make -j$(nproc) \ && make install \ - && find / -depth -type d -name __pycache__ -exec rm -rf {} \; 2> /dev/null \ + && cd .. \ + && rm -rf Python-${PYTHON_VERSION} \ && python3 --version \ - && python3 -m pip --version + && python3 -m pip --version \ + && find / -depth -type d -name __pycache__ -exec rm -rf {} \; 2> /dev/null FROM base diff --git a/src/docker/Dockerfile-ubi8 b/src/docker/Dockerfile-ubi8 index 93d17e17..d7241650 100644 --- a/src/docker/Dockerfile-ubi8 +++ b/src/docker/Dockerfile-ubi8 @@ -96,6 +96,7 @@ RUN --mount=target=/var/cache/yum,type=cache,sharing=locked \ zlib-devel \ && curl -LsSf --retry 8 https://www.python.org/ftp/python/${PYTHON_VERSION}/Python-${PYTHON_VERSION}.tgz -o python.tgz \ && tar -xzf python.tgz \ + && rm python.tgz \ && cd Python-${PYTHON_VERSION} \ && ./configure \ --enable-optimizations \ @@ -103,9 +104,11 @@ RUN --mount=target=/var/cache/yum,type=cache,sharing=locked \ --with-lto \ && make -j$(nproc) \ && make install \ - && find / -depth -type d -name __pycache__ -exec rm -rf {} \; 2> /dev/null \ + && cd .. \ + && rm -rf Python-${PYTHON_VERSION} \ && python3 --version \ - && python3 -m pip --version + && python3 -m pip --version \ + && find / -depth -type d -name __pycache__ -exec rm -rf {} \; 2> /dev/null FROM base diff --git a/src/docker/Dockerfile-ubi9 b/src/docker/Dockerfile-ubi9 index f55e1a64..26bf5467 100644 --- a/src/docker/Dockerfile-ubi9 +++ b/src/docker/Dockerfile-ubi9 @@ -95,6 +95,7 @@ RUN --mount=target=/var/cache/yum,type=cache,sharing=locked \ zlib-devel \ && curl -LsSf --retry 8 --retry-all-errors https://www.python.org/ftp/python/${PYTHON_VERSION}/Python-${PYTHON_VERSION}.tgz -o python.tgz \ && tar -xzf python.tgz \ + && rm python.tgz \ && cd Python-${PYTHON_VERSION} \ && ./configure \ --enable-optimizations \ @@ -102,9 +103,11 @@ RUN --mount=target=/var/cache/yum,type=cache,sharing=locked \ --with-lto \ && make -j$(nproc) \ && make install \ - && find / -depth -type d -name __pycache__ -exec rm -rf {} \; 2> /dev/null \ + && cd .. \ + && rm -rf Python-${PYTHON_VERSION} \ && python3 --version \ - && python3 -m pip --version + && python3 -m pip --version \ + && find / -depth -type d -name __pycache__ -exec rm -rf {} \; 2> /dev/null FROM base diff --git a/src/docker/Dockerfile-win-ltsc2019 b/src/docker/Dockerfile-win-ltsc2019 index 36301259..cd047d71 100644 --- a/src/docker/Dockerfile-win-ltsc2019 +++ b/src/docker/Dockerfile-win-ltsc2019 @@ -39,14 +39,18 @@ ARG PYTHON_VERSION ENV PYTHON_VERSION=${PYTHON_VERSION} RUN curl -LsSf --retry 8 --retry-all-errors "https://python.org/ftp/python/${Env:PYTHON_VERSION}/python-${Env:PYTHON_VERSION}-amd64.exe" -o python.exe \ && Start-Process python.exe -Wait -ArgumentList '/quiet InstallAllUsers=1 PrependPath=1 Include_test=0' \ - && Remove-Item python.exe + && Remove-Item python.exe \ + && Get-ChildItem 'C:\\' -Include '__pycache__' -Recurse -Force | Remove-Item -Recurse -Force + +# Install Python build tools RUN python --version \ && python -m pip \ --disable-pip-version-check \ --no-cache-dir \ --quiet \ install \ - setuptools wheel + setuptools wheel \ + && Get-ChildItem 'C:\\' -Include '__pycache__' -Recurse -Force | Remove-Item -Recurse -Force # Install Azure CLI, then verify installation ARG AZURE_CLI_VERSION @@ -57,7 +61,8 @@ RUN python -m pip \ --quiet \ install \ "azure-cli==${Env:AZURE_CLI_VERSION}" \ - && az version + && az version \ + && Get-ChildItem 'C:\\' -Include '__pycache__' -Recurse -Force | Remove-Item -Recurse -Force # Install AWS CLI, then verify installation ARG AWS_CLI_VERSION diff --git a/src/docker/Dockerfile-win-ltsc2022 b/src/docker/Dockerfile-win-ltsc2022 index 06bebb2c..3b452389 100644 --- a/src/docker/Dockerfile-win-ltsc2022 +++ b/src/docker/Dockerfile-win-ltsc2022 @@ -39,14 +39,18 @@ ARG PYTHON_VERSION ENV PYTHON_VERSION=${PYTHON_VERSION} RUN curl -LsSf --retry 8 --retry-all-errors "https://python.org/ftp/python/${Env:PYTHON_VERSION}/python-${Env:PYTHON_VERSION}-amd64.exe" -o python.exe \ && Start-Process python.exe -Wait -ArgumentList '/quiet InstallAllUsers=1 PrependPath=1 Include_test=0' \ - && Remove-Item python.exe + && Remove-Item python.exe \ + && Get-ChildItem 'C:\\' -Include '__pycache__' -Recurse -Force | Remove-Item -Recurse -Force + +# Install Python build tools RUN python --version \ && python -m pip \ --disable-pip-version-check \ --no-cache-dir \ --quiet \ install \ - setuptools wheel + setuptools wheel \ + && Get-ChildItem 'C:\\' -Include '__pycache__' -Recurse -Force | Remove-Item -Recurse -Force # Install Azure CLI, then verify installation ARG AZURE_CLI_VERSION @@ -57,7 +61,8 @@ RUN python -m pip \ --quiet \ install \ "azure-cli==${Env:AZURE_CLI_VERSION}" \ - && az version + && az version \ + && Get-ChildItem 'C:\\' -Include '__pycache__' -Recurse -Force | Remove-Item -Recurse -Force # Install AWS CLI, then verify installation ARG AWS_CLI_VERSION