diff --git a/Dockerfile b/Dockerfile index ea6692ed..50206f21 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,8 +1,8 @@ FROM debian:bullseye-slim as rust WORKDIR /app -# Incrementally compiled crates cannot be cached with sccache -ENV CARGO_INCREMENTAL false +# sccache cannot cache incrementals, but we use --mount=type=cache and import caches so it should be helpful +ENV CARGO_INCREMENTAL true ENV CARGO_UNSTABLE_SPARSE_REGISTRY true ENV CARGO_TERM_COLOR always SHELL [ "/bin/bash", "-c" ] @@ -56,88 +56,27 @@ RUN --mount=type=cache,target=/root/.cargo/git \ bash /tmp/install-binstall.sh; \ rm -rf /tmp/* -# sccache -ARG AWS_ACCESS_KEY_ID -ARG AWS_PROFILE -ARG AWS_SECRET_ACCESS_KEY -ARG AWS_SESSION_TOKEN -ARG BUILD_JOBS=4 -ARG SCCACHE_BUCKET -ARG SCCACHE_REGION -ARG SCCACHE_S3_KEY_PREFIX -ARG SCCACHE_S3_USE_SSL -RUN --mount=type=cache,target=/root/.cargo/git \ - --mount=type=cache,target=/root/.cargo/registry \ - --mount=type=cache,target=/root/.cache/sccache \ - set -eux -o pipefail; \ - \ - cargo binstall -y sccache; \ - sccache -s - -ENV RUSTC_WRAPPER "/root/.cargo/bin/sccache" - # nextest runs tests in parallel (done its in own FROM so that it can run in parallel) # TODO: i'd like to use binaries for these, but i had trouble with arm and binstall FROM rust as rust_nextest -# keep the ARGs from the previous step -# we probably won't need sccache since we install with binstall. But compiling is a fallback for binstall, so it is possible. -ARG AWS_ACCESS_KEY_ID -ARG AWS_PROFILE -ARG AWS_SECRET_ACCESS_KEY -ARG AWS_SESSION_TOKEN -ARG BUILD_JOBS -ARG SCCACHE_BUCKET -ARG SCCACHE_REGION -ARG SCCACHE_S3_KEY_PREFIX -ARG SCCACHE_S3_USE_SSL - RUN --mount=type=cache,target=/root/.cargo/git \ --mount=type=cache,target=/root/.cargo/registry \ - --mount=type=cache,target=/root/.cache/sccache \ set -eux -o pipefail; \ \ - sccache -s; \ - cargo binstall -y cargo-nextest; \ - sccache -s + 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 -# keep the ARGs from the previous step -# we probably won't need sccache since foundry tries to use binaries. But compiling is a fallback, so it is possible. -ARG AWS_ACCESS_KEY_ID -ARG AWS_PROFILE -ARG AWS_SECRET_ACCESS_KEY -ARG AWS_SESSION_TOKEN -ARG BUILD_JOBS -ARG SCCACHE_BUCKET -ARG SCCACHE_REGION -ARG SCCACHE_S3_KEY_PREFIX -ARG SCCACHE_S3_USE_SSL - RUN --mount=type=cache,target=/root/.cargo/git \ --mount=type=cache,target=/root/.cargo/registry \ - --mount=type=cache,target=/root/.cache/sccache \ set -eux -o pipefail; \ \ - sccache -s; \ - curl -L https://foundry.paradigm.xyz | bash && foundryup; \ - sccache -s + curl -L https://foundry.paradigm.xyz | bash && foundryup FROM rust as rust_with_env -# keep the ARGs from the previous step -ARG AWS_ACCESS_KEY_ID -ARG AWS_PROFILE -ARG AWS_SECRET_ACCESS_KEY -ARG AWS_SESSION_TOKEN -ARG BUILD_JOBS -ARG SCCACHE_BUCKET -ARG SCCACHE_REGION -ARG SCCACHE_S3_KEY_PREFIX -ARG SCCACHE_S3_USE_SSL - # changing our features doesn't change any of the steps above ENV WEB3_PROXY_FEATURES "deadlock_detection,rdkafka-src" @@ -147,7 +86,6 @@ COPY . . # fetch deps RUN --mount=type=cache,target=/root/.cargo/git \ --mount=type=cache,target=/root/.cargo/registry \ - --mount=type=cache,target=/root/.cache/sccache \ --mount=type=cache,target=/app/target \ set -eux -o pipefail; \ \ @@ -160,65 +98,34 @@ FROM rust_with_env as build_tests COPY --from=rust_foundry /root/.foundry/bin/anvil /root/.foundry/bin/ COPY --from=rust_nextest /root/.cargo/bin/cargo-nextest* /root/.cargo/bin/ -# keep the ARGs from the previous step -# sccache should be a huge savings here -ARG AWS_ACCESS_KEY_ID -ARG AWS_PROFILE -ARG AWS_SECRET_ACCESS_KEY -ARG AWS_SESSION_TOKEN -ARG BUILD_JOBS -ARG SCCACHE_BUCKET -ARG SCCACHE_REGION -ARG SCCACHE_S3_KEY_PREFIX -ARG SCCACHE_S3_USE_SSL - # test the application with cargo-nextest RUN --mount=type=cache,target=/root/.cargo/git \ --mount=type=cache,target=/root/.cargo/registry \ - --mount=type=cache,target=/root/.cache/sccache \ --mount=type=cache,target=/app/target \ set -eux -o pipefail; \ \ - sccache -s; \ [ -e "$(pwd)/payment-contracts/src/contracts/mod.rs" ] || touch "$(pwd)/payment-contracts/build.rs"; \ RUST_LOG=web3_proxy=trace,info \ cargo \ --frozen \ --offline \ nextest run \ - --build-jobs "$BUILD_JOBS" \ --features "$WEB3_PROXY_FEATURES" --no-default-features \ ; \ - sccache -s; \ touch /test_success FROM rust_with_env as build_app -# keep the ARGs from the previous step -# sccache should be a huge savings here -ARG AWS_ACCESS_KEY_ID -ARG AWS_PROFILE -ARG AWS_SECRET_ACCESS_KEY -ARG AWS_SESSION_TOKEN -ARG BUILD_JOBS -ARG SCCACHE_BUCKET -ARG SCCACHE_REGION -ARG SCCACHE_S3_KEY_PREFIX -ARG SCCACHE_S3_USE_SSL - # # 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 --mount=type=cache,target=/root/.cargo/git \ --mount=type=cache,target=/root/.cargo/registry \ - --mount=type=cache,target=/root/.cache/sccache \ --mount=type=cache,target=/app/target \ set -eux -o pipefail; \ \ - sccache -s; \ [ -e "$(pwd)/payment-contracts/src/contracts/mod.rs" ] || touch "$(pwd)/payment-contracts/build.rs"; \ cargo install \ - --jobs "$BUILD_JOBS" \ --features "$WEB3_PROXY_FEATURES" \ --frozen \ --no-default-features \ @@ -226,7 +133,6 @@ RUN --mount=type=cache,target=/root/.cargo/git \ --path ./web3_proxy \ --root /usr/local \ ; \ - sccache -s; \ /usr/local/bin/web3_proxy_cli --help | grep 'Usage: web3_proxy_cli' # copy this file so that docker actually creates the build_tests container