From 7809e1398d1cb2221aedec71e3dd883047b1ff1a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9mence=20Lesn=C3=A9?= Date: Thu, 24 Oct 2024 18:22:50 +0200 Subject: [PATCH] perf: Add shared build cache See: https://github.com/moby/buildkit/issues/2598 --- src/docker/Dockerfile-bookworm | 31 ++++++++++++++++++++----------- src/docker/Dockerfile-bullseye | 31 ++++++++++++++++++++----------- src/docker/Dockerfile-focal | 31 ++++++++++++++++++++----------- src/docker/Dockerfile-jammy | 31 ++++++++++++++++++++----------- src/docker/Dockerfile-noble | 31 ++++++++++++++++++++----------- src/docker/Dockerfile-ubi8 | 32 +++++++++++++++++++++----------- src/docker/Dockerfile-ubi9 | 32 +++++++++++++++++++++----------- 7 files changed, 142 insertions(+), 77 deletions(-) diff --git a/src/docker/Dockerfile-bookworm b/src/docker/Dockerfile-bookworm index 14bee7b7..7a45a900 100644 --- a/src/docker/Dockerfile-bookworm +++ b/src/docker/Dockerfile-bookworm @@ -21,7 +21,7 @@ ENV PIP_BREAK_SYSTEM_PACKAGES=1 # - zsh, for inter-operability RUN rm -f /etc/apt/apt.conf.d/docker-clean \ && echo 'Binary::apt::APT::Keep-Downloaded-Packages "true";' > /etc/apt/apt.conf.d/keep-cache -RUN --mount=target=/var/lib/apt/lists,type=cache,sharing=locked --mount=target=/var/cache,type=cache,sharing=locked \ +RUN --mount=target=/var/lib/apt/lists,type=cache,id=apt-lists-${TARGETPLATFORM},sharing=locked --mount=target=/var/cache,type=cache,id=var-cache-${TARGETPLATFORM},sharing=locked \ apt-get update -q \ && apt-get install -y -q --no-install-recommends \ build-essential \ @@ -71,10 +71,15 @@ RUN go version # Install RootlessKit, then verify installation ARG ROOTLESSKIT_VERSION ENV ROOTLESSKIT_VERSION=${ROOTLESSKIT_VERSION} -RUN git clone --depth 1 --branch v${ROOTLESSKIT_VERSION} https://github.com/rootless-containers/rootlesskit.git rootlesskit \ - && make --directory rootlesskit \ - && make --directory rootlesskit install \ +RUN --mount=target=/rootlesskit-${ROOTLESSKIT_VERSION},type=cache,id=rootlesskit-${ROOTLESSKIT_VERSION}-${TARGETPLATFORM},sharing=locked \ + git clone --depth 1 --branch v${ROOTLESSKIT_VERSION} https://github.com/rootless-containers/rootlesskit.git rootlesskit \ + # Ugly but that's work + && cp -r rootlesskit/* rootlesskit-${ROOTLESSKIT_VERSION} \ && rm -rf rootlesskit \ + && cd rootlesskit-${ROOTLESSKIT_VERSION} \ + && make \ + && make install \ + && cd .. \ && rootlesskit --version \ && rootlessctl --version @@ -83,7 +88,7 @@ FROM base AS python # Build Python 3.12 from source, then verify installation ARG PYTHON_VERSION ENV PYTHON_VERSION=${PYTHON_VERSION} -RUN --mount=target=/var/lib/apt/lists,type=cache,sharing=locked --mount=target=/var/cache,type=cache,sharing=locked \ +RUN --mount=target=/var/lib/apt/lists,type=cache,id=apt-lists-${TARGETPLATFORM},sharing=locked --mount=target=/var/cache,type=cache,id=var-cache-${TARGETPLATFORM},sharing=locked --mount=target=/Python-${PYTHON_VERSION},type=cache,id=python-${PYTHON_VERSION}-${TARGETPLATFORM},sharing=locked \ apt-get update -q \ && apt-get install -y -q --no-install-recommends \ g++ \ @@ -109,14 +114,18 @@ RUN --mount=target=/var/lib/apt/lists,type=cache,sharing=locked --mount=target=/ && tar -xzf python.tgz \ && rm python.tgz \ && cd Python-${PYTHON_VERSION} \ + && gnu_arch="$(dpkg-architecture --query DEB_BUILD_GNU_TYPE)" \ && ./configure \ + --build=$gnu_arch \ --enable-optimizations \ --with-ensurepip=install \ --with-lto \ - && make -j$(nproc) \ + && make profile-removal \ + && extra_cflags="$(dpkg-buildflags --get CFLAGS)" \ + && ldflags="$(dpkg-buildflags --get LDFLAGS)" \ + && make -j $(nproc) "EXTRA_CFLAGS=${extra_cflags:-}" "LDFLAGS=${ldflags:-}" \ && make install \ && cd .. \ - && rm -rf Python-${PYTHON_VERSION} \ && python3 --version \ && python3 -m pip --version \ && find / -depth -type d -name __pycache__ -exec rm -rf {} \; 2> /dev/null @@ -132,9 +141,9 @@ RUN ln -s /usr/local/bin/python3.12 /usr/local/bin/python3 \ && python3 -m pip --version # Install Python build tools -RUN python3 -m pip \ +RUN --mount=target=/${USER}/.cache/pip,type=cache,id=pip-${TARGETPLATFORM} \ + python3 -m pip \ --disable-pip-version-check \ - --no-cache-dir \ --quiet \ install \ setuptools wheel \ @@ -143,9 +152,9 @@ RUN python3 -m pip \ # Install Azure CLI, then verify installation ARG AZURE_CLI_VERSION ENV AZURE_CLI_VERSION=${AZURE_CLI_VERSION} -RUN python3 -m pip \ +RUN --mount=target=/${USER}/.cache/pip,type=cache,id=pip-${TARGETPLATFORM} \ + python3 -m pip \ --disable-pip-version-check \ - --no-cache-dir \ --quiet \ install \ azure-cli==${AZURE_CLI_VERSION} \ diff --git a/src/docker/Dockerfile-bullseye b/src/docker/Dockerfile-bullseye index a84b0e36..6059b50e 100644 --- a/src/docker/Dockerfile-bullseye +++ b/src/docker/Dockerfile-bullseye @@ -18,7 +18,7 @@ ENV PYTHONDONTWRITEBYTECODE=1 # - zsh, for inter-operability RUN rm -f /etc/apt/apt.conf.d/docker-clean \ && echo 'Binary::apt::APT::Keep-Downloaded-Packages "true";' > /etc/apt/apt.conf.d/keep-cache -RUN --mount=target=/var/lib/apt/lists,type=cache,sharing=locked --mount=target=/var/cache,type=cache,sharing=locked \ +RUN --mount=target=/var/lib/apt/lists,type=cache,id=apt-lists-${TARGETPLATFORM},sharing=locked --mount=target=/var/cache,type=cache,id=var-cache-${TARGETPLATFORM},sharing=locked \ apt-get update -q \ && apt-get install -y -q --no-install-recommends \ build-essential \ @@ -68,10 +68,15 @@ RUN go version # Install RootlessKit, then verify installation ARG ROOTLESSKIT_VERSION ENV ROOTLESSKIT_VERSION=${ROOTLESSKIT_VERSION} -RUN git clone --depth 1 --branch v${ROOTLESSKIT_VERSION} https://github.com/rootless-containers/rootlesskit.git rootlesskit \ - && make --directory rootlesskit \ - && make --directory rootlesskit install \ +RUN --mount=target=/rootlesskit-${ROOTLESSKIT_VERSION},type=cache,id=rootlesskit-${ROOTLESSKIT_VERSION}-${TARGETPLATFORM},sharing=locked \ + git clone --depth 1 --branch v${ROOTLESSKIT_VERSION} https://github.com/rootless-containers/rootlesskit.git rootlesskit \ + # Ugly but that's work + && cp -r rootlesskit/* rootlesskit-${ROOTLESSKIT_VERSION} \ && rm -rf rootlesskit \ + && cd rootlesskit-${ROOTLESSKIT_VERSION} \ + && make \ + && make install \ + && cd .. \ && rootlesskit --version \ && rootlessctl --version @@ -80,7 +85,7 @@ FROM base AS python # Build Python 3.12 from source, then verify installation ARG PYTHON_VERSION ENV PYTHON_VERSION=${PYTHON_VERSION} -RUN --mount=target=/var/lib/apt/lists,type=cache,sharing=locked --mount=target=/var/cache,type=cache,sharing=locked \ +RUN --mount=target=/var/lib/apt/lists,type=cache,id=apt-lists-${TARGETPLATFORM},sharing=locked --mount=target=/var/cache,type=cache,id=var-cache-${TARGETPLATFORM},sharing=locked --mount=target=/Python-${PYTHON_VERSION},type=cache,id=python-${PYTHON_VERSION}-${TARGETPLATFORM},sharing=locked \ apt-get update -q \ && apt-get install -y -q --no-install-recommends \ g++ \ @@ -107,14 +112,18 @@ RUN --mount=target=/var/lib/apt/lists,type=cache,sharing=locked --mount=target=/ && tar -xzf python.tgz \ && rm python.tgz \ && cd Python-${PYTHON_VERSION} \ + && gnu_arch="$(dpkg-architecture --query DEB_BUILD_GNU_TYPE)" \ && ./configure \ + --build=$gnu_arch \ --enable-optimizations \ --with-ensurepip=install \ --with-lto \ - && make -j$(nproc) \ + && make profile-removal \ + && extra_cflags="$(dpkg-buildflags --get CFLAGS)" \ + && ldflags="$(dpkg-buildflags --get LDFLAGS)" \ + && make -j $(nproc) "EXTRA_CFLAGS=${extra_cflags:-}" "LDFLAGS=${ldflags:-}" \ && make install \ && cd .. \ - && rm -rf Python-${PYTHON_VERSION} \ && python3 --version \ && python3 -m pip --version \ && find / -depth -type d -name __pycache__ -exec rm -rf {} \; 2> /dev/null @@ -130,9 +139,9 @@ RUN ln -s /usr/local/bin/python3.12 /usr/local/bin/python3 \ && python3 -m pip --version # Install Python build tools -RUN python3 -m pip \ +RUN --mount=target=/${USER}/.cache/pip,type=cache,id=pip-${TARGETPLATFORM} \ + python3 -m pip \ --disable-pip-version-check \ - --no-cache-dir \ --quiet \ install \ setuptools wheel \ @@ -141,9 +150,9 @@ RUN python3 -m pip \ # Install Azure CLI, then verify installation ARG AZURE_CLI_VERSION ENV AZURE_CLI_VERSION=${AZURE_CLI_VERSION} -RUN python3 -m pip \ +RUN --mount=target=/${USER}/.cache/pip,type=cache,id=pip-${TARGETPLATFORM} \ + python3 -m pip \ --disable-pip-version-check \ - --no-cache-dir \ --quiet \ install \ azure-cli==${AZURE_CLI_VERSION} \ diff --git a/src/docker/Dockerfile-focal b/src/docker/Dockerfile-focal index 1f69d802..d2d513b2 100644 --- a/src/docker/Dockerfile-focal +++ b/src/docker/Dockerfile-focal @@ -18,7 +18,7 @@ ENV PYTHONDONTWRITEBYTECODE=1 # - zsh, for inter-operability RUN rm -f /etc/apt/apt.conf.d/docker-clean \ && echo 'Binary::apt::APT::Keep-Downloaded-Packages "true";' > /etc/apt/apt.conf.d/keep-cache -RUN --mount=target=/var/lib/apt/lists,type=cache,sharing=locked --mount=target=/var/cache,type=cache,sharing=locked \ +RUN --mount=target=/var/lib/apt/lists,type=cache,id=apt-lists-${TARGETPLATFORM},sharing=locked --mount=target=/var/cache,type=cache,id=var-cache-${TARGETPLATFORM},sharing=locked \ apt-get update -q \ && apt-get install -y -q --no-install-recommends \ build-essential \ @@ -67,10 +67,15 @@ RUN go version # Install RootlessKit, then verify installation ARG ROOTLESSKIT_VERSION ENV ROOTLESSKIT_VERSION=${ROOTLESSKIT_VERSION} -RUN git clone --depth 1 --branch v${ROOTLESSKIT_VERSION} https://github.com/rootless-containers/rootlesskit.git rootlesskit \ - && make --directory rootlesskit \ - && make --directory rootlesskit install \ +RUN --mount=target=/rootlesskit-${ROOTLESSKIT_VERSION},type=cache,id=rootlesskit-${ROOTLESSKIT_VERSION}-${TARGETPLATFORM},sharing=locked \ + git clone --depth 1 --branch v${ROOTLESSKIT_VERSION} https://github.com/rootless-containers/rootlesskit.git rootlesskit \ + # Ugly but that's work + && cp -r rootlesskit/* rootlesskit-${ROOTLESSKIT_VERSION} \ && rm -rf rootlesskit \ + && cd rootlesskit-${ROOTLESSKIT_VERSION} \ + && make \ + && make install \ + && cd .. \ && rootlesskit --version \ && rootlessctl --version @@ -79,7 +84,7 @@ FROM base AS python # Build Python 3.12 from source, then verify installation ARG PYTHON_VERSION ENV PYTHON_VERSION=${PYTHON_VERSION} -RUN --mount=target=/var/lib/apt/lists,type=cache,sharing=locked --mount=target=/var/cache,type=cache,sharing=locked \ +RUN --mount=target=/var/lib/apt/lists,type=cache,id=apt-lists-${TARGETPLATFORM},sharing=locked --mount=target=/var/cache,type=cache,id=var-cache-${TARGETPLATFORM},sharing=locked --mount=target=/Python-${PYTHON_VERSION},type=cache,id=python-${PYTHON_VERSION}-${TARGETPLATFORM},sharing=locked \ apt-get update -q \ && apt-get install -y -q --no-install-recommends \ g++ \ @@ -106,14 +111,18 @@ RUN --mount=target=/var/lib/apt/lists,type=cache,sharing=locked --mount=target=/ && tar -xzf python.tgz \ && rm python.tgz \ && cd Python-${PYTHON_VERSION} \ + && gnu_arch="$(dpkg-architecture --query DEB_BUILD_GNU_TYPE)" \ && ./configure \ + --build=$gnu_arch \ --enable-optimizations \ --with-ensurepip=install \ --with-lto \ - && make -j$(nproc) \ + && make profile-removal \ + && extra_cflags="$(dpkg-buildflags --get CFLAGS)" \ + && ldflags="$(dpkg-buildflags --get LDFLAGS)" \ + && make -j $(nproc) "EXTRA_CFLAGS=${extra_cflags:-}" "LDFLAGS=${ldflags:-}" \ && make install \ && cd .. \ - && rm -rf Python-${PYTHON_VERSION} \ && python3 --version \ && python3 -m pip --version \ && find / -depth -type d -name __pycache__ -exec rm -rf {} \; 2> /dev/null @@ -129,9 +138,9 @@ RUN ln -s /usr/local/bin/python3.12 /usr/local/bin/python3 \ && python3 -m pip --version # Install Python build tools -RUN python3 -m pip \ +RUN --mount=target=/${USER}/.cache/pip,type=cache,id=pip-${TARGETPLATFORM} \ + python3 -m pip \ --disable-pip-version-check \ - --no-cache-dir \ --quiet \ install \ setuptools wheel \ @@ -140,9 +149,9 @@ RUN python3 -m pip \ # Install Azure CLI, then verify installation ARG AZURE_CLI_VERSION ENV AZURE_CLI_VERSION=${AZURE_CLI_VERSION} -RUN python3 -m pip \ +RUN --mount=target=/${USER}/.cache/pip,type=cache,id=pip-${TARGETPLATFORM} \ + python3 -m pip \ --disable-pip-version-check \ - --no-cache-dir \ --quiet \ install \ azure-cli==${AZURE_CLI_VERSION} \ diff --git a/src/docker/Dockerfile-jammy b/src/docker/Dockerfile-jammy index 952ba94d..4c80b359 100644 --- a/src/docker/Dockerfile-jammy +++ b/src/docker/Dockerfile-jammy @@ -18,7 +18,7 @@ ENV PYTHONDONTWRITEBYTECODE=1 # - zsh, for inter-operability RUN rm -f /etc/apt/apt.conf.d/docker-clean \ && echo 'Binary::apt::APT::Keep-Downloaded-Packages "true";' > /etc/apt/apt.conf.d/keep-cache -RUN --mount=target=/var/lib/apt/lists,type=cache,sharing=locked --mount=target=/var/cache,type=cache,sharing=locked \ +RUN --mount=target=/var/lib/apt/lists,type=cache,id=apt-lists-${TARGETPLATFORM},sharing=locked --mount=target=/var/cache,type=cache,id=var-cache-${TARGETPLATFORM},sharing=locked \ apt-get update -q \ && apt-get install -y -q --no-install-recommends \ build-essential \ @@ -67,10 +67,15 @@ RUN go version # Install RootlessKit, then verify installation ARG ROOTLESSKIT_VERSION ENV ROOTLESSKIT_VERSION=${ROOTLESSKIT_VERSION} -RUN git clone --depth 1 --branch v${ROOTLESSKIT_VERSION} https://github.com/rootless-containers/rootlesskit.git rootlesskit \ - && make --directory rootlesskit \ - && make --directory rootlesskit install \ +RUN --mount=target=/rootlesskit-${ROOTLESSKIT_VERSION},type=cache,id=rootlesskit-${ROOTLESSKIT_VERSION}-${TARGETPLATFORM},sharing=locked \ + git clone --depth 1 --branch v${ROOTLESSKIT_VERSION} https://github.com/rootless-containers/rootlesskit.git rootlesskit \ + # Ugly but that's work + && cp -r rootlesskit/* rootlesskit-${ROOTLESSKIT_VERSION} \ && rm -rf rootlesskit \ + && cd rootlesskit-${ROOTLESSKIT_VERSION} \ + && make \ + && make install \ + && cd .. \ && rootlesskit --version \ && rootlessctl --version @@ -79,7 +84,7 @@ FROM base AS python # Build Python 3.12 from source, then verify installation ARG PYTHON_VERSION ENV PYTHON_VERSION=${PYTHON_VERSION} -RUN --mount=target=/var/lib/apt/lists,type=cache,sharing=locked --mount=target=/var/cache,type=cache,sharing=locked \ +RUN --mount=target=/var/lib/apt/lists,type=cache,id=apt-lists-${TARGETPLATFORM},sharing=locked --mount=target=/var/cache,type=cache,id=var-cache-${TARGETPLATFORM},sharing=locked --mount=target=/Python-${PYTHON_VERSION},type=cache,id=python-${PYTHON_VERSION}-${TARGETPLATFORM},sharing=locked \ apt-get update -q \ && apt-get install -y -q --no-install-recommends \ g++ \ @@ -106,14 +111,18 @@ RUN --mount=target=/var/lib/apt/lists,type=cache,sharing=locked --mount=target=/ && tar -xzf python.tgz \ && rm python.tgz \ && cd Python-${PYTHON_VERSION} \ + && gnu_arch="$(dpkg-architecture --query DEB_BUILD_GNU_TYPE)" \ && ./configure \ + --build=$gnu_arch \ --enable-optimizations \ --with-ensurepip=install \ --with-lto \ - && make -j$(nproc) \ + && make profile-removal \ + && extra_cflags="$(dpkg-buildflags --get CFLAGS)" \ + && ldflags="$(dpkg-buildflags --get LDFLAGS)" \ + && make -j $(nproc) "EXTRA_CFLAGS=${extra_cflags:-}" "LDFLAGS=${ldflags:-}" \ && make install \ && cd .. \ - && rm -rf Python-${PYTHON_VERSION} \ && python3 --version \ && python3 -m pip --version \ && find / -depth -type d -name __pycache__ -exec rm -rf {} \; 2> /dev/null @@ -129,9 +138,9 @@ RUN ln -s /usr/local/bin/python3.12 /usr/local/bin/python3 \ && python3 -m pip --version # Install Python build tools -RUN python3 -m pip \ +RUN --mount=target=/${USER}/.cache/pip,type=cache,id=pip-${TARGETPLATFORM} \ + python3 -m pip \ --disable-pip-version-check \ - --no-cache-dir \ --quiet \ install \ setuptools wheel \ @@ -140,9 +149,9 @@ RUN python3 -m pip \ # Install Azure CLI, then verify installation ARG AZURE_CLI_VERSION ENV AZURE_CLI_VERSION=${AZURE_CLI_VERSION} -RUN python3 -m pip \ +RUN --mount=target=/${USER}/.cache/pip,type=cache,id=pip-${TARGETPLATFORM} \ + python3 -m pip \ --disable-pip-version-check \ - --no-cache-dir \ --quiet \ install \ azure-cli==${AZURE_CLI_VERSION} \ diff --git a/src/docker/Dockerfile-noble b/src/docker/Dockerfile-noble index 694e5d10..45e7c2c0 100644 --- a/src/docker/Dockerfile-noble +++ b/src/docker/Dockerfile-noble @@ -21,7 +21,7 @@ ENV PIP_BREAK_SYSTEM_PACKAGES=1 # - zsh, for inter-operability RUN rm -f /etc/apt/apt.conf.d/docker-clean \ && echo 'Binary::apt::APT::Keep-Downloaded-Packages "true";' > /etc/apt/apt.conf.d/keep-cache -RUN --mount=target=/var/lib/apt/lists,type=cache,sharing=locked --mount=target=/var/cache,type=cache,sharing=locked \ +RUN --mount=target=/var/lib/apt/lists,type=cache,id=apt-lists-${TARGETPLATFORM},sharing=locked --mount=target=/var/cache,type=cache,id=var-cache-${TARGETPLATFORM},sharing=locked \ apt-get update -q \ && apt-get install -y -q --no-install-recommends \ build-essential \ @@ -71,10 +71,15 @@ RUN go version # Install RootlessKit, then verify installation ARG ROOTLESSKIT_VERSION ENV ROOTLESSKIT_VERSION=${ROOTLESSKIT_VERSION} -RUN git clone --depth 1 --branch v${ROOTLESSKIT_VERSION} https://github.com/rootless-containers/rootlesskit.git rootlesskit \ - && make --directory rootlesskit \ - && make --directory rootlesskit install \ +RUN --mount=target=/rootlesskit-${ROOTLESSKIT_VERSION},type=cache,id=rootlesskit-${ROOTLESSKIT_VERSION}-${TARGETPLATFORM},sharing=locked \ + git clone --depth 1 --branch v${ROOTLESSKIT_VERSION} https://github.com/rootless-containers/rootlesskit.git rootlesskit \ + # Ugly but that's work + && cp -r rootlesskit/* rootlesskit-${ROOTLESSKIT_VERSION} \ && rm -rf rootlesskit \ + && cd rootlesskit-${ROOTLESSKIT_VERSION} \ + && make \ + && make install \ + && cd .. \ && rootlesskit --version \ && rootlessctl --version @@ -83,7 +88,7 @@ FROM base AS python # Build Python 3.12 from source, then verify installation ARG PYTHON_VERSION ENV PYTHON_VERSION=${PYTHON_VERSION} -RUN --mount=target=/var/lib/apt/lists,type=cache,sharing=locked --mount=target=/var/cache,type=cache,sharing=locked \ +RUN --mount=target=/var/lib/apt/lists,type=cache,id=apt-lists-${TARGETPLATFORM},sharing=locked --mount=target=/var/cache,type=cache,id=var-cache-${TARGETPLATFORM},sharing=locked --mount=target=/Python-${PYTHON_VERSION},type=cache,id=python-${PYTHON_VERSION}-${TARGETPLATFORM},sharing=locked \ apt-get update -q \ && apt-get install -y -q --no-install-recommends \ g++ \ @@ -109,14 +114,18 @@ RUN --mount=target=/var/lib/apt/lists,type=cache,sharing=locked --mount=target=/ && tar -xzf python.tgz \ && rm python.tgz \ && cd Python-${PYTHON_VERSION} \ + && gnu_arch="$(dpkg-architecture --query DEB_BUILD_GNU_TYPE)" \ && ./configure \ + --build=$gnu_arch \ --enable-optimizations \ --with-ensurepip=install \ --with-lto \ - && make -j$(nproc) \ + && make profile-removal \ + && extra_cflags="$(dpkg-buildflags --get CFLAGS)" \ + && ldflags="$(dpkg-buildflags --get LDFLAGS)" \ + && make -j $(nproc) "EXTRA_CFLAGS=${extra_cflags:-}" "LDFLAGS=${ldflags:-}" \ && make install \ && cd .. \ - && rm -rf Python-${PYTHON_VERSION} \ && python3 --version \ && python3 -m pip --version \ && find / -depth -type d -name __pycache__ -exec rm -rf {} \; 2> /dev/null @@ -132,9 +141,9 @@ RUN ln -s /usr/local/bin/python3.12 /usr/local/bin/python3 \ && python3 -m pip --version # Install Python build tools -RUN python3 -m pip \ +RUN --mount=target=/${USER}/.cache/pip,type=cache,id=pip-${TARGETPLATFORM} \ + python3 -m pip \ --disable-pip-version-check \ - --no-cache-dir \ --quiet \ install \ setuptools wheel \ @@ -143,9 +152,9 @@ RUN python3 -m pip \ # Install Azure CLI, then verify installation ARG AZURE_CLI_VERSION ENV AZURE_CLI_VERSION=${AZURE_CLI_VERSION} -RUN python3 -m pip \ +RUN --mount=target=/${USER}/.cache/pip,type=cache,id=pip-${TARGETPLATFORM} \ + python3 -m pip \ --disable-pip-version-check \ - --no-cache-dir \ --quiet \ install \ azure-cli==${AZURE_CLI_VERSION} \ diff --git a/src/docker/Dockerfile-ubi8 b/src/docker/Dockerfile-ubi8 index d7241650..ce7b6d08 100644 --- a/src/docker/Dockerfile-ubi8 +++ b/src/docker/Dockerfile-ubi8 @@ -14,7 +14,7 @@ ENV PYTHONDONTWRITEBYTECODE=1 # - fuse-overlayfs, iptables, shadow-utils, for BuildKit # - gzip, make, tar, unzip, wget, zip, zstd for developer ease-of-life # - zsh, for inter-operability -RUN --mount=target=/var/cache/yum,type=cache,sharing=locked \ +RUN --mount=target=/var/cache/yum,type=cache,id=yum-${TARGETPLATFORM},sharing=locked \ microdnf install -y --nodocs --setopt=install_weak_deps=0 \ aspnetcore-runtime-8.0 \ ca-certificates \ @@ -64,10 +64,15 @@ RUN go version # Install RootlessKit, then verify installation ARG ROOTLESSKIT_VERSION ENV ROOTLESSKIT_VERSION=${ROOTLESSKIT_VERSION} -RUN git clone --depth 1 --branch v${ROOTLESSKIT_VERSION} https://github.com/rootless-containers/rootlesskit.git rootlesskit \ - && make --directory rootlesskit \ - && make --directory rootlesskit install \ +RUN --mount=target=/rootlesskit-${ROOTLESSKIT_VERSION},type=cache,id=rootlesskit-${ROOTLESSKIT_VERSION}-${TARGETPLATFORM},sharing=locked \ + git clone --depth 1 --branch v${ROOTLESSKIT_VERSION} https://github.com/rootless-containers/rootlesskit.git rootlesskit \ + # Ugly but that's work + && cp -r rootlesskit/* rootlesskit-${ROOTLESSKIT_VERSION} \ && rm -rf rootlesskit \ + && cd rootlesskit-${ROOTLESSKIT_VERSION} \ + && make \ + && make install \ + && cd .. \ && rootlesskit --version \ && rootlessctl --version @@ -76,7 +81,7 @@ FROM base AS python # Build Python 3.12 from source, then verify installation ARG PYTHON_VERSION ENV PYTHON_VERSION=${PYTHON_VERSION} -RUN --mount=target=/var/cache/yum,type=cache,sharing=locked \ +RUN --mount=target=/var/cache/yum,type=cache,id=yum-${TARGETPLATFORM},sharing=locked --mount=target=/Python-${PYTHON_VERSION},type=cache,id=python-${PYTHON_VERSION}-${TARGETPLATFORM},sharing=locked \ microdnf install -y --nodocs --setopt=install_weak_deps=0 \ bzip2 \ bzip2-devel \ @@ -89,6 +94,7 @@ RUN --mount=target=/var/cache/yum,type=cache,sharing=locked \ libstdc++-devel \ libuuid-devel \ mpdecimal \ + redhat-rpm-config \ sqlite \ sqlite-devel \ sqlite-libs \ @@ -98,14 +104,18 @@ RUN --mount=target=/var/cache/yum,type=cache,sharing=locked \ && tar -xzf python.tgz \ && rm python.tgz \ && cd Python-${PYTHON_VERSION} \ + && gnu_arch="$(rpm --eval '%{_target_cpu}')-redhat-linux" \ && ./configure \ + --build=$gnu_arch \ --enable-optimizations \ --with-ensurepip=install \ --with-lto \ - && make -j$(nproc) \ + && make profile-removal \ + && extra_cflags="$(rpm --eval '%{optflags}')" \ + && ldflags="$(rpm --eval '%{__global_ldflags}')" \ + && make -j $(nproc) "EXTRA_CFLAGS=${extra_cflags:-}" "LDFLAGS=${ldflags:-}" \ && make install \ && cd .. \ - && rm -rf Python-${PYTHON_VERSION} \ && python3 --version \ && python3 -m pip --version \ && find / -depth -type d -name __pycache__ -exec rm -rf {} \; 2> /dev/null @@ -121,9 +131,9 @@ RUN ln -s /usr/local/bin/python3.12 /usr/local/bin/python3 \ && python3 -m pip --version # Install Python build tools -RUN python3 -m pip \ +RUN --mount=target=/${USER}/.cache/pip,type=cache,id=pip-${TARGETPLATFORM} \ + python3 -m pip \ --disable-pip-version-check \ - --no-cache-dir \ --quiet \ install \ setuptools wheel \ @@ -132,9 +142,9 @@ RUN python3 -m pip \ # Install Azure CLI, then verify installation ARG AZURE_CLI_VERSION ENV AZURE_CLI_VERSION=${AZURE_CLI_VERSION} -RUN python3 -m pip \ +RUN --mount=target=/${USER}/.cache/pip,type=cache,id=pip-${TARGETPLATFORM} \ + python3 -m pip \ --disable-pip-version-check \ - --no-cache-dir \ --quiet \ install \ azure-cli==${AZURE_CLI_VERSION} \ diff --git a/src/docker/Dockerfile-ubi9 b/src/docker/Dockerfile-ubi9 index 26bf5467..a41a55a3 100644 --- a/src/docker/Dockerfile-ubi9 +++ b/src/docker/Dockerfile-ubi9 @@ -14,7 +14,7 @@ ENV PYTHONDONTWRITEBYTECODE=1 # - fuse-overlayfs, iptables, shadow-utils, for BuildKit # - gzip, make, tar, unzip, wget, zip, zstd for developer ease-of-life # - zsh, for inter-operability -RUN --mount=target=/var/cache/yum,type=cache,sharing=locked \ +RUN --mount=target=/var/cache/yum,type=cache,id=yum-${TARGETPLATFORM},sharing=locked \ microdnf install -y --nodocs --setopt=install_weak_deps=0 \ aspnetcore-runtime-8.0 \ ca-certificates \ @@ -63,10 +63,15 @@ RUN go version # Install RootlessKit, then verify installation ARG ROOTLESSKIT_VERSION ENV ROOTLESSKIT_VERSION=${ROOTLESSKIT_VERSION} -RUN git clone --depth 1 --branch v${ROOTLESSKIT_VERSION} https://github.com/rootless-containers/rootlesskit.git rootlesskit \ - && make --directory rootlesskit \ - && make --directory rootlesskit install \ +RUN --mount=target=/rootlesskit-${ROOTLESSKIT_VERSION},type=cache,id=rootlesskit-${ROOTLESSKIT_VERSION}-${TARGETPLATFORM},sharing=locked \ + git clone --depth 1 --branch v${ROOTLESSKIT_VERSION} https://github.com/rootless-containers/rootlesskit.git rootlesskit \ + # Ugly but that's work + && cp -r rootlesskit/* rootlesskit-${ROOTLESSKIT_VERSION} \ && rm -rf rootlesskit \ + && cd rootlesskit-${ROOTLESSKIT_VERSION} \ + && make \ + && make install \ + && cd .. \ && rootlesskit --version \ && rootlessctl --version @@ -75,7 +80,7 @@ FROM base AS python # Build Python 3.12 from source, then verify installation ARG PYTHON_VERSION ENV PYTHON_VERSION=${PYTHON_VERSION} -RUN --mount=target=/var/cache/yum,type=cache,sharing=locked \ +RUN --mount=target=/var/cache/yum,type=cache,id=yum-${TARGETPLATFORM},sharing=locked --mount=target=/Python-${PYTHON_VERSION},type=cache,id=python-${PYTHON_VERSION}-${TARGETPLATFORM},sharing=locked \ microdnf install -y --nodocs --setopt=install_weak_deps=0 \ bzip2 \ bzip2-devel \ @@ -88,6 +93,7 @@ RUN --mount=target=/var/cache/yum,type=cache,sharing=locked \ libstdc++-devel \ libuuid-devel \ mpdecimal \ + redhat-rpm-config \ sqlite \ sqlite-devel \ sqlite-libs \ @@ -97,14 +103,18 @@ RUN --mount=target=/var/cache/yum,type=cache,sharing=locked \ && tar -xzf python.tgz \ && rm python.tgz \ && cd Python-${PYTHON_VERSION} \ + && gnu_arch="$(rpm --eval '%{_target_cpu}')-redhat-linux" \ && ./configure \ + --build=$gnu_arch \ --enable-optimizations \ --with-ensurepip=install \ --with-lto \ - && make -j$(nproc) \ + && make profile-removal \ + && extra_cflags="$(rpm --eval '%{optflags}')" \ + && ldflags="$(rpm --eval '%{__global_ldflags}')" \ + && make -j $(nproc) "EXTRA_CFLAGS=${extra_cflags:-}" "LDFLAGS=${ldflags:-}" \ && make install \ && cd .. \ - && rm -rf Python-${PYTHON_VERSION} \ && python3 --version \ && python3 -m pip --version \ && find / -depth -type d -name __pycache__ -exec rm -rf {} \; 2> /dev/null @@ -120,9 +130,9 @@ RUN ln -s /usr/local/bin/python3.12 /usr/local/bin/python3 \ && python3 -m pip --version # Install Python build tools -RUN python3 -m pip \ +RUN --mount=target=/${USER}/.cache/pip,type=cache,id=pip-${TARGETPLATFORM} \ + python3 -m pip \ --disable-pip-version-check \ - --no-cache-dir \ --quiet \ install \ setuptools wheel \ @@ -131,9 +141,9 @@ RUN python3 -m pip \ # Install Azure CLI, then verify installation ARG AZURE_CLI_VERSION ENV AZURE_CLI_VERSION=${AZURE_CLI_VERSION} -RUN python3 -m pip \ +RUN --mount=target=/${USER}/.cache/pip,type=cache,id=pip-${TARGETPLATFORM} \ + python3 -m pip \ --disable-pip-version-check \ - --no-cache-dir \ --quiet \ install \ azure-cli==${AZURE_CLI_VERSION} \