From 667c43cca15d9ff2a38a24fe6105151c26398661 Mon Sep 17 00:00:00 2001 From: Bryan Stitt Date: Wed, 6 Sep 2023 13:25:21 -0700 Subject: [PATCH] Revert "drop mount type cache" This reverts commit dcfc51c2f5e78ec1768a36d0a4472948ebf73bb5. --- Dockerfile | 45 ++++++++++++++++++++++++++++++++++----------- 1 file changed, 34 insertions(+), 11 deletions(-) diff --git a/Dockerfile b/Dockerfile index 45305398..16de3070 100644 --- a/Dockerfile +++ b/Dockerfile @@ -31,17 +31,25 @@ RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \ ; # install rustup -RUN set -eux -o pipefail; \ +RUN --mount=type=cache,target=/root/.cargo/git \ + --mount=type=cache,target=/root/.cargo/registry \ + set -eux -o pipefail; \ \ curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --default-toolchain none --profile=minimal # run a cargo command to install our desired version of rust # it is expected to exit code 101 since no Cargo.toml exists COPY rust-toolchain.toml ./ -RUN cargo check || [ "$?" -eq 101 ] +RUN --mount=type=cache,target=/root/.cargo/git \ + --mount=type=cache,target=/root/.cargo/registry \ + set -eux -o pipefail; \ + \ + cargo check || [ "$?" -eq 101 ] # cargo binstall -RUN set -eux -o pipefail; \ +RUN --mount=type=cache,target=/root/.cargo/git \ + --mount=type=cache,target=/root/.cargo/registry \ + set -eux -o pipefail; \ \ curl -L --proto '=https' --tlsv1.2 -sSf https://raw.githubusercontent.com/cargo-bins/cargo-binstall/main/install-from-binstall-release.sh >/tmp/install-binstall.sh; \ bash /tmp/install-binstall.sh; \ @@ -51,12 +59,18 @@ RUN set -eux -o pipefail; \ # TODO: i'd like to use binaries for these, but i had trouble with arm and binstall FROM rust as rust_nextest -RUN cargo binstall -y cargo-nextest +RUN --mount=type=cache,target=/root/.cargo/git \ + --mount=type=cache,target=/root/.cargo/registry \ + set -eux -o pipefail; \ + \ + cargo binstall -y cargo-nextest # foundry/anvil are needed to run tests (done its in own FROM so that it can run in parallel) FROM rust as rust_foundry -RUN set -eux -o pipefail; \ +RUN --mount=type=cache,target=/root/.cargo/git \ + --mount=type=cache,target=/root/.cargo/registry \ + set -eux -o pipefail; \ \ curl -L https://foundry.paradigm.xyz | bash && foundryup @@ -65,11 +79,12 @@ FROM rust as rust_with_env # changing our features doesn't change any of the steps above ENV WEB3_PROXY_FEATURES "rdkafka-src" -# copy the app -COPY . . - # fill the package caches -RUN set -eux -o pipefail; \ +RUN --mount=type=bind,source=.,target=/app,rw \ + --mount=type=cache,target=/root/.cargo/git \ + --mount=type=cache,target=/root/.cargo/registry \ + --mount=type=cache,target=/app/target \ + set -eux -o pipefail; \ \ [ -e "$(pwd)/payment-contracts/src/contracts/mod.rs" ] || touch "$(pwd)/payment-contracts/build.rs"; \ cargo \ @@ -83,7 +98,11 @@ COPY --from=rust_foundry /root/.foundry/bin/anvil /root/.foundry/bin/ COPY --from=rust_nextest /root/.cargo/bin/cargo-nextest* /root/.cargo/bin/ # test the application with cargo-nextest -RUN set -eux -o pipefail; \ +RUN --mount=type=bind,source=.,target=/app,rw \ + --mount=type=cache,target=/root/.cargo/git \ + --mount=type=cache,target=/root/.cargo/registry \ + --mount=type=cache,target=/app/target_test \ + set -eux -o pipefail; \ \ export CARGO_TARGET_DIR=target_test; \ [ -e "$(pwd)/payment-contracts/src/contracts/mod.rs" ] || touch "$(pwd)/payment-contracts/build.rs"; \ @@ -102,7 +121,11 @@ FROM rust_with_env as build_app # build the release application # using a "release" profile (which install does by default) is **very** important # TODO: use the "faster_release" profile which builds with `codegen-units = 1` (but compile is SLOW) -RUN set -eux -o pipefail; \ +RUN --mount=type=bind,source=.,target=/app,rw \ + --mount=type=cache,target=/root/.cargo/git \ + --mount=type=cache,target=/root/.cargo/registry \ + --mount=type=cache,target=/app/target \ + set -eux -o pipefail; \ \ [ -e "$(pwd)/payment-contracts/src/contracts/mod.rs" ] || touch "$(pwd)/payment-contracts/build.rs"; \ cargo install \