From 897778a9192bf353c497a71ee1008b662846c242 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 --- src/docker/Dockerfile-bookworm | 11 ++++++----- src/docker/Dockerfile-bullseye | 11 ++++++----- src/docker/Dockerfile-focal | 11 ++++++----- src/docker/Dockerfile-jammy | 11 ++++++----- src/docker/Dockerfile-noble | 11 ++++++----- src/docker/Dockerfile-ubi8 | 11 ++++++----- src/docker/Dockerfile-ubi9 | 11 ++++++----- 7 files changed, 42 insertions(+), 35 deletions(-) diff --git a/src/docker/Dockerfile-bookworm b/src/docker/Dockerfile-bookworm index 14bee7b7..8bb3ad4b 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 \ @@ -83,7 +83,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++ \ @@ -116,7 +116,6 @@ RUN --mount=target=/var/lib/apt/lists,type=cache,sharing=locked --mount=target=/ && make -j$(nproc) \ && 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,7 +131,8 @@ 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 \ @@ -143,7 +143,8 @@ 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 \ diff --git a/src/docker/Dockerfile-bullseye b/src/docker/Dockerfile-bullseye index a84b0e36..474c3a93 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 \ @@ -80,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/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++ \ @@ -114,7 +114,6 @@ RUN --mount=target=/var/lib/apt/lists,type=cache,sharing=locked --mount=target=/ && make -j$(nproc) \ && 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,7 +129,8 @@ 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 \ @@ -141,7 +141,8 @@ 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 \ diff --git a/src/docker/Dockerfile-focal b/src/docker/Dockerfile-focal index 1f69d802..e9584263 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 \ @@ -79,7 +79,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++ \ @@ -113,7 +113,6 @@ RUN --mount=target=/var/lib/apt/lists,type=cache,sharing=locked --mount=target=/ && make -j$(nproc) \ && 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,7 +128,8 @@ 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 \ @@ -140,7 +140,8 @@ 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 \ diff --git a/src/docker/Dockerfile-jammy b/src/docker/Dockerfile-jammy index 952ba94d..c2b6c5ed 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 \ @@ -79,7 +79,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++ \ @@ -113,7 +113,6 @@ RUN --mount=target=/var/lib/apt/lists,type=cache,sharing=locked --mount=target=/ && make -j$(nproc) \ && 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,7 +128,8 @@ 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 \ @@ -140,7 +140,8 @@ 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 \ diff --git a/src/docker/Dockerfile-noble b/src/docker/Dockerfile-noble index 694e5d10..177d2917 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 \ @@ -83,7 +83,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++ \ @@ -116,7 +116,6 @@ RUN --mount=target=/var/lib/apt/lists,type=cache,sharing=locked --mount=target=/ && make -j$(nproc) \ && 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,7 +131,8 @@ 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 \ @@ -143,7 +143,8 @@ 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 \ diff --git a/src/docker/Dockerfile-ubi8 b/src/docker/Dockerfile-ubi8 index d7241650..03618368 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 \ @@ -76,7 +76,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 \ @@ -105,7 +105,6 @@ RUN --mount=target=/var/cache/yum,type=cache,sharing=locked \ && make -j$(nproc) \ && 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,7 +120,8 @@ 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 \ @@ -132,7 +132,8 @@ 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 \ diff --git a/src/docker/Dockerfile-ubi9 b/src/docker/Dockerfile-ubi9 index 26bf5467..3838ee6d 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 \ @@ -75,7 +75,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 \ @@ -104,7 +104,6 @@ RUN --mount=target=/var/cache/yum,type=cache,sharing=locked \ && make -j$(nproc) \ && 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,7 +119,8 @@ 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 \ @@ -131,7 +131,8 @@ 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 \