diff --git a/.github/workflows/cd-deploy-nodes-gcp.yml b/.github/workflows/cd-deploy-nodes-gcp.yml index cccdd4af542..e827d939c8a 100644 --- a/.github/workflows/cd-deploy-nodes-gcp.yml +++ b/.github/workflows/cd-deploy-nodes-gcp.yml @@ -229,12 +229,29 @@ jobs: # Runs: # - on every push to the `main` branch # - on every release, when it's published + # - on workflow_dispatch for manual deployments + + # Determine which networks to deploy based on the trigger + set-matrix: + runs-on: ubuntu-latest + outputs: + networks: ${{ steps.set-networks.outputs.matrix }} + steps: + - id: set-networks + run: | + if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then + # Manually triggered deployment: output a valid JSON array with the single chosen network. + echo "matrix=[\"${{ inputs.network }}\"]" >> $GITHUB_OUTPUT + else + echo 'matrix=["Mainnet","Testnet"]' >> $GITHUB_OUTPUT + fi + deploy-nodes: strategy: matrix: - network: [Mainnet, Testnet] + network: ${{ fromJSON(needs.set-matrix.outputs.networks) }} name: Deploy ${{ matrix.network }} nodes - needs: [ build, versioning, test-configuration-file, test-zebra-conf-path, get-disk-name ] + needs: [ set-matrix, build, versioning, test-configuration-file, test-zebra-conf-path, get-disk-name ] runs-on: ubuntu-latest timeout-minutes: 60 env: @@ -243,7 +260,11 @@ jobs: permissions: contents: 'read' id-token: 'write' - if: ${{ !cancelled() && !failure() && ((github.event_name == 'push' && github.ref_name == 'main') || github.event_name == 'release') }} + if: ${{ !cancelled() && !failure() && ( + (github.event_name == 'push' && github.ref_name == 'main') || + github.event_name == 'release' || + github.event_name == 'workflow_dispatch' + ) }} steps: - uses: actions/checkout@v4.2.2 @@ -260,7 +281,7 @@ jobs: # Labels in GCP are required to be in lowercase, but the blockchain network # uses sentence case, so we need to downcase the network. # - # Passes the lowercase network to subsequent steps using $NETWORK env variable. + # Passes lowercase network to subsequent steps using $NETWORK env variable. - name: Downcase network name for labels run: | NETWORK_CAPS="${{ matrix.network }}" @@ -277,6 +298,14 @@ jobs: - name: Set up Cloud SDK uses: google-github-actions/setup-gcloud@v2.1.2 + - name: Get static IP address for long-running nodes + # Now runs when triggered by a release or a manual workflow_dispatch event. + if: ${{ github.event_name == 'release' || github.event_name == 'workflow_dispatch' }} + run: | + set -e # Exit immediately if a command exits with a non-zero status. + # Attempt to retrieve the static IP address for the network. + echo "IP_ADDRESS=$(gcloud compute addresses describe zebra-${NETWORK} --region ${{ vars.GCP_REGION }} --format='value(address)')" >> "$GITHUB_ENV" + - name: Create instance template for ${{ matrix.network }} run: | if [ "${{ github.event_name }}" == "release" ]; then @@ -284,6 +313,11 @@ jobs: else DISK_NAME="zebrad-cache-${{ env.GITHUB_HEAD_REF_SLUG_URL || env.GITHUB_REF_SLUG_URL }}-${{ env.GITHUB_SHA_SHORT }}-${NETWORK}" fi + if [ -n "${{ env.IP_ADDRESS }}" ]; then + IP_FLAG="--address=${{ env.IP_ADDRESS }}" + else + IP_FLAG="" + fi DISK_PARAMS="name=${DISK_NAME},device-name=${DISK_NAME},size=400GB,type=pd-balanced" if [ -n "${{ env.CACHED_DISK_NAME }}" ]; then DISK_PARAMS+=",image=${{ env.CACHED_DISK_NAME }}" @@ -293,23 +327,32 @@ jobs: echo "No cached disk found for ${{ matrix.network }} in main branch" exit 1 fi + + # Set log file based on input or default + if [ "${{ github.event_name }}" == "workflow_dispatch" ]; then + LOG_FILE="${{ inputs.log_file }}" + else + LOG_FILE="${{ vars.CD_LOG_FILE }}" + fi + gcloud compute instance-templates create-with-container zebrad-${{ needs.versioning.outputs.major_version || env.GITHUB_REF_SLUG_URL }}-${{ env.GITHUB_SHA_SHORT }}-${NETWORK} \ --machine-type ${{ vars.GCP_SMALL_MACHINE }} \ --boot-disk-size=10GB \ --boot-disk-type=pd-standard \ --image-project=cos-cloud \ --image-family=cos-stable \ - --network-interface=subnet=${{ vars.GCP_SUBNETWORK }} \ + --subnet=${{ vars.GCP_SUBNETWORK }} \ + ${IP_FLAG} \ --create-disk="${DISK_PARAMS}" \ --container-mount-disk=mount-path='/var/cache/zebrad-cache',name=${DISK_NAME},mode=rw \ --container-stdin \ --container-tty \ --container-image ${{ vars.GAR_BASE }}/zebrad@${{ needs.build.outputs.image_digest }} \ - --container-env "NETWORK=${{ matrix.network }},LOG_FILE=${{ vars.CD_LOG_FILE }},LOG_COLOR=false,SENTRY_DSN=${{ vars.SENTRY_DSN }}" \ + --container-env "NETWORK=${{ matrix.network }},LOG_FILE=${LOG_FILE},LOG_COLOR=false,SENTRY_DSN=${{ vars.SENTRY_DSN }}" \ --service-account ${{ vars.GCP_DEPLOYMENTS_SA }} \ --scopes cloud-platform \ --metadata google-logging-enabled=true,google-logging-use-fluentbit=true,google-monitoring-enabled=true \ - --labels=app=zebrad,environment=staging,network=${NETWORK},github_ref=${{ env.GITHUB_REF_SLUG_URL }} \ + --labels=app=zebrad,environment=${{ github.event_name == 'workflow_dispatch' && 'qa' || 'staging' }},network=${NETWORK},github_ref=${{ env.GITHUB_REF_SLUG_URL }} \ --tags zebrad # Check if our destination instance group exists already @@ -340,95 +383,10 @@ jobs: --version template="zebrad-${{ needs.versioning.outputs.major_version || env.GITHUB_REF_SLUG_URL }}-${{ env.GITHUB_SHA_SHORT }}-${NETWORK}" \ --region "${{ vars.GCP_REGION }}" - # This jobs handles the deployment of a single node (1) in the configured GCP zone - # when an instance is required to test a specific commit - # - # Runs: - # - on request, using workflow_dispatch with regenerate-disks - # - # Note: this instances are not automatically replaced or deleted - deploy-instance: - name: Deploy single ${{ inputs.network }} instance - needs: [ build, test-configuration-file, test-zebra-conf-path, get-disk-name ] - runs-on: ubuntu-latest - timeout-minutes: 30 - env: - CACHED_DISK_NAME: ${{ needs.get-disk-name.outputs.cached_disk_name }} - permissions: - contents: 'read' - id-token: 'write' - # Run even if we don't need a cached disk, but only when triggered by a workflow_dispatch - if: ${{ !failure() && github.event_name == 'workflow_dispatch' }} - - steps: - - uses: actions/checkout@v4.2.2 - with: - persist-credentials: false - - - name: Inject slug/short variables - uses: rlespinasse/github-slug-action@v5 - with: - short-length: 7 - - # Makes the Zcash network name lowercase. - # - # Labels in GCP are required to be in lowercase, but the blockchain network - # uses sentence case, so we need to downcase the network. - # - # Passes the lowercase network to subsequent steps using $NETWORK env variable. - - name: Downcase network name for labels - run: | - NETWORK_CAPS="${{ inputs.network }}" - echo "NETWORK=${NETWORK_CAPS,,}" >> "$GITHUB_ENV" - - # Setup gcloud CLI - - name: Authenticate to Google Cloud - id: auth - uses: google-github-actions/auth@v2.1.7 - with: - workload_identity_provider: '${{ vars.GCP_WIF }}' - service_account: '${{ vars.GCP_DEPLOYMENTS_SA }}' - - - name: Set up Cloud SDK - uses: google-github-actions/setup-gcloud@v2.1.2 - - # Create instance template from container image - - name: Manual deploy of a single ${{ inputs.network }} instance running zebrad - run: | - DISK_NAME="zebrad-cache-${{ env.GITHUB_HEAD_REF_SLUG_URL || env.GITHUB_REF_SLUG_URL }}-${{ env.GITHUB_SHA_SHORT }}-${NETWORK}" - DISK_PARAMS="name=${DISK_NAME},device-name=${DISK_NAME},size=400GB,type=pd-balanced" - if [ -n "${{ env.CACHED_DISK_NAME }}" ]; then - DISK_PARAMS+=",image=${{ env.CACHED_DISK_NAME }}" - elif [ ${{ !inputs.need_cached_disk && github.event_name == 'workflow_dispatch' }} ]; then - echo "No cached disk required" - else - echo "No cached disk found for ${{ matrix.network }} in main branch" - exit 1 - fi - gcloud compute instances create-with-container "zebrad-${{ env.GITHUB_REF_SLUG_URL }}-${{ env.GITHUB_SHA_SHORT }}-${NETWORK}" \ - --machine-type ${{ vars.GCP_SMALL_MACHINE }} \ - --boot-disk-size=10GB \ - --boot-disk-type=pd-standard \ - --image-project=cos-cloud \ - --image-family=cos-stable \ - --network-interface=subnet=${{ vars.GCP_SUBNETWORK }} \ - --create-disk="${DISK_PARAMS}" \ - --container-mount-disk=mount-path='/var/cache/zebrad-cache',name=${DISK_NAME},mode=rw \ - --container-stdin \ - --container-tty \ - --container-image ${{ vars.GAR_BASE }}/zebrad@${{ needs.build.outputs.image_digest }} \ - --container-env "NETWORK=${{ inputs.network }},LOG_FILE=${{ inputs.log_file }},LOG_COLOR=false,SENTRY_DSN=${{ vars.SENTRY_DSN }}" \ - --service-account ${{ vars.GCP_DEPLOYMENTS_SA }} \ - --scopes cloud-platform \ - --metadata google-logging-enabled=true,google-monitoring-enabled=true \ - --labels=app=zebrad,environment=qa,network=${NETWORK},github_ref=${{ env.GITHUB_REF_SLUG_URL }} \ - --tags zebrad \ - --zone ${{ vars.GCP_ZONE }} - failure-issue: name: Open or update issues for release failures # When a new job is added to this workflow, add it to this list. - needs: [ versioning, build, deploy-nodes, deploy-instance ] + needs: [ versioning, build, deploy-nodes ] # Only open tickets for failed or cancelled jobs that are not coming from PRs. # (PR statuses are already reported in the PR jobs list, and checked by GitHub's Merge Queue.) if: (failure() && github.event.pull_request == null) || (cancelled() && github.event.pull_request == null) diff --git a/.github/workflows/manual-zcashd-deploy.yml b/.github/workflows/manual-zcashd-deploy.yml index 8fc5951d142..139c51d4b2d 100644 --- a/.github/workflows/manual-zcashd-deploy.yml +++ b/.github/workflows/manual-zcashd-deploy.yml @@ -73,7 +73,7 @@ jobs: --container-image electriccoinco/zcashd \ --container-env ZCASHD_NETWORK="${{ inputs.network }}" \ --machine-type ${{ vars.GCP_SMALL_MACHINE }} \ - --network-interface=subnet=${{ vars.GCP_SUBNETWORK }} \ + --subnet=${{ vars.GCP_SUBNETWORK }} \ --service-account ${{ vars.GCP_DEPLOYMENTS_SA }} \ --scopes cloud-platform \ --labels=app=zcashd,environment=prod,network=${NETWORK},github_ref=${{ env.GITHUB_REF_SLUG_URL }} \