From b381de25bb16381758223132329629705695da93 Mon Sep 17 00:00:00 2001 From: Alex Gartner Date: Wed, 6 Nov 2024 11:22:03 -0800 Subject: [PATCH] refactor(e2e): only build zetanode once add docker login back to reusable flow --- .github/workflows/e2e.yml | 76 +++++++++++++++++++++++++++++- .github/workflows/reusable-e2e.yml | 55 +++------------------ Makefile | 39 ++++++++++----- 3 files changed, 108 insertions(+), 62 deletions(-) diff --git a/.github/workflows/e2e.yml b/.github/workflows/e2e.yml index 773775e816..94bf0c53dc 100644 --- a/.github/workflows/e2e.yml +++ b/.github/workflows/e2e.yml @@ -28,7 +28,73 @@ concurrency: cancel-in-progress: true jobs: + build-zetanode: + runs-on: ubuntu-22.04 + env: + DOCKER_IMAGE: ghcr.io/${{ github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name || github.repository }}/zetanode + DOCKER_TAG: ${{ github.ref == 'refs/heads/develop' && 'develop' || github.sha }} + outputs: + image: ${{ fromJson(steps.build.outputs.metadata)['image.name'] }} + steps: + - uses: actions/checkout@v4 + + # configure docker to use the containerd snapshotter + # so that we can use the buildkit cache + - uses: depot/use-containerd-snapshotter-action@v1 + + - name: Login to github docker registry + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.repository_owner }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Restore go cache + uses: actions/cache@v4 + id: restore-go-cache + with: + path: | + go-cache + key: cache-${{ hashFiles('go.sum') }} + + - name: Inject go cache into docker + uses: reproducible-containers/buildkit-cache-dance@v3.1.2 + with: + cache-map: | + { + "go-cache": "/root/.cache/go-build" + } + skip-extraction: ${{ steps.restore-go-cache.outputs.cache-hit || github.event_name != 'push' }} + + # this ensures that the version is consistent between cache build and make build + - name: Set version for cache + run: | + NODE_VERSION=$(./version.sh) + echo "NODE_VERSION=$NODE_VERSION" >> $GITHUB_ENV + NODE_COMMIT=$(git log -1 --format='%H') + echo "NODE_COMMIT=$NODE_COMMIT" >> $GITHUB_ENV + + # build zetanode with cache options + - name: Build zetanode for cache + id: build + uses: docker/build-push-action@v6 + env: + CACHE_FROM_CONFIG: "type=registry,ref=ghcr.io/${{ github.repository }}:buildcache" + CACHE_TO_CONFIG: "type=registry,ref=ghcr.io/${{ github.repository }}:buildcache,mode=max" + with: + context: . + file: ./Dockerfile-localnet + push: true + tags: ${{ env.DOCKER_IMAGE }}:${{ env.DOCKER_TAG }} + cache-from: ${{ env.CACHE_FROM_CONFIG }} + cache-to: ${{ github.event_name == 'push' && env.CACHE_TO_CONFIG || '' }} + target: latest-runtime + build-args: | + NODE_VERSION=${{ env.NODE_VERSION }} + NODE_COMMIT=${{ env.NODE_COMMIT }} + matrix-conditionals: + needs: build-zetanode runs-on: ubuntu-22.04 env: GH_TOKEN: ${{ github.token }} @@ -119,7 +185,9 @@ jobs: } e2e: - needs: matrix-conditionals + needs: + - build-zetanode + - matrix-conditionals strategy: fail-fast: false matrix: @@ -170,12 +238,14 @@ jobs: runs-on: ${{ matrix.runs-on}} run: ${{ matrix.run }} timeout-minutes: "${{ matrix.timeout-minutes || 25 }}" + zetanode-image: ${{ needs.zetanode-build.outputs.image }} enable-monitoring: ${{ needs.matrix-conditionals.outputs.ENABLE_MONITORING == 'true' }} secrets: inherit # this allows you to set a required status check e2e-ok: runs-on: ubuntu-22.04 needs: + - build-zetanode - matrix-conditionals - e2e if: always() @@ -224,6 +294,10 @@ jobs: - run: | + result="${{ needs.build-zetanode.result }}" + if [[ $result != "success" ]]; then + exit 1 + fi result="${{ needs.e2e.result }}" if [[ $result == "success" || $result == "skipped" ]]; then exit 0 diff --git a/.github/workflows/reusable-e2e.yml b/.github/workflows/reusable-e2e.yml index 88c42466a5..a4aa35c2ec 100644 --- a/.github/workflows/reusable-e2e.yml +++ b/.github/workflows/reusable-e2e.yml @@ -19,6 +19,10 @@ on: required: true type: string default: 'ubuntu-20.04' + zetanode-image: + description: 'docker image to use for zetanode' + required: true + type: string enable-monitoring: description: 'Enable the monitoring stack for this run' type: boolean @@ -31,12 +35,10 @@ jobs: timeout-minutes: ${{ inputs.timeout-minutes }} strategy: fail-fast: false + env: + ZETANODE_IMAGE: ${{ inputs.zetanode-image }} steps: - uses: actions/checkout@v4 - - # configure docker to use the containerd snapshotter - # so that we can use the buildkit cache - - uses: depot/use-containerd-snapshotter-action@v1 - name: Login to Docker Hub registry uses: docker/login-action@v3 @@ -51,50 +53,7 @@ jobs: registry: ghcr.io username: ${{ github.repository_owner }} password: ${{ secrets.GITHUB_TOKEN }} - - - name: Restore go cache - uses: actions/cache@v4 - id: restore-go-cache - with: - path: | - go-cache - key: cache-${{ hashFiles('go.sum') }} - - - name: Inject go cache into docker - uses: reproducible-containers/buildkit-cache-dance@v3.1.2 - with: - cache-map: | - { - "go-cache": "/root/.cache/go-build" - } - skip-extraction: ${{ steps.restore-go-cache.outputs.cache-hit || github.event_name != 'push' }} - - # this ensures that the version is consistent between cache build and make build - - name: Set version for cache - run: | - NODE_VERSION=$(./version.sh) - echo "NODE_VERSION=$NODE_VERSION" >> $GITHUB_ENV - NODE_COMMIT=$(git log -1 --format='%H') - echo "NODE_COMMIT=$NODE_COMMIT" >> $GITHUB_ENV - - # build zetanode with cache options - - name: Build zetanode for cache - uses: docker/build-push-action@v6 - env: - CACHE_FROM_CONFIG: "type=registry,ref=ghcr.io/${{ github.repository }}:buildcache" - CACHE_TO_CONFIG: "type=registry,ref=ghcr.io/${{ github.repository }}:buildcache,mode=max" - with: - context: . - file: ./Dockerfile-localnet - push: false - tags: zetanode:latest - cache-from: ${{ env.CACHE_FROM_CONFIG }} - cache-to: ${{ github.event_name == 'push' && env.CACHE_TO_CONFIG || '' }} - target: latest-runtime - build-args: | - NODE_VERSION=${{ env.NODE_VERSION }} - NODE_COMMIT=${{ env.NODE_COMMIT }} - + - name: Enable monitoring if: inputs.enable-monitoring run: | diff --git a/Makefile b/Makefile index f39e4f27ff..4ecb211f09 100644 --- a/Makefile +++ b/Makefile @@ -227,7 +227,8 @@ generate: proto-gen openapi specs typescript docs-zetacored mocks precompiles fm ############################################################################### ### Localnet ### ############################################################################### -start-localnet: zetanode start-localnet-skip-build +e2e-images: zetanode orchestrator +start-localnet: e2e-images start-localnet-skip-build start-localnet-skip-build: @echo "--> Starting localnet" @@ -242,11 +243,23 @@ stop-localnet: ### E2E tests ### ############################################################################### +ifdef ZETANODE_IMAGE +zetanode: + @echo "Pulling zetanode image" + $(DOCKER) pull $(ZETANODE_IMAGE) + $(DOCKER) tag $(ZETANODE_IMAGE) zetanode +.PHONY: zetanode +else zetanode: @echo "Building zetanode" $(DOCKER) build -t zetanode --build-arg NODE_VERSION=$(NODE_VERSION) --build-arg NODE_COMMIT=$(NODE_COMMIT) --target latest-runtime -f ./Dockerfile-localnet . - $(DOCKER) build -t orchestrator -f contrib/localnet/orchestrator/Dockerfile.fastbuild . .PHONY: zetanode +endif + +orchestrator: + @echo "Building e2e orchestrator" + $(DOCKER) build -t orchestrator -f contrib/localnet/orchestrator/Dockerfile.fastbuild . +.PHONY: orchestrator install-zetae2e: go.sum @echo "--> Installing zetae2e" @@ -257,47 +270,47 @@ solana: @echo "Building solana docker image" $(DOCKER) build -t solana-local -f contrib/localnet/solana/Dockerfile contrib/localnet/solana/ -start-e2e-test: zetanode +start-e2e-test: e2e-images @echo "--> Starting e2e test" cd contrib/localnet/ && $(DOCKER_COMPOSE) up -d -start-e2e-admin-test: zetanode +start-e2e-admin-test: e2e-images @echo "--> Starting e2e admin test" export E2E_ARGS="--skip-regular --test-admin" && \ cd contrib/localnet/ && $(DOCKER_COMPOSE) --profile eth2 up -d -start-e2e-performance-test: zetanode +start-e2e-performance-test: e2e-images @echo "--> Starting e2e performance test" export E2E_ARGS="--test-performance" && \ cd contrib/localnet/ && $(DOCKER_COMPOSE) --profile stress up -d -start-e2e-import-mainnet-test: zetanode +start-e2e-import-mainnet-test: e2e-images @echo "--> Starting e2e import-data test" export ZETACORED_IMPORT_GENESIS_DATA=true && \ export ZETACORED_START_PERIOD=15m && \ cd contrib/localnet/ && ./scripts/import-data.sh mainnet && $(DOCKER_COMPOSE) up -d -start-stress-test: zetanode +start-stress-test: e2e-images @echo "--> Starting stress test" cd contrib/localnet/ && $(DOCKER_COMPOSE) --profile stress up -d -start-tss-migration-test: zetanode +start-tss-migration-test: e2e-images @echo "--> Starting tss migration test" export LOCALNET_MODE=tss-migrate && \ export E2E_ARGS="--test-tss-migration" && \ cd contrib/localnet/ && $(DOCKER_COMPOSE) up -d -start-solana-test: zetanode solana +start-solana-test: e2e-images solana @echo "--> Starting solana test" export E2E_ARGS="--skip-regular --test-solana" && \ cd contrib/localnet/ && $(DOCKER_COMPOSE) --profile solana up -d -start-ton-test: zetanode +start-ton-test: e2e-images @echo "--> Starting TON test" export E2E_ARGS="--skip-regular --test-ton" && \ cd contrib/localnet/ && $(DOCKER_COMPOSE) --profile ton up -d -start-v2-test: zetanode +start-v2-test: e2e-images @echo "--> Starting e2e smart contracts v2 test" export E2E_ARGS="--skip-regular --test-v2" && \ cd contrib/localnet/ && $(DOCKER_COMPOSE) up -d @@ -309,7 +322,7 @@ start-v2-test: zetanode # build from source only if requested # NODE_VERSION and NODE_COMMIT must be set as old-runtime depends on lastest-runtime ifdef UPGRADE_TEST_FROM_SOURCE -zetanode-upgrade: zetanode +zetanode-upgrade: e2e-images @echo "Building zetanode-upgrade from source" $(DOCKER) build -t zetanode:old -f Dockerfile-localnet --target old-runtime-source \ --build-arg OLD_VERSION='release/v21' \ @@ -318,7 +331,7 @@ zetanode-upgrade: zetanode . .PHONY: zetanode-upgrade else -zetanode-upgrade: zetanode +zetanode-upgrade: e2e-images @echo "Building zetanode-upgrade from binaries" $(DOCKER) build -t zetanode:old -f Dockerfile-localnet --target old-runtime \ --build-arg OLD_VERSION='https://github.com/zeta-chain/node/releases/download/v21.0.0' \