Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(cd): add external static IPs to release nodes #8891

Draft
wants to merge 13 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
139 changes: 46 additions & 93 deletions .github/workflows/cd-deploy-nodes-gcp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -229,12 +229,28 @@
# 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: |

Check warning on line 241 in .github/workflows/cd-deploy-nodes-gcp.yml

View workflow job for this annotation

GitHub Actions / actionlint

[actionlint] .github/workflows/cd-deploy-nodes-gcp.yml#L241

shellcheck reported issue in this script: SC2086:info:2:52: Double quote to prevent globbing and word splitting [shellcheck]
Raw output
.github/workflows/cd-deploy-nodes-gcp.yml:241:9: shellcheck reported issue in this script: SC2086:info:2:52: Double quote to prevent globbing and word splitting [shellcheck]

Check warning on line 241 in .github/workflows/cd-deploy-nodes-gcp.yml

View workflow job for this annotation

GitHub Actions / actionlint

[actionlint] .github/workflows/cd-deploy-nodes-gcp.yml#L241

shellcheck reported issue in this script: SC2086:info:4:42: Double quote to prevent globbing and word splitting [shellcheck]
Raw output
.github/workflows/cd-deploy-nodes-gcp.yml:241:9: shellcheck reported issue in this script: SC2086:info:4:42: Double quote to prevent globbing and word splitting [shellcheck]
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
echo "matrix=[${{ toJSON(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:
Expand All @@ -243,7 +259,11 @@
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
Expand All @@ -260,7 +280,7 @@
# 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 }}"
Expand All @@ -277,13 +297,22 @@
- name: Set up Cloud SDK
uses: google-github-actions/setup-gcloud@v2.1.2

- name: Get IP address for long-running release nodes
if: ${{ github.event_name == 'release' }}
run: echo "IP_ADDRESS=$(gcloud compute addresses describe zebra-${NETWORK} --region ${{ vars.GCP_REGION }} --format='value(address)')" >> "$GITHUB_ENV"

Check warning on line 302 in .github/workflows/cd-deploy-nodes-gcp.yml

View workflow job for this annotation

GitHub Actions / actionlint

[actionlint] .github/workflows/cd-deploy-nodes-gcp.yml#L302

shellcheck reported issue in this script: SC2086:info:1:60: Double quote to prevent globbing and word splitting [shellcheck]
Raw output
.github/workflows/cd-deploy-nodes-gcp.yml:302:9: shellcheck reported issue in this script: SC2086:info:1:60: Double quote to prevent globbing and word splitting [shellcheck]

- name: Create instance template for ${{ matrix.network }}
run: |
if [ "${{ github.event_name }}" == "release" ]; then
DISK_NAME="zebrad-cache-${NETWORK}"
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 }}"
Expand All @@ -293,23 +322,32 @@
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
Expand Down Expand Up @@ -340,95 +378,10 @@
--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)
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/manual-zcashd-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }} \
Expand Down
Loading