diff --git a/.github/workflows/interop-test.yml b/.github/workflows/interop-test.yml index e3485f25dc6..c2f07a47453 100644 --- a/.github/workflows/interop-test.yml +++ b/.github/workflows/interop-test.yml @@ -18,9 +18,23 @@ jobs: flavour: [chromium, native] steps: - uses: actions/checkout@v4 + - uses: docker/setup-buildx-action@v3 + + # This uses the same S3 cache as all test-plans images. Because we use `cargo-chef` in the Dockerfile, we have a layer available with all dependencies built. - name: Build ${{ matrix.flavour }} image - run: docker buildx build --load -t ${{ matrix.flavour }}-rust-libp2p-head . -f interop-tests/Dockerfile.${{ matrix.flavour }} + run: | + docker buildx build \ + --load \ + --cache-to type=s3,mode=max,bucket=libp2p-by-tf-aws-bootstrap,region=us-east-1,prefix=buildCache,name=${{ matrix.flavour }}-rust-libp2p-head \ + --cache-from type=s3,mode=max,bucket=libp2p-by-tf-aws-bootstrap,region=us-east-1,prefix=buildCache,name=${{ matrix.flavour }}-rust-libp2p-head \ + -t ${{ matrix.flavour }}-rust-libp2p-head \ + . \ + -f interop-tests/Dockerfile.${{ matrix.flavour }} + env: + AWS_ACCESS_KEY_ID: ${{ vars.TEST_PLANS_BUILD_CACHE_KEY_ID }} + AWS_SECRET_ACCESS_KEY: ${{ secrets.TEST_PLANS_BUILD_CACHE_KEY }} + - name: Run ${{ matrix.flavour }} tests uses: libp2p/test-plans/.github/actions/run-interop-ping-test@master with: diff --git a/interop-tests/Dockerfile.chromium b/interop-tests/Dockerfile.chromium index 33e0a0bf637..ab720c4d317 100644 --- a/interop-tests/Dockerfile.chromium +++ b/interop-tests/Dockerfile.chromium @@ -1,28 +1,26 @@ -FROM rust:1.67.0 as builder - -# Run with access to the target cache to speed up builds -WORKDIR /workspace -ADD . . - +# syntax=docker/dockerfile:1.5-labs +FROM rust:1.67.0 as chef RUN rustup target add wasm32-unknown-unknown - RUN wget -q -O- https://github.com/rustwasm/wasm-pack/releases/download/v0.12.1/wasm-pack-v0.12.1-x86_64-unknown-linux-musl.tar.gz | tar -zx -C /usr/local/bin --strip-components 1 --wildcards "wasm-pack-*/wasm-pack" RUN wget -q -O- https://github.com/WebAssembly/binaryen/releases/download/version_115/binaryen-version_115-x86_64-linux.tar.gz | tar -zx -C /usr/local/bin --strip-components 2 --wildcards "binaryen-version_*/bin/wasm-opt" - -RUN --mount=type=cache,target=./target \ - --mount=type=cache,target=/usr/local/cargo/registry \ - wasm-pack build --target web interop-tests - -RUN --mount=type=cache,target=./target \ - --mount=type=cache,target=/usr/local/cargo/registry \ - cargo build --release --package interop-tests --bin wasm_ping - -RUN --mount=type=cache,target=./target \ - mv ./target/release/wasm_ping /usr/local/bin/testplan +RUN wget -q -O- https://github.com/LukeMathWalker/cargo-chef/releases/download/v0.1.62/cargo-chef-x86_64-unknown-linux-gnu.tar.gz | tar -zx -C /usr/local/bin +WORKDIR /app + +FROM chef AS planner +COPY . . +RUN cargo chef prepare --recipe-path recipe.json + +FROM chef AS builder +COPY --from=planner /app/recipe.json recipe.json +# Build dependencies - this is the caching Docker layer! +RUN cargo chef cook --release --package interop-tests --target wasm32-unknown-unknown --recipe-path recipe.json +RUN cargo chef cook --release --package interop-tests --bin wasm_ping --recipe-path recipe.json +# Build application +COPY . . +RUN wasm-pack build --target web interop-tests +RUN cargo build --release --package interop-tests --bin wasm_ping FROM selenium/standalone-chrome:115.0 -COPY --from=builder /usr/local/bin/testplan /usr/local/bin/testplan - +COPY --from=builder /app/target/release/wasm_ping /usr/local/bin/testplan ENV RUST_BACKTRACE=1 - ENTRYPOINT ["testplan"] diff --git a/interop-tests/Dockerfile.native b/interop-tests/Dockerfile.native index f78b85e424c..df5eb9a1240 100644 --- a/interop-tests/Dockerfile.native +++ b/interop-tests/Dockerfile.native @@ -1,17 +1,21 @@ # syntax=docker/dockerfile:1.5-labs -FROM rust:1.67.0 as builder +FROM rust:1.67.0 as chef +RUN wget -q -O- https://github.com/LukeMathWalker/cargo-chef/releases/download/v0.1.62/cargo-chef-x86_64-unknown-linux-gnu.tar.gz | tar -zx -C /usr/local/bin +WORKDIR /app -# Run with access to the target cache to speed up builds -WORKDIR /workspace -ADD . . -RUN --mount=type=cache,target=./target \ - --mount=type=cache,target=/usr/local/cargo/registry \ - cargo build --release --package interop-tests --bin native_ping +FROM chef AS planner +COPY . . +RUN cargo chef prepare --recipe-path recipe.json -RUN --mount=type=cache,target=./target \ - mv ./target/release/native_ping /usr/local/bin/testplan +FROM chef AS builder +COPY --from=planner /app/recipe.json recipe.json +# Build dependencies - this is the caching Docker layer! +RUN cargo chef cook --release --package interop-tests --bin native_ping --recipe-path recipe.json +# Build application +COPY . . +RUN cargo build --release --package interop-tests --bin native_ping FROM gcr.io/distroless/cc -COPY --from=builder /usr/local/bin/testplan /usr/local/bin/testplan +COPY --from=builder /app/target/release/native_ping /usr/local/bin/testplan ENV RUST_BACKTRACE=1 ENTRYPOINT ["testplan"]