From 1c596af1cf77e74d79b172b06179c38cfdf78bcd Mon Sep 17 00:00:00 2001 From: Thomas Eizinger Date: Thu, 26 Jan 2023 20:35:16 +1100 Subject: [PATCH] feat: publish container images for interop-test binaries (#3383) This patch adds a workflow that automatically publishes a docker image of our `ping` interop-test binaries on every release. Releases are different from Git tags. We publish a tag for each version of each crate but only a single release for each version of the `libp2p` crate. Alternatively, this workflow can also be triggered manually: ![image](https://user-images.githubusercontent.com/5486389/214460448-d4fca593-d323-4476-956f-d180aadf8850.png) 1. Select the Git ref you want to run the workflow on. This should be the version of `libp2p` you want to publish the test binary for. For example, if you want to publish a version of the test binary for a hotfix release of a sub-crate, you would pick the respective tag of the hotfix release. 2. Choose the tag of the docker image. To resolve https://github.com/libp2p/test-plans/issues/112, I am planning to create branches off current master that hardcodes the libp2p version in the test-binary to a particular one and then trigger this workflow for the respective branch. --- .github/workflows/interop-test.yml | 2 +- .../workflows/publish-interop-test-images.yml | 53 +++++++++++++++++++ interop-tests/Dockerfile | 1 + 3 files changed, 55 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/publish-interop-test-images.yml diff --git a/.github/workflows/interop-test.yml b/.github/workflows/interop-test.yml index 9351198b..b4110059 100644 --- a/.github/workflows/interop-test.yml +++ b/.github/workflows/interop-test.yml @@ -26,7 +26,7 @@ jobs: - name: Build image run: | cargo build --release -p interop-tests - docker build -t rust-libp2p-head --build-arg=TEST_BINARY=target/release/ping . -f ./interop-tests/Dockerfile + 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 diff --git a/.github/workflows/publish-interop-test-images.yml b/.github/workflows/publish-interop-test-images.yml new file mode 100644 index 00000000..b1f94603 --- /dev/null +++ b/.github/workflows/publish-interop-test-images.yml @@ -0,0 +1,53 @@ +name: Publish interop test docker images + +on: + release: + types: [ created ] # Publishing of a containers is triggered on _releases_. Releases are a GH concept building on top of tags. + workflow_dispatch: # This workflow can also be triggered manually which is useful for testing, updates to test binaries or publishing of test binaries for older libp2p versions. + inputs: + dockerTag: + description: 'Docker image tag' + required: true + +env: + REGISTRY: ghcr.io + PING_TEST_IMAGE_NAME: ${{ github.repository }}/ping-interop-test + +jobs: + publish-interop-test-images: + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + steps: + - uses: actions/checkout@v3 + + - uses: actions-rs/toolchain@16499b5e05bf2e26879000db0c1d13f7e13fa3af # v1.0.7 + with: + profile: minimal + toolchain: stable + override: true + + - uses: Swatinem/rust-cache@359a70e43a0bb8a13953b04a90f76428b4959bb6 # v2.2.0 + with: + shared-key: interop-tests + save-if: false + + - name: Log in to the Container registry + uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Build test binaries + run: | + sudo apt-get install protobuf-compiler + cargo build --release -p interop-tests + + - name: Build and push ping interop docker image + run: | + TAG="${{ env.REGISTRY }}/${{ env.PING_TEST_IMAGE_NAME }}:${{ inputs.dockerTag || github.event.release.tag_name }}" + + docker build -t $TAG --build-arg=TEST_BINARY=target/release/ping . -f interop-tests/Dockerfile + docker push $TAG diff --git a/interop-tests/Dockerfile b/interop-tests/Dockerfile index 7197b378..41c640e1 100644 --- a/interop-tests/Dockerfile +++ b/interop-tests/Dockerfile @@ -1,5 +1,6 @@ FROM ubuntu:22.04 ARG TEST_BINARY COPY $TEST_BINARY /usr/local/bin/testplan +LABEL org.opencontainers.image.source https://github.com/libp2p/rust-libp2p ENV RUST_BACKTRACE=1 ENTRYPOINT ["testplan"]