From 674729eebde04f4dedb1dde12665d4b30b00f0ed Mon Sep 17 00:00:00 2001 From: Dustin Brickwood Date: Wed, 18 Dec 2024 18:43:43 -0600 Subject: [PATCH] feat: add docker build for amd64 / arm64, runs e2e tests against docker node, publishes to ghcr --- .github/workflows/build-push-docker.yml | 14 ++++- .github/workflows/e2e-docker.yml | 84 +++++++++++++++++++++++++ 2 files changed, 97 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/e2e-docker.yml diff --git a/.github/workflows/build-push-docker.yml b/.github/workflows/build-push-docker.yml index 928b7a2b..0224599e 100644 --- a/.github/workflows/build-push-docker.yml +++ b/.github/workflows/build-push-docker.yml @@ -14,6 +14,9 @@ jobs: build-push-image: name: Build and push Docker image runs-on: [matterlabs-ci-runner] + strategy: + matrix: + platform: [linux/amd64, linux/arm64] steps: - uses: actions/checkout@v4 @@ -39,6 +42,13 @@ jobs: - name: Login to GAR run: | gcloud auth configure-docker us-docker.pkg.dev -q + + - name: Login to GHCR + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} - name: Set up QEMU uses: docker/setup-qemu-action@v3 @@ -46,16 +56,18 @@ jobs: - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 - # For now, we're only pushing to the internal registry - name: Build and push Docker image id: docker_build uses: docker/build-push-action@v6 with: context: . push: ${{ github.event_name == 'push' && (github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/')) }} + platforms: ${{ matrix.platform }} tags: | us-docker.pkg.dev/matterlabs-infra/matterlabs-docker/era-test-node:${{ steps.docker_tag.outputs.tag }} us-docker.pkg.dev/matterlabs-infra/matterlabs-docker/era-test-node:latest + ghcr.io/${{ github.repository_owner }}/anvil-zksync:${{ steps.docker_tag.outputs.tag }} + ghcr.io/${{ github.repository_owner }}/anvil-zksync:latest - name: Print image digest to summary run: | diff --git a/.github/workflows/e2e-docker.yml b/.github/workflows/e2e-docker.yml new file mode 100644 index 00000000..cc038bb3 --- /dev/null +++ b/.github/workflows/e2e-docker.yml @@ -0,0 +1,84 @@ +name: Running e2e tests against Docker image + +on: + workflow_call: + push: + branches: + - main + pull_request: + +jobs: + test-docker-image: + name: Test Docker Image + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Build Docker image locally + id: docker_build + uses: docker/build-push-action@v6 + with: + context: . + push: false + load: true + tags: test-anvil-zksync:latest + + - name: Start Docker container + run: | + echo "Starting Docker container with test-anvil-zksync image..." + docker run --rm -d -p 8011:8011 -v $PWD/logs:/logs --name test_anvil_zksync test-anvil-zksync:latest + + - name: Wait for the node to be ready + run: | + echo "Waiting for the node to be ready..." + MAX_RETRIES=10 + COUNTER=0 + URL="http://localhost:8011" + DATA='{"jsonrpc": "2.0", "id": "1", "method": "eth_chainId", "params": []}' + + while [ $COUNTER -lt $MAX_RETRIES ]; do + RESPONSE=$(curl -s -o /dev/null -w "%{http_code}" -X POST -H "content-type: application/json" -d "$DATA" $URL || true) + if [ "$RESPONSE" -eq 200 ]; then + echo "Node is running!" + break + else + echo "Node not ready, retrying in 1 second..." + COUNTER=$((COUNTER + 1)) + sleep 1 + fi + done + + if [ $COUNTER -eq $MAX_RETRIES ]; then + echo "Failed to contact node after $MAX_RETRIES attempts. Are you sure the node is running at $URL ?" + docker stop test_anvil_zksync + exit 1 + fi + + - name: Install dependencies for e2e tests + working-directory: ./e2e-tests + run: | + echo "Installing e2e test dependencies..." + yarn install --frozen-lockfile + + - name: Compile contracts and run e2e tests + working-directory: ./e2e-tests + run: | + echo "Compiling contracts and running e2e tests..." + yarn hardhat compile + export ANVIL_LOG_PATH=/logs/anvil-zksync.log + yarn test + + - name: Stop Docker container + if: always() + run: | + echo "Stopping Docker container..." + docker stop test_anvil_zksync + + - name: Print test result summary + run: | + echo "Tests completed successfully!"