-
Notifications
You must be signed in to change notification settings - Fork 108
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(e2e): only build zetanode once (#3121)
* refactor(e2e): only build zetanode once add docker login back to reusable flow * debug * fix * remove apt install from orchestrator build and just use zetanode as base * use zetanode:latest * fix fork build * ghcr_username * cannot use env in env * try packages write permission * fall back to slow build on forks * have to run matrix always() * more always() * only check failed status (fork will be skipped)
- Loading branch information
Showing
5 changed files
with
124 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,7 +28,83 @@ concurrency: | |
cancel-in-progress: true | ||
|
||
jobs: | ||
# this cannot run on forks as forks cannot push packages in pull request context | ||
# forked pull request will fall back to slow build | ||
build-zetanode: | ||
runs-on: ubuntu-22.04 | ||
if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == 'zeta-chain/node' | ||
env: | ||
DOCKER_IMAGE: ghcr.io/${{ github.repository_owner }}/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 Docker Hub registry | ||
uses: docker/login-action@v3 | ||
with: | ||
username: ${{ secrets.DOCKER_HUB_USERNAME }} | ||
password: ${{ secrets.DOCKER_HUB_READ_ONLY }} | ||
|
||
- 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/[email protected] | ||
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 | ||
if: always() | ||
runs-on: ubuntu-22.04 | ||
env: | ||
GH_TOKEN: ${{ github.token }} | ||
|
@@ -119,7 +195,10 @@ jobs: | |
} | ||
e2e: | ||
needs: matrix-conditionals | ||
needs: | ||
- build-zetanode | ||
- matrix-conditionals | ||
if: always() | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
|
@@ -170,12 +249,14 @@ jobs: | |
runs-on: ${{ matrix.runs-on}} | ||
run: ${{ matrix.run }} | ||
timeout-minutes: "${{ matrix.timeout-minutes || 25 }}" | ||
zetanode-image: ${{ needs.build-zetanode.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 +305,10 @@ jobs: | |
- run: | | ||
result="${{ needs.build-zetanode.result }}" | ||
if [[ $result == "failed" ]]; then | ||
exit 1 | ||
fi | ||
result="${{ needs.e2e.result }}" | ||
if [[ $result == "success" || $result == "skipped" ]]; then | ||
exit 0 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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/[email protected] | ||
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: | | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters