2020-06-21 01:39:47 -07:00
|
|
|
name: CD
|
2020-06-08 18:03:51 -07:00
|
|
|
|
|
|
|
on:
|
2020-11-19 12:21:03 -08:00
|
|
|
workflow_dispatch:
|
2022-02-08 16:50:13 -08:00
|
|
|
inputs:
|
|
|
|
network:
|
|
|
|
default: 'Mainnet'
|
2022-04-11 22:06:37 -07:00
|
|
|
description: 'Network to deploy: Mainnet or Testnet'
|
|
|
|
required: true
|
2022-02-08 16:50:13 -08:00
|
|
|
checkpoint_sync:
|
2022-04-11 22:06:37 -07:00
|
|
|
default: 'true'
|
|
|
|
description: 'Use as many checkpoints as possible when syncing'
|
|
|
|
required: true
|
2020-06-08 18:03:51 -07:00
|
|
|
push:
|
2020-06-18 23:14:10 -07:00
|
|
|
branches:
|
|
|
|
- main
|
2022-08-28 05:46:21 -07:00
|
|
|
release:
|
|
|
|
types:
|
|
|
|
- published
|
2020-06-08 18:03:51 -07:00
|
|
|
|
2020-06-15 01:32:51 -07:00
|
|
|
env:
|
2022-02-08 16:50:13 -08:00
|
|
|
NETWORK: Mainnet
|
2022-03-18 14:25:35 -07:00
|
|
|
GAR_BASE: us-docker.pkg.dev/zealous-zebra/zebra
|
2022-02-08 16:50:13 -08:00
|
|
|
REGION: us-central1
|
|
|
|
ZONE: us-central1-a
|
|
|
|
MACHINE_TYPE: c2-standard-4
|
2020-06-15 01:32:51 -07:00
|
|
|
|
2020-06-08 18:03:51 -07:00
|
|
|
jobs:
|
2022-08-28 05:46:21 -07:00
|
|
|
# If a release was made we want to extract the first part of the semver from the
|
|
|
|
# tag_name
|
|
|
|
#
|
|
|
|
# Generate the following output to pass to subsequent jobs
|
|
|
|
# - If our semver is `v1.3.0` the resulting output from this job would be `v1`
|
|
|
|
#
|
|
|
|
# Note: We just use the first part of the version to replace old instances, and change
|
|
|
|
# it when a major version is released, to keep a segregation between new and old
|
|
|
|
# versions.
|
|
|
|
versioning:
|
|
|
|
name: Versioning
|
|
|
|
runs-on: ubuntu-latest
|
|
|
|
outputs:
|
|
|
|
major_version: ${{ steps.set.outputs.major_version }}
|
2022-08-28 16:56:58 -07:00
|
|
|
if: ${{ github.event_name == 'release' }}
|
2022-08-28 05:46:21 -07:00
|
|
|
steps:
|
|
|
|
- name: Getting Zebrad Version
|
|
|
|
id: get
|
|
|
|
uses: actions/github-script@v6.1.0
|
|
|
|
with:
|
|
|
|
result-encoding: string
|
|
|
|
script: |
|
|
|
|
return context.payload.release.tag_name.substring(0,2)
|
|
|
|
- name: Setting API Version
|
|
|
|
id: set
|
|
|
|
run: echo "::set-output name=major_version::${{ steps.get.outputs.result }}"
|
|
|
|
|
|
|
|
# Each time this workflow is executed, a build will be triggered to create a new image
|
|
|
|
# with the corresponding tags using information from Git
|
|
|
|
#
|
|
|
|
# The image will be commonly named `zebrad:<short-hash | github-ref | semver>`
|
2020-06-08 18:03:51 -07:00
|
|
|
build:
|
2022-05-09 12:54:16 -07:00
|
|
|
uses: ./.github/workflows/build-docker-image.yml
|
2022-04-28 01:13:35 -07:00
|
|
|
with:
|
|
|
|
dockerfile_path: ./docker/Dockerfile
|
|
|
|
dockerfile_target: runtime
|
|
|
|
image_name: zebrad
|
|
|
|
network: Mainnet
|
|
|
|
checkpoint_sync: true
|
|
|
|
rust_backtrace: '1'
|
|
|
|
zebra_skip_ipv6_tests: '1'
|
|
|
|
rust_log: info
|
2022-02-08 16:50:13 -08:00
|
|
|
|
2022-08-28 05:46:21 -07:00
|
|
|
# This jobs handles the deployment of a Managed Instance Group (MiG) with 2 nodes in
|
|
|
|
# the us-central1 region. Two different groups of MiGs are deployed one for pushes to
|
|
|
|
# the main branch and another for version releases of Zebra
|
|
|
|
#
|
|
|
|
# Once this workflow is triggered the previous MiG is replaced, on pushes to main its
|
|
|
|
# always replaced, and with releases its only replaced if the same major version is
|
|
|
|
# being deployed, otherwise a new major version is deployed
|
|
|
|
#
|
|
|
|
# Runs:
|
|
|
|
# - on every push/merge to the `main` branch
|
|
|
|
# - on every release, when it's published
|
2022-02-08 16:50:13 -08:00
|
|
|
deploy-nodes:
|
|
|
|
name: Deploy Mainnet nodes
|
2022-08-28 05:46:21 -07:00
|
|
|
needs: [ build, versioning ]
|
2020-11-12 12:18:35 -08:00
|
|
|
runs-on: ubuntu-latest
|
|
|
|
timeout-minutes: 30
|
2022-03-18 14:25:35 -07:00
|
|
|
permissions:
|
|
|
|
contents: 'read'
|
|
|
|
id-token: 'write'
|
2022-08-28 16:56:58 -07:00
|
|
|
if: ${{ !cancelled() && !failure() && ((github.event_name == 'push' && github.ref_name == 'main') || github.event_name == 'release') }}
|
2022-02-08 16:50:13 -08:00
|
|
|
|
2020-11-12 12:18:35 -08:00
|
|
|
steps:
|
refactor (actions): make better use of variables, secrets and versions (#3393)
* style: use global variables and don't double print
Remove repeated instances of global environment variables. Do not print ENV variables on the terminal as GitHub Actions already shows it.
* fix (actions): Use fixed major versions for actions
As actions get recurrent fixes, using a specific version causes more maintance on the pipelines.
On the other hand, using @master versions could make some action unreliable, as breaking changes might be included without further notice, and even change behavior on a daily basis.
* refactor: make better use of ENV variables
A whole step with refex was being used to extract different variables from GitHub's environment. This gets depecrated in favor of using `rlespinasse/github-slug-action@v4` which has slug URL variables.
A SLUG on a variable will:
- put the variable content in lower case
- replace any character by - except 0-9, a-z, ., and _
- remove leading and trailing - character
- limit the string size to 63 characters
This changes also takes care of using the Head or Base branch for deployments. This will allow us tomerge of workflows, as most steps on this deployment actions are very similar, with little variations between workflows.
* fix (actions): use secrets for sensitive information
* revert: use specific versions for dependabot
Reverting commit 8c934099028e0651e464678c096d8d3815efe95c
2022-01-26 17:46:18 -08:00
|
|
|
- name: Inject slug/short variables
|
|
|
|
uses: rlespinasse/github-slug-action@v4
|
2022-03-21 16:07:01 -07:00
|
|
|
with:
|
|
|
|
short-length: 7
|
2020-11-12 12:18:35 -08:00
|
|
|
|
|
|
|
# Setup gcloud CLI
|
2022-02-08 16:50:13 -08:00
|
|
|
- name: Authenticate to Google Cloud
|
|
|
|
id: auth
|
2022-05-24 12:16:18 -07:00
|
|
|
uses: google-github-actions/auth@v0.8.0
|
2022-02-08 16:50:13 -08:00
|
|
|
with:
|
2022-08-23 20:49:55 -07:00
|
|
|
retries: '3'
|
2022-03-18 14:25:35 -07:00
|
|
|
workload_identity_provider: 'projects/143793276228/locations/global/workloadIdentityPools/github-actions/providers/github-oidc'
|
|
|
|
service_account: 'github-service-account@zealous-zebra.iam.gserviceaccount.com'
|
|
|
|
token_format: 'access_token'
|
2020-11-12 12:18:35 -08:00
|
|
|
|
|
|
|
- name: Create instance template
|
|
|
|
run: |
|
2022-08-28 05:46:21 -07:00
|
|
|
gcloud compute instance-templates create-with-container zebrad-${{ needs.versioning.outputs.major_version || env.GITHUB_REF_SLUG_URL }}-${{ env.GITHUB_SHA_SHORT }} \
|
2022-02-08 16:50:13 -08:00
|
|
|
--boot-disk-type=pd-ssd \
|
2022-08-28 05:46:21 -07:00
|
|
|
--container-image ${{ env.GAR_BASE }}/zebrad@${{ needs.build.outputs.image_digest }} \
|
2022-02-08 16:50:13 -08:00
|
|
|
--create-disk name=zebrad-cache-${{ env.GITHUB_SHA_SHORT }},auto-delete=yes,size=100GB,type=pd-ssd \
|
refactor (actions): make better use of variables, secrets and versions (#3393)
* style: use global variables and don't double print
Remove repeated instances of global environment variables. Do not print ENV variables on the terminal as GitHub Actions already shows it.
* fix (actions): Use fixed major versions for actions
As actions get recurrent fixes, using a specific version causes more maintance on the pipelines.
On the other hand, using @master versions could make some action unreliable, as breaking changes might be included without further notice, and even change behavior on a daily basis.
* refactor: make better use of ENV variables
A whole step with refex was being used to extract different variables from GitHub's environment. This gets depecrated in favor of using `rlespinasse/github-slug-action@v4` which has slug URL variables.
A SLUG on a variable will:
- put the variable content in lower case
- replace any character by - except 0-9, a-z, ., and _
- remove leading and trailing - character
- limit the string size to 63 characters
This changes also takes care of using the Head or Base branch for deployments. This will allow us tomerge of workflows, as most steps on this deployment actions are very similar, with little variations between workflows.
* fix (actions): use secrets for sensitive information
* revert: use specific versions for dependabot
Reverting commit 8c934099028e0651e464678c096d8d3815efe95c
2022-01-26 17:46:18 -08:00
|
|
|
--container-mount-disk mount-path="/zebrad-cache",name=zebrad-cache-${{ env.GITHUB_SHA_SHORT }} \
|
|
|
|
--machine-type ${{ env.MACHINE_TYPE }} \
|
2020-06-15 01:32:51 -07:00
|
|
|
--scopes cloud-platform \
|
2022-02-08 16:50:13 -08:00
|
|
|
--tags zebrad
|
2020-06-18 14:52:53 -07:00
|
|
|
|
2020-11-12 12:18:35 -08:00
|
|
|
# Check if our destination instance group exists already
|
|
|
|
- name: Check if instance group exists
|
|
|
|
id: does-group-exist
|
|
|
|
continue-on-error: true
|
|
|
|
run: |
|
2022-08-28 05:46:21 -07:00
|
|
|
gcloud compute instance-groups list | grep "zebrad-${{ needs.versioning.outputs.major_version || env.GITHUB_REF_SLUG_URL }}" | grep "${{ env.REGION }}"
|
2020-11-12 12:18:35 -08:00
|
|
|
|
|
|
|
# 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 \
|
2022-08-28 05:46:21 -07:00
|
|
|
"zebrad-${{ needs.versioning.outputs.major_version || env.GITHUB_REF_SLUG_URL }}" \
|
|
|
|
--template "zebrad-${{ needs.versioning.outputs.major_version || env.GITHUB_REF_SLUG_URL }}-${{ env.GITHUB_SHA_SHORT }}" \
|
2020-06-21 01:39:47 -07:00
|
|
|
--health-check zebrad-tracing-filter \
|
|
|
|
--initial-delay 30 \
|
refactor (actions): make better use of variables, secrets and versions (#3393)
* style: use global variables and don't double print
Remove repeated instances of global environment variables. Do not print ENV variables on the terminal as GitHub Actions already shows it.
* fix (actions): Use fixed major versions for actions
As actions get recurrent fixes, using a specific version causes more maintance on the pipelines.
On the other hand, using @master versions could make some action unreliable, as breaking changes might be included without further notice, and even change behavior on a daily basis.
* refactor: make better use of ENV variables
A whole step with refex was being used to extract different variables from GitHub's environment. This gets depecrated in favor of using `rlespinasse/github-slug-action@v4` which has slug URL variables.
A SLUG on a variable will:
- put the variable content in lower case
- replace any character by - except 0-9, a-z, ., and _
- remove leading and trailing - character
- limit the string size to 63 characters
This changes also takes care of using the Head or Base branch for deployments. This will allow us tomerge of workflows, as most steps on this deployment actions are very similar, with little variations between workflows.
* fix (actions): use secrets for sensitive information
* revert: use specific versions for dependabot
Reverting commit 8c934099028e0651e464678c096d8d3815efe95c
2022-01-26 17:46:18 -08:00
|
|
|
--region "${{ env.REGION }}" \
|
2020-06-21 01:39:47 -07:00
|
|
|
--size 2
|
2020-06-19 00:26:31 -07:00
|
|
|
|
2020-11-12 12:18:35 -08:00
|
|
|
# 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 \
|
2022-08-28 05:46:21 -07:00
|
|
|
"zebrad-${{ needs.versioning.outputs.major_version || env.GITHUB_REF_SLUG_URL }}" \
|
|
|
|
--version template="zebrad-${{ needs.versioning.outputs.major_version || env.GITHUB_REF_SLUG_URL }}-${{ env.GITHUB_SHA_SHORT }}" \
|
refactor (actions): make better use of variables, secrets and versions (#3393)
* style: use global variables and don't double print
Remove repeated instances of global environment variables. Do not print ENV variables on the terminal as GitHub Actions already shows it.
* fix (actions): Use fixed major versions for actions
As actions get recurrent fixes, using a specific version causes more maintance on the pipelines.
On the other hand, using @master versions could make some action unreliable, as breaking changes might be included without further notice, and even change behavior on a daily basis.
* refactor: make better use of ENV variables
A whole step with refex was being used to extract different variables from GitHub's environment. This gets depecrated in favor of using `rlespinasse/github-slug-action@v4` which has slug URL variables.
A SLUG on a variable will:
- put the variable content in lower case
- replace any character by - except 0-9, a-z, ., and _
- remove leading and trailing - character
- limit the string size to 63 characters
This changes also takes care of using the Head or Base branch for deployments. This will allow us tomerge of workflows, as most steps on this deployment actions are very similar, with little variations between workflows.
* fix (actions): use secrets for sensitive information
* revert: use specific versions for dependabot
Reverting commit 8c934099028e0651e464678c096d8d3815efe95c
2022-01-26 17:46:18 -08:00
|
|
|
--region "${{ env.REGION }}"
|
2022-02-08 16:50:13 -08:00
|
|
|
|
2022-08-28 05:46:21 -07:00
|
|
|
# This jobs handles the deployment of a single node (1) in the us-central1-a 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
|
2022-02-08 16:50:13 -08:00
|
|
|
deploy-instance:
|
|
|
|
name: Deploy single instance
|
|
|
|
needs: build
|
|
|
|
runs-on: ubuntu-latest
|
|
|
|
timeout-minutes: 30
|
2022-03-18 14:25:35 -07:00
|
|
|
permissions:
|
|
|
|
contents: 'read'
|
|
|
|
id-token: 'write'
|
2022-02-08 16:50:13 -08:00
|
|
|
if: github.event_name == 'workflow_dispatch'
|
|
|
|
|
|
|
|
steps:
|
|
|
|
- name: Inject slug/short variables
|
|
|
|
uses: rlespinasse/github-slug-action@v4
|
2022-03-21 16:07:01 -07:00
|
|
|
with:
|
|
|
|
short-length: 7
|
2022-02-08 16:50:13 -08:00
|
|
|
|
|
|
|
# Setup gcloud CLI
|
|
|
|
- name: Authenticate to Google Cloud
|
|
|
|
id: auth
|
2022-05-24 12:16:18 -07:00
|
|
|
uses: google-github-actions/auth@v0.8.0
|
2022-02-08 16:50:13 -08:00
|
|
|
with:
|
2022-08-23 20:49:55 -07:00
|
|
|
retries: '3'
|
2022-03-18 14:25:35 -07:00
|
|
|
workload_identity_provider: 'projects/143793276228/locations/global/workloadIdentityPools/github-actions/providers/github-oidc'
|
|
|
|
service_account: 'github-service-account@zealous-zebra.iam.gserviceaccount.com'
|
|
|
|
token_format: 'access_token'
|
2022-02-08 16:50:13 -08:00
|
|
|
|
|
|
|
# Create instance template from container image
|
|
|
|
- name: Manual deploy of a single instance running zebrad
|
|
|
|
run: |
|
2022-03-03 22:33:29 -08:00
|
|
|
gcloud compute instances create-with-container "zebrad-${{ env.GITHUB_REF_SLUG_URL }}-${{ env.GITHUB_SHA_SHORT }}" \
|
2022-02-08 16:50:13 -08:00
|
|
|
--boot-disk-size 100GB \
|
|
|
|
--boot-disk-type=pd-ssd \
|
|
|
|
--container-stdin \
|
|
|
|
--container-tty \
|
2022-08-28 05:46:21 -07:00
|
|
|
--container-image ${{ env.GAR_BASE }}/zebrad@${{ needs.build.outputs.image_digest }} \
|
2022-02-08 16:50:13 -08:00
|
|
|
--create-disk name=zebrad-cache-${{ env.GITHUB_SHA_SHORT }},auto-delete=yes,size=100GB,type=pd-ssd \
|
|
|
|
--container-mount-disk mount-path='/zebrad-cache',name=zebrad-cache-${{ env.GITHUB_SHA_SHORT }} \
|
|
|
|
--machine-type ${{ env.MACHINE_TYPE }} \
|
|
|
|
--zone ${{ env.ZONE }} \
|
|
|
|
--tags zebrad
|