From a68430f6c0d7f4ec75d7beca10cbf44353005945 Mon Sep 17 00:00:00 2001 From: Gustavo Valverde Date: Thu, 7 Nov 2024 12:59:33 +0000 Subject: [PATCH 1/6] feat(actions): use GitHub `environments` for infra deployments --- .github/workflows/cd-deploy-nodes-gcp.yml | 2 ++ .github/workflows/chore-delete-gcp-resources.yml | 8 ++++++++ .github/workflows/manual-zcashd-deploy.yml | 3 +++ .github/workflows/sub-build-docker-image.yml | 7 +++++++ .github/workflows/sub-ci-integration-tests-gcp.yml | 3 +++ .github/workflows/sub-deploy-integration-tests-gcp.yml | 4 ++++ .github/workflows/sub-find-cached-disks.yml | 4 ++++ 7 files changed, 31 insertions(+) diff --git a/.github/workflows/cd-deploy-nodes-gcp.yml b/.github/workflows/cd-deploy-nodes-gcp.yml index 6eb3f10e9d6..41e55620418 100644 --- a/.github/workflows/cd-deploy-nodes-gcp.yml +++ b/.github/workflows/cd-deploy-nodes-gcp.yml @@ -174,6 +174,7 @@ jobs: image_name: zebrad no_cache: ${{ inputs.no_cache || false }} rust_log: info + environment: ${{ github.event_name == 'release' && 'prod' || 'dev' }} # This step needs access to Docker Hub secrets to run successfully secrets: inherit @@ -239,6 +240,7 @@ jobs: timeout-minutes: 60 env: CACHED_DISK_NAME: ${{ needs.get-disk-name.outputs.cached_disk_name }} + environment: ${{ github.event_name == 'release' && 'prod' || 'dev' }} permissions: contents: 'read' id-token: 'write' diff --git a/.github/workflows/chore-delete-gcp-resources.yml b/.github/workflows/chore-delete-gcp-resources.yml index b4e9eda2f64..fe0c42de7c6 100644 --- a/.github/workflows/chore-delete-gcp-resources.yml +++ b/.github/workflows/chore-delete-gcp-resources.yml @@ -38,6 +38,10 @@ jobs: permissions: contents: 'read' id-token: 'write' + strategy: + matrix: + environment: [dev, prod] + environment: ${{ matrix.environment }} steps: - uses: actions/checkout@v4.2.2 with: @@ -105,6 +109,10 @@ jobs: permissions: contents: 'read' id-token: 'write' + strategy: + matrix: + environment: [dev, prod] + environment: ${{ matrix.environment }} steps: - uses: actions/checkout@v4.2.2 with: diff --git a/.github/workflows/manual-zcashd-deploy.yml b/.github/workflows/manual-zcashd-deploy.yml index 8fc5951d142..507dc0c57f2 100644 --- a/.github/workflows/manual-zcashd-deploy.yml +++ b/.github/workflows/manual-zcashd-deploy.yml @@ -10,6 +10,9 @@ name: Zcashd Manual Deploy on: workflow_dispatch: inputs: + environment: + required: false + default: dev network: default: 'Mainnet' description: 'Network to deploy: Mainnet or Testnet' diff --git a/.github/workflows/sub-build-docker-image.yml b/.github/workflows/sub-build-docker-image.yml index ac6d5bbbecc..bd7a492ec29 100644 --- a/.github/workflows/sub-build-docker-image.yml +++ b/.github/workflows/sub-build-docker-image.yml @@ -10,6 +10,11 @@ name: Build docker image on: workflow_call: inputs: + environment: + description: 'The infra environment to build the image for' + required: false + default: dev + type: string image_name: required: true type: string @@ -77,6 +82,8 @@ jobs: contents: 'read' id-token: 'write' pull-requests: write # for `docker-scout` to be able to write the comment + environment: + name: ${{ inputs.environment }} env: DOCKER_BUILD_SUMMARY: ${{ vars.DOCKER_BUILD_SUMMARY }} steps: diff --git a/.github/workflows/sub-ci-integration-tests-gcp.yml b/.github/workflows/sub-ci-integration-tests-gcp.yml index d4e4bd506d4..65d751ed7eb 100644 --- a/.github/workflows/sub-ci-integration-tests-gcp.yml +++ b/.github/workflows/sub-ci-integration-tests-gcp.yml @@ -8,6 +8,9 @@ name: Integration Tests on GCP on: workflow_call: inputs: + environment: + required: true + type: string network: default: "Mainnet" type: string diff --git a/.github/workflows/sub-deploy-integration-tests-gcp.yml b/.github/workflows/sub-deploy-integration-tests-gcp.yml index 05b2c42019f..182f22573d3 100644 --- a/.github/workflows/sub-deploy-integration-tests-gcp.yml +++ b/.github/workflows/sub-deploy-integration-tests-gcp.yml @@ -3,6 +3,10 @@ name: Deploy Tests to GCP on: workflow_call: inputs: + environment: + required: false + default: dev + type: string # Status and logging test_id: required: true diff --git a/.github/workflows/sub-find-cached-disks.yml b/.github/workflows/sub-find-cached-disks.yml index 9c2ee919d32..f32801ce91e 100644 --- a/.github/workflows/sub-find-cached-disks.yml +++ b/.github/workflows/sub-find-cached-disks.yml @@ -10,6 +10,10 @@ name: Check if cached state disks exist on: workflow_call: inputs: + environment: + required: false + default: dev + type: string network: description: 'The Zcash network used to look up the disks' required: true From ac0222790167ae34dbbac928e059e61fd18436b6 Mon Sep 17 00:00:00 2001 From: Gustavo Valverde Date: Thu, 26 Dec 2024 11:08:44 -0400 Subject: [PATCH 2/6] chore(workflows): enhance environment handling in CI/CD configurations - Added dynamic environment assignment in `cd-deploy-nodes-gcp.yml` based on event type (release or dev). - Updated `sub-build-docker-image.yml` to utilize the `inputs.environment` for environment configuration. - Introduced a strategy matrix for environment selection in `sub-deploy-integration-tests-gcp.yml`, allowing for both dev and prod environments based on the branch. - Ensured `sub-find-cached-disks.yml` uses the `inputs.environment` for consistency across workflows. --- .github/workflows/cd-deploy-nodes-gcp.yml | 1 + .github/workflows/sub-build-docker-image.yml | 3 +-- .github/workflows/sub-deploy-integration-tests-gcp.yml | 6 +++++- .github/workflows/sub-find-cached-disks.yml | 1 + 4 files changed, 8 insertions(+), 3 deletions(-) diff --git a/.github/workflows/cd-deploy-nodes-gcp.yml b/.github/workflows/cd-deploy-nodes-gcp.yml index 41e55620418..f35fe986965 100644 --- a/.github/workflows/cd-deploy-nodes-gcp.yml +++ b/.github/workflows/cd-deploy-nodes-gcp.yml @@ -155,6 +155,7 @@ jobs: # This workflow also runs on release tags, the event name check will run it on releases. if: ${{ (!startsWith(github.event_name, 'pull') || !github.event.pull_request.head.repo.fork) && !inputs.no_cached_disk }} with: + environment: ${{ github.event_name == 'release' && 'prod' || 'dev' }} network: ${{ inputs.network || vars.ZCASH_NETWORK }} disk_prefix: zebrad-cache disk_suffix: ${{ inputs.cached_disk_type || 'tip' }} diff --git a/.github/workflows/sub-build-docker-image.yml b/.github/workflows/sub-build-docker-image.yml index bd7a492ec29..7710105900f 100644 --- a/.github/workflows/sub-build-docker-image.yml +++ b/.github/workflows/sub-build-docker-image.yml @@ -75,6 +75,7 @@ jobs: name: Build images timeout-minutes: 210 runs-on: ubuntu-latest + environment: ${{ inputs.environment }} outputs: image_digest: ${{ steps.docker_build.outputs.digest }} image_name: ${{ fromJSON(steps.docker_build.outputs.metadata)['image.name'] }} @@ -82,8 +83,6 @@ jobs: contents: 'read' id-token: 'write' pull-requests: write # for `docker-scout` to be able to write the comment - environment: - name: ${{ inputs.environment }} env: DOCKER_BUILD_SUMMARY: ${{ vars.DOCKER_BUILD_SUMMARY }} steps: diff --git a/.github/workflows/sub-deploy-integration-tests-gcp.yml b/.github/workflows/sub-deploy-integration-tests-gcp.yml index 182f22573d3..7b4cbb4449b 100644 --- a/.github/workflows/sub-deploy-integration-tests-gcp.yml +++ b/.github/workflows/sub-deploy-integration-tests-gcp.yml @@ -388,6 +388,10 @@ jobs: permissions: contents: 'read' id-token: 'write' + strategy: + matrix: + environment: ${{ github.ref_name == 'main' && fromJSON('["dev", "prod"]') || fromJSON('["dev"]') }} + environment: ${{ matrix.environment }} steps: - uses: actions/checkout@v4.2.2 with: @@ -667,7 +671,7 @@ jobs: --source-disk-zone=${{ vars.GCP_ZONE }} \ --storage-location=us \ --description="Created from commit ${{ env.GITHUB_SHA_SHORT }} with height ${{ env.SYNC_HEIGHT }} and database format ${{ env.DB_VERSION_SUMMARY }}" \ - --labels="height=${{ env.SYNC_HEIGHT }},purpose=${{ inputs.disk_prefix }},commit=${{ env.GITHUB_SHA_SHORT }},state-version=${{ env.STATE_VERSION }},state-running-version=${RUNNING_DB_VERSION},initial-state-disk-version=${INITIAL_DISK_DB_VERSION},network=${NETWORK},target-height-kind=${{ inputs.disk_suffix }},update-flag=${UPDATE_SUFFIX},force-save=${{ inputs.force_save_to_disk }},updated-from-height=${ORIGINAL_HEIGHT},updated-from-disk=${ORIGINAL_DISK_NAME},test-id=${{ inputs.test_id }},app-name=${{ inputs.app_name }}" + --labels="height=${{ env.SYNC_HEIGHT }},purpose=${{ inputs.disk_prefix }},branch=${{ env.GITHUB_REF_SLUG_URL }},commit=${{ env.GITHUB_SHA_SHORT }},state-version=${{ env.STATE_VERSION }},state-running-version=${RUNNING_DB_VERSION},initial-state-disk-version=${INITIAL_DISK_DB_VERSION},network=${NETWORK},target-height-kind=${{ inputs.disk_suffix }},update-flag=${UPDATE_SUFFIX},force-save=${{ inputs.force_save_to_disk }},updated-from-height=${ORIGINAL_HEIGHT},updated-from-disk=${ORIGINAL_DISK_NAME},test-id=${{ inputs.test_id }},app-name=${{ inputs.app_name }}" else echo "Skipped cached state update because the new sync height $SYNC_HEIGHT was less than $CACHED_STATE_UPDATE_LIMIT blocks above the original height $ORIGINAL_HEIGHT of $ORIGINAL_DISK_NAME" fi diff --git a/.github/workflows/sub-find-cached-disks.yml b/.github/workflows/sub-find-cached-disks.yml index f32801ce91e..d09d101b4b7 100644 --- a/.github/workflows/sub-find-cached-disks.yml +++ b/.github/workflows/sub-find-cached-disks.yml @@ -52,6 +52,7 @@ jobs: get-cached-disks: name: Get ${{ inputs.test_id || inputs.network }} cached disk runs-on: ubuntu-latest + environment: ${{ inputs.environment }} outputs: state_version: ${{ steps.get-available-disks.outputs.state_version }} cached_disk_name: ${{ steps.get-available-disks.outputs.cached_disk_name }} From 2d187bda742ded9269c51135a64c8c734c422b13 Mon Sep 17 00:00:00 2001 From: Gustavo Valverde Date: Thu, 26 Dec 2024 15:09:37 -0400 Subject: [PATCH 3/6] fix(workflows): streamline environment input handling in CI configurations - Removed the required environment input from `sub-ci-integration-tests-gcp.yml`. - Updated comments in `sub-deploy-integration-tests-gcp.yml` to clarify the strategy for creating images in dev and prod environments based on the main branch. --- .github/workflows/sub-ci-integration-tests-gcp.yml | 3 --- .github/workflows/sub-deploy-integration-tests-gcp.yml | 2 ++ 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/.github/workflows/sub-ci-integration-tests-gcp.yml b/.github/workflows/sub-ci-integration-tests-gcp.yml index 65d751ed7eb..d4e4bd506d4 100644 --- a/.github/workflows/sub-ci-integration-tests-gcp.yml +++ b/.github/workflows/sub-ci-integration-tests-gcp.yml @@ -8,9 +8,6 @@ name: Integration Tests on GCP on: workflow_call: inputs: - environment: - required: true - type: string network: default: "Mainnet" type: string diff --git a/.github/workflows/sub-deploy-integration-tests-gcp.yml b/.github/workflows/sub-deploy-integration-tests-gcp.yml index 7b4cbb4449b..9596aed6c19 100644 --- a/.github/workflows/sub-deploy-integration-tests-gcp.yml +++ b/.github/workflows/sub-deploy-integration-tests-gcp.yml @@ -388,6 +388,8 @@ jobs: permissions: contents: 'read' id-token: 'write' + # We want to create images for both dev and prod environments, + # but for prod we only want to create images from the main branch strategy: matrix: environment: ${{ github.ref_name == 'main' && fromJSON('["dev", "prod"]') || fromJSON('["dev"]') }} From 72c26e6f444b68517a9c42d2313721914bc4cd50 Mon Sep 17 00:00:00 2001 From: Gustavo Valverde Date: Mon, 30 Dec 2024 08:52:12 -0400 Subject: [PATCH 4/6] test: just set the environmet when diff to dev --- .github/workflows/sub-find-cached-disks.yml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/.github/workflows/sub-find-cached-disks.yml b/.github/workflows/sub-find-cached-disks.yml index d09d101b4b7..8701ccc8cb0 100644 --- a/.github/workflows/sub-find-cached-disks.yml +++ b/.github/workflows/sub-find-cached-disks.yml @@ -10,10 +10,6 @@ name: Check if cached state disks exist on: workflow_call: inputs: - environment: - required: false - default: dev - type: string network: description: 'The Zcash network used to look up the disks' required: true From 25f4b101197cbdb8a4637a088309f5feedf6c617 Mon Sep 17 00:00:00 2001 From: Gustavo Valverde Date: Mon, 30 Dec 2024 10:13:21 -0400 Subject: [PATCH 5/6] refactor(workflows): unify environment handling across CI configurations - Removed the optional environment input from multiple workflow files, including `manual-zcashd-deploy.yml`, `sub-build-docker-image.yml`, and `sub-deploy-integration-tests-gcp.yml`. - Updated environment assignment logic to consistently use 'prod' for release events across `cd-deploy-nodes-gcp.yml`, `sub-build-docker-image.yml`, `sub-find-cached-disks.yml`, and `sub-deploy-integration-tests-gcp.yml`. - Enhanced clarity in comments regarding environment strategies in `sub-deploy-integration-tests-gcp.yml`. --- .github/workflows/cd-deploy-nodes-gcp.yml | 4 +--- .github/workflows/manual-zcashd-deploy.yml | 3 --- .github/workflows/sub-build-docker-image.yml | 7 +------ .github/workflows/sub-deploy-integration-tests-gcp.yml | 9 ++------- .github/workflows/sub-find-cached-disks.yml | 2 +- 5 files changed, 5 insertions(+), 20 deletions(-) diff --git a/.github/workflows/cd-deploy-nodes-gcp.yml b/.github/workflows/cd-deploy-nodes-gcp.yml index f35fe986965..2872fdb64e6 100644 --- a/.github/workflows/cd-deploy-nodes-gcp.yml +++ b/.github/workflows/cd-deploy-nodes-gcp.yml @@ -155,7 +155,6 @@ jobs: # This workflow also runs on release tags, the event name check will run it on releases. if: ${{ (!startsWith(github.event_name, 'pull') || !github.event.pull_request.head.repo.fork) && !inputs.no_cached_disk }} with: - environment: ${{ github.event_name == 'release' && 'prod' || 'dev' }} network: ${{ inputs.network || vars.ZCASH_NETWORK }} disk_prefix: zebrad-cache disk_suffix: ${{ inputs.cached_disk_type || 'tip' }} @@ -175,7 +174,6 @@ jobs: image_name: zebrad no_cache: ${{ inputs.no_cache || false }} rust_log: info - environment: ${{ github.event_name == 'release' && 'prod' || 'dev' }} # This step needs access to Docker Hub secrets to run successfully secrets: inherit @@ -241,7 +239,7 @@ jobs: timeout-minutes: 60 env: CACHED_DISK_NAME: ${{ needs.get-disk-name.outputs.cached_disk_name }} - environment: ${{ github.event_name == 'release' && 'prod' || 'dev' }} + environment: ${{ github.event_name == 'release' && 'prod' }} permissions: contents: 'read' id-token: 'write' diff --git a/.github/workflows/manual-zcashd-deploy.yml b/.github/workflows/manual-zcashd-deploy.yml index 507dc0c57f2..8fc5951d142 100644 --- a/.github/workflows/manual-zcashd-deploy.yml +++ b/.github/workflows/manual-zcashd-deploy.yml @@ -10,9 +10,6 @@ name: Zcashd Manual Deploy on: workflow_dispatch: inputs: - environment: - required: false - default: dev network: default: 'Mainnet' description: 'Network to deploy: Mainnet or Testnet' diff --git a/.github/workflows/sub-build-docker-image.yml b/.github/workflows/sub-build-docker-image.yml index 7710105900f..60205b69be5 100644 --- a/.github/workflows/sub-build-docker-image.yml +++ b/.github/workflows/sub-build-docker-image.yml @@ -10,11 +10,6 @@ name: Build docker image on: workflow_call: inputs: - environment: - description: 'The infra environment to build the image for' - required: false - default: dev - type: string image_name: required: true type: string @@ -75,7 +70,7 @@ jobs: name: Build images timeout-minutes: 210 runs-on: ubuntu-latest - environment: ${{ inputs.environment }} + environment: ${{ github.event_name == 'release' && 'prod' }} outputs: image_digest: ${{ steps.docker_build.outputs.digest }} image_name: ${{ fromJSON(steps.docker_build.outputs.metadata)['image.name'] }} diff --git a/.github/workflows/sub-deploy-integration-tests-gcp.yml b/.github/workflows/sub-deploy-integration-tests-gcp.yml index 9596aed6c19..fd737de9460 100644 --- a/.github/workflows/sub-deploy-integration-tests-gcp.yml +++ b/.github/workflows/sub-deploy-integration-tests-gcp.yml @@ -3,10 +3,6 @@ name: Deploy Tests to GCP on: workflow_call: inputs: - environment: - required: false - default: dev - type: string # Status and logging test_id: required: true @@ -388,11 +384,10 @@ jobs: permissions: contents: 'read' id-token: 'write' - # We want to create images for both dev and prod environments, - # but for prod we only want to create images from the main branch + # We want to create main branch images for both dev and prod environments strategy: matrix: - environment: ${{ github.ref_name == 'main' && fromJSON('["dev", "prod"]') || fromJSON('["dev"]') }} + environment: ${{ github.ref_name == 'main' && fromJSON('["dev", "prod"]') }} environment: ${{ matrix.environment }} steps: - uses: actions/checkout@v4.2.2 diff --git a/.github/workflows/sub-find-cached-disks.yml b/.github/workflows/sub-find-cached-disks.yml index 8701ccc8cb0..82da4af9f21 100644 --- a/.github/workflows/sub-find-cached-disks.yml +++ b/.github/workflows/sub-find-cached-disks.yml @@ -48,7 +48,7 @@ jobs: get-cached-disks: name: Get ${{ inputs.test_id || inputs.network }} cached disk runs-on: ubuntu-latest - environment: ${{ inputs.environment }} + environment: ${{ github.event_name == 'release' && 'prod' }} outputs: state_version: ${{ steps.get-available-disks.outputs.state_version }} cached_disk_name: ${{ steps.get-available-disks.outputs.cached_disk_name }} From 83a2e34ebccc1c0f544d468a452bf2564dc0aa91 Mon Sep 17 00:00:00 2001 From: Gustavo Valverde Date: Tue, 14 Jan 2025 11:41:38 +0000 Subject: [PATCH 6/6] fix(workflows): update environment assignment logic for CI configurations - Changed environment assignment in `cd-deploy-nodes-gcp.yml`, `sub-build-docker-image.yml`, and `sub-find-cached-disks.yml` to use 'dev' as a fallback when the event is not a release, to avoid a `false` fallback --- .github/workflows/cd-deploy-nodes-gcp.yml | 2 +- .github/workflows/sub-build-docker-image.yml | 2 +- .github/workflows/sub-find-cached-disks.yml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/cd-deploy-nodes-gcp.yml b/.github/workflows/cd-deploy-nodes-gcp.yml index 2872fdb64e6..b515179732b 100644 --- a/.github/workflows/cd-deploy-nodes-gcp.yml +++ b/.github/workflows/cd-deploy-nodes-gcp.yml @@ -239,7 +239,7 @@ jobs: timeout-minutes: 60 env: CACHED_DISK_NAME: ${{ needs.get-disk-name.outputs.cached_disk_name }} - environment: ${{ github.event_name == 'release' && 'prod' }} + environment: ${{ github.event_name == 'release' && 'prod' || 'dev' }} permissions: contents: 'read' id-token: 'write' diff --git a/.github/workflows/sub-build-docker-image.yml b/.github/workflows/sub-build-docker-image.yml index 60205b69be5..82083b53be0 100644 --- a/.github/workflows/sub-build-docker-image.yml +++ b/.github/workflows/sub-build-docker-image.yml @@ -70,7 +70,7 @@ jobs: name: Build images timeout-minutes: 210 runs-on: ubuntu-latest - environment: ${{ github.event_name == 'release' && 'prod' }} + environment: ${{ github.event_name == 'release' && 'prod' || 'dev' }} outputs: image_digest: ${{ steps.docker_build.outputs.digest }} image_name: ${{ fromJSON(steps.docker_build.outputs.metadata)['image.name'] }} diff --git a/.github/workflows/sub-find-cached-disks.yml b/.github/workflows/sub-find-cached-disks.yml index 82da4af9f21..a45e3f731fa 100644 --- a/.github/workflows/sub-find-cached-disks.yml +++ b/.github/workflows/sub-find-cached-disks.yml @@ -48,7 +48,7 @@ jobs: get-cached-disks: name: Get ${{ inputs.test_id || inputs.network }} cached disk runs-on: ubuntu-latest - environment: ${{ github.event_name == 'release' && 'prod' }} + environment: ${{ github.event_name == 'release' && 'prod' || 'dev' }} outputs: state_version: ${{ steps.get-available-disks.outputs.state_version }} cached_disk_name: ${{ steps.get-available-disks.outputs.cached_disk_name }}