Skip to content

Commit

Permalink
perf: Add shared build cache
Browse files Browse the repository at this point in the history
  • Loading branch information
clemlesne committed Oct 25, 2024
1 parent 0e487f1 commit 897778a
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 35 deletions.
11 changes: 6 additions & 5 deletions src/docker/Dockerfile-bookworm
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down Expand Up @@ -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++ \
Expand Down Expand Up @@ -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
Expand All @@ -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 \
Expand All @@ -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 \
Expand Down
11 changes: 6 additions & 5 deletions src/docker/Dockerfile-bullseye
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down Expand Up @@ -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++ \
Expand Down Expand Up @@ -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
Expand All @@ -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 \
Expand All @@ -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 \
Expand Down
11 changes: 6 additions & 5 deletions src/docker/Dockerfile-focal
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down Expand Up @@ -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++ \
Expand Down Expand Up @@ -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
Expand All @@ -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 \
Expand All @@ -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 \
Expand Down
11 changes: 6 additions & 5 deletions src/docker/Dockerfile-jammy
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down Expand Up @@ -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++ \
Expand Down Expand Up @@ -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
Expand All @@ -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 \
Expand All @@ -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 \
Expand Down
11 changes: 6 additions & 5 deletions src/docker/Dockerfile-noble
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down Expand Up @@ -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++ \
Expand Down Expand Up @@ -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
Expand All @@ -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 \
Expand All @@ -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 \
Expand Down
11 changes: 6 additions & 5 deletions src/docker/Dockerfile-ubi8
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down Expand Up @@ -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 \
Expand Down Expand Up @@ -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
Expand All @@ -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 \
Expand All @@ -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 \
Expand Down
11 changes: 6 additions & 5 deletions src/docker/Dockerfile-ubi9
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down Expand Up @@ -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 \
Expand Down Expand Up @@ -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
Expand All @@ -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 \
Expand All @@ -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 \
Expand Down

0 comments on commit 897778a

Please sign in to comment.