name: Zcashd Manual Deploy on: workflow_dispatch: inputs: network: default: 'Mainnet' description: 'Network to deploy: Mainnet or Testnet' required: true size: default: '10' description: 'GCP Managed Instance Group size' required: true jobs: deploy: name: Deploy zcashd nodes runs-on: ubuntu-latest timeout-minutes: 30 permissions: contents: 'read' id-token: 'write' steps: - uses: actions/checkout@v3.5.3 with: persist-credentials: false - name: Inject slug/short variables uses: rlespinasse/github-slug-action@v4 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 ${{ inputs.network }}. # # Passes ${{ inputs.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@v1.1.1 with: retries: '3' workload_identity_provider: '${{ vars.GCP_WIF }}' service_account: '${{ vars.GCP_DEPLOYMENTS_SA }}' - name: Set up Cloud SDK uses: google-github-actions/setup-gcloud@v1.1.1 # Create instance template from container image - name: Create instance template run: | gcloud compute instance-templates create-with-container zcashd-${{ env.GITHUB_REF_SLUG_URL }}-${{ env.GITHUB_SHA_SHORT }} \ --boot-disk-size 10GB \ --boot-disk-type=pd-ssd \ --image-project=cos-cloud \ --image-family=cos-stable \ --container-stdin \ --container-tty \ --container-image electriccoinco/zcashd \ --container-env ZCASHD_NETWORK="${{ inputs.network }}" \ --machine-type ${{ vars.GCP_SMALL_MACHINE }} \ --network-interface=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 }} \ --tags zcashd # Check if our destination instance group exists already - name: Check if instance group exists id: does-group-exist continue-on-error: true run: | gcloud compute instance-groups list | grep "zcashd-${{ env.GITHUB_REF_SLUG_URL }}-${{ inputs.network }}" | grep "${{ vars.GCP_REGION }}" # Deploy new managed instance group using the new instance template - name: Create managed instance group if: steps.does-group-exist.outcome == 'failure' run: | gcloud compute instance-groups managed create \ "zcashd-${{ env.GITHUB_REF_SLUG_URL }}-${{ inputs.network }}" \ --template "zcashd-${{ env.GITHUB_REF_SLUG_URL }}-${{ env.GITHUB_SHA_SHORT }}" \ --region "${{ vars.GCP_REGION }}" \ --size "${{ github.event.inputs.size }}" # Rolls out update to existing group using the new instance template - name: Update managed instance group if: steps.does-group-exist.outcome == 'success' run: | gcloud compute instance-groups managed rolling-action start-update \ "zcashd-${{ env.GITHUB_REF_SLUG_URL }}-${{ inputs.network }}" \ --version template="zcashd-${{ env.GITHUB_REF_SLUG_URL }}-${{ env.GITHUB_SHA_SHORT }}" \ --region "${{ vars.GCP_REGION }}"