From c94aabf8f63471fb9e87ef5f10b72ae8d905064e Mon Sep 17 00:00:00 2001 From: Thomas Eizinger Date: Thu, 26 Jan 2023 14:46:51 +1100 Subject: [PATCH] feat(inter-op): make `Dockerfile` generic over test binary (#3382) We make the binary that should be copied into the container configurable via a build time `ARG`. This will allow us to reuse the same `Dockerfile` once we write more tests. Additionally, this allows us to remove some of the directory switching and creation code. In order to not send the entire repository over to the docker daemon as a build context, we introduce a `.dockerignore` file that only allows select binary to be sent over. The downside of this is that we need to extend this ignore file every time we add a new test. This shouldn't happen very often though and is easily discovered because the building of the docker container will fail. --- .dockerignore | 10 ++++++++++ .github/workflows/interop-test.yml | 7 ++----- interop-tests/Dockerfile | 3 ++- 3 files changed, 14 insertions(+), 6 deletions(-) create mode 100644 .dockerignore diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 00000000..865b3f50 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,10 @@ +# This Docker ignore file aims to optimise the build process of the interop tests. +# The Dockerfile in ./interop-tests/Dockerfile copies a locally built binary into the container and +# thus does not need anything else to be present in the working directory. +* + +# CI will build and copy over the release binary. +!target/release/ping + +# Locally, we might want to build it as `debug` binary to accelerate the build process. +!target/debug/ping diff --git a/.github/workflows/interop-test.yml b/.github/workflows/interop-test.yml index bd438019..9351198b 100644 --- a/.github/workflows/interop-test.yml +++ b/.github/workflows/interop-test.yml @@ -24,13 +24,10 @@ jobs: - name: Install Protoc run: sudo apt-get install protobuf-compiler - name: Build image - working-directory: ./interop-tests run: | cargo build --release -p interop-tests - mkdir -p target/release/ - cp ../target/release/ping target/release - docker build -t rust-libp2p-head . - docker image save -o ping-image.tar rust-libp2p-head + docker build -t rust-libp2p-head --build-arg=TEST_BINARY=target/release/ping . -f ./interop-tests/Dockerfile + docker image save -o ./interop-tests/ping-image.tar rust-libp2p-head - name: Upload ping versions info uses: actions/upload-artifact@v3 with: diff --git a/interop-tests/Dockerfile b/interop-tests/Dockerfile index 0f28bb61..7197b378 100644 --- a/interop-tests/Dockerfile +++ b/interop-tests/Dockerfile @@ -1,4 +1,5 @@ FROM ubuntu:22.04 -COPY target/release/ping /usr/local/bin/testplan +ARG TEST_BINARY +COPY $TEST_BINARY /usr/local/bin/testplan ENV RUST_BACKTRACE=1 ENTRYPOINT ["testplan"]