From b64dadc4979a3d9f1de6399a02f28fe247b36157 Mon Sep 17 00:00:00 2001 From: Erik Johnston Date: Wed, 17 Feb 2021 15:09:45 +0000 Subject: Add a Dockerfile that allows using a base image with a cargo cache --- docker/Dockerfile | 6 +++++- docker/Dockerfile-cargo-cache | 21 +++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 docker/Dockerfile-cargo-cache diff --git a/docker/Dockerfile b/docker/Dockerfile index d619ee08ed..ce404662ce 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -12,11 +12,13 @@ # ARG PYTHON_VERSION=3.8 +ARG BASE_IMAGE=docker.io/python:${PYTHON_VERSION}-slim +ARG CARGO_NET_OFFLINE=false ### ### Stage 0: builder ### -FROM docker.io/python:${PYTHON_VERSION}-slim as builder +FROM ${BASE_IMAGE} as builder # install the OS build deps RUN apt-get update && apt-get install -y \ @@ -32,6 +34,8 @@ RUN apt-get update && apt-get install -y \ zlib1g-dev \ && rm -rf /var/lib/apt/lists/* +ENV CARGO_NET_OFFLINE=${CARGO_NET_OFFLINE} + # Build dependencies that are not available as wheels, to speed up rebuilds RUN pip install --prefix="/install" --no-warn-script-location \ cryptography \ diff --git a/docker/Dockerfile-cargo-cache b/docker/Dockerfile-cargo-cache new file mode 100644 index 0000000000..b4673fff53 --- /dev/null +++ b/docker/Dockerfile-cargo-cache @@ -0,0 +1,21 @@ +# A docker file that caches the cargo index for the cryptography deps. This is +# mainly useful for multi-arch builds where fetching the index from the internet +# fails for 32bit archs built on 64 bit platforms. + +ARG PYTHON_VERSION=3.8 + +FROM --platform=$BUILDPLATFORM docker.io/python:${PYTHON_VERSION}-slim as builder + +RUN apt-get update && apt-get install -y \ + rustc \ + && rm -rf /var/lib/apt/lists/* + +RUN pip download --no-binary cryptography --no-deps cryptography + +RUN tar -xf cryptography*.tar.gz --wildcards cryptography*/src/rust/ + +RUN cd cryptography*/src/rust && cargo fetch + +FROM docker.io/python:${PYTHON_VERSION}-slim + +COPY --from=builder /root/.cargo /root/.cargo -- cgit 1.4.1