do even more in parallel

and also use the proper rust cache path
This commit is contained in:
Bryan Stitt 2023-07-05 12:44:38 -07:00
parent 1f1f2433e0
commit 8ea9a0a5cb

View File

@ -27,82 +27,88 @@ RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
; ;
# install rustup # install rustup
RUN --mount=type=cache,target=/usr/local/cargo/git \ RUN --mount=type=cache,target=/root/.cargo/git \
--mount=type=cache,target=/usr/local/cargo/registry \ --mount=type=cache,target=/root/.cargo/registry \
set -eux; \ set -eux; \
\ \
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --default-toolchain none --profile=minimal curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --default-toolchain none --profile=minimal
# run a cargo command which install our desired version of rust # 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 ./ COPY rust-toolchain.toml ./
RUN --mount=type=cache,target=/usr/local/cargo/git \ RUN --mount=type=cache,target=/root/.cargo/git \
--mount=type=cache,target=/usr/local/cargo/registry \ --mount=type=cache,target=/root/.cargo/registry \
set -eux; \ set -eux; \
\ \
cargo check || [ "$?" -eq 101 ] cargo check || [ "$?" -eq 101 ]
# nextest runs tests in parallel # nextest runs tests in parallel (done its in own FROM so that it can run in parallel)
# We only pay the installation cost once, it will be cached from the second build onwards FROM rust as rust_nextest
RUN --mount=type=cache,target=/usr/local/cargo/git \ RUN --mount=type=cache,target=/root/.cargo/git \
--mount=type=cache,target=/usr/local/cargo/registry \ --mount=type=cache,target=/root/.cargo/registry \
set -eux; \ set -eux; \
\ \
cargo install --locked cargo-nextest cargo install --locked cargo-nextest
# foundry/anvil are needed to run tests # foundry/anvil are needed to run tests (done its in own FROM so that it can run in parallel)
RUN --mount=type=cache,target=/usr/local/cargo/git \ FROM rust as rust_foundry
--mount=type=cache,target=/usr/local/cargo/registry \ RUN --mount=type=cache,target=/root/.cargo/git \
--mount=type=cache,target=/root/.cargo/registry \
set -eux; \ set -eux; \
\ \
curl -L https://foundry.paradigm.xyz | bash && foundryup curl -L https://foundry.paradigm.xyz | bash && foundryup
FROM rust as rust_with_env
# changing our features doesn't change any of the steps above # changing our features doesn't change any of the steps above
ENV WEB3_PROXY_FEATURES "rdkafka-src" ENV WEB3_PROXY_FEATURES "rdkafka-src"
# check downloads all the packages # fetch deps
RUN --mount=type=bind,target=.,rw \ RUN --mount=type=bind,target=.,rw \
--mount=type=cache,target=/usr/local/cargo/git \ --mount=type=cache,target=/root/.cargo/git \
--mount=type=cache,target=/usr/local/cargo/registry \ --mount=type=cache,target=/root/.cargo/registry \
--mount=type=cache,target=/app/target \ --mount=type=cache,target=/app/target \
set -eux; \ set -eux; \
\ \
cargo fetch --locked cargo --locked fetch
FROM rust as build_tests # build tests (done its in own FROM so that it can run in parallel)
FROM rust_with_env as build_tests
COPY --from=rust_foundry /root/.foundry /root/
COPY --from=rust_nextest /root/.cargo/bin/cargo-nextest* /root/.cargo/bin/
# test the application with cargo-nextest # test the application with cargo-nextest
RUN --mount=type=bind,target=.,rw \ RUN --mount=type=bind,target=.,rw \
--mount=type=cache,target=/usr/local/cargo/git \ --mount=type=cache,target=/root/.cargo/git \
--mount=type=cache,target=/usr/local/cargo/registry \ --mount=type=cache,target=/root/.cargo/registry \
--mount=type=cache,target=/app/target,id=build_tests_target \ --mount=type=cache,target=/app/target \
set -eux; \ set -eux; \
\ \
RUST_LOG=web3_proxy=trace,info cargo --frozen nextest run --features "$WEB3_PROXY_FEATURES" --no-default-features --offline; \ RUST_LOG=web3_proxy=trace,info cargo --locked nextest run --features "$WEB3_PROXY_FEATURES" --no-default-features; \
touch /test_success touch /test_success
FROM rust as build_app FROM rust_with_env as build_app
# build the release application # # build the release application
# using a "release" profile (which install does by default) is **very** important # # 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) # # TODO: use the "faster_release" profile which builds with `codegen-units = 1` (but compile is SLOW)
RUN --mount=type=bind,target=.,rw \ RUN --mount=type=bind,target=.,rw \
--mount=type=cache,target=/usr/local/cargo/git \ --mount=type=cache,target=/root/.cargo/git \
--mount=type=cache,target=/usr/local/cargo/registry \ --mount=type=cache,target=/root/.cargo/registry \
--mount=type=cache,target=/app/target \ --mount=type=cache,target=/app/target \
set -eux; \ set -eux; \
\ \
cargo install \ cargo install \
--features "$WEB3_PROXY_FEATURES" \ --features "$WEB3_PROXY_FEATURES" \
--frozen \
--no-default-features \ --no-default-features \
--offline \
--path ./web3_proxy \ --path ./web3_proxy \
--root /usr/local \ --root /usr/local \
; \ ; \
/usr/local/bin/web3_proxy_cli --help | grep 'Usage: web3_proxy_cli' /usr/local/bin/web3_proxy_cli --help | grep 'Usage: web3_proxy_cli'
# copy this file so that docker actually creates the build_tests container # # copy this file so that docker actually creates the build_tests container
# without this, the runtime container doesn't need build_tests and so docker build skips it # # without this, the runtime container doesn't need build_tests and so docker build skips it
COPY --from=build_tests /test_success / COPY --from=build_tests /test_success /
# #