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

refactor(cd): improve Docker and gcloud usage without Cloud Build #3431

Merged
merged 60 commits into from
Feb 9, 2022
Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
5f812db
refactor (cd): overall pipeline improvement
gustavovalverde Jan 28, 2022
3824e7d
refactor (cd): overall pipeline improvement
gustavovalverde Jan 28, 2022
7bcdab1
fix (cd): allow to build on manual deploy
gustavovalverde Jan 28, 2022
9fd3c22
refactor (cd): use newer google auth action
gustavovalverde Jan 28, 2022
af41726
fix (cd): use newer secret as gcp credential
gustavovalverde Jan 28, 2022
fb8b91f
fix (docker): do not create extra directories
gustavovalverde Jan 28, 2022
f55cf9b
fix (docker): ignore .github for caching purposes
gustavovalverde Jan 28, 2022
850f5a4
fix (docker): use latest rust
gustavovalverde Jan 28, 2022
4bf58f2
fix (cd): bump build timeout
gustavovalverde Jan 28, 2022
9cf620a
fix: use a better name for manual deployment
gustavovalverde Jan 28, 2022
ea2b5bd
refactor (docker): use standard directories for executable
gustavovalverde Jan 30, 2022
8235085
fix (cd): most systems expect a "latest" tag
gustavovalverde Jan 30, 2022
358fbd3
fix (cd): push the build image and the cache separately
gustavovalverde Jan 30, 2022
6b5eeec
fix (cd): remove unused GHA cache
gustavovalverde Jan 30, 2022
0702d79
refactor (cd): use cargo-chef for caching rust deps
gustavovalverde Jan 30, 2022
08b9ba9
fix: move build system deps before cargo cheg cook
gustavovalverde Jan 30, 2022
2122319
fix (release): use newer debian to reduce vulnerabilities
gustavovalverde Jan 30, 2022
d7dc062
fix (cd): use same zone, region and service accounts
gustavovalverde Jan 31, 2022
0e66323
fix (cd): use same disk size and type for all deployments
gustavovalverde Jan 31, 2022
c4a6e88
refactor (cd): activate interactive shells
gustavovalverde Jan 31, 2022
7a2bbdd
tmp (cd): bump timeout for building from scratch
gustavovalverde Jan 31, 2022
556c0f8
fix (docker): do not build with different settings
gustavovalverde Feb 1, 2022
607f4ea
revert (docker): do not fix the rust version
gustavovalverde Feb 1, 2022
7ad399a
fix (docker): build on the root directory
gustavovalverde Feb 1, 2022
3f0604c
refactor(docker): Use base image commands and tools
gustavovalverde Feb 1, 2022
a118ee6
fix (cd): use correct variables & values, add build concurrency
gustavovalverde Feb 1, 2022
5301086
fix(cd): use Mainnet instead of mainnet
gustavovalverde Feb 1, 2022
0b1ff6e
imp: remove checkout as Buildkit uses the git context
gustavovalverde Feb 1, 2022
41635f9
fix (docker): just Buildkit uses a .dockerignore in a path
gustavovalverde Feb 1, 2022
e6fa407
imp (cd): just use needed variables in the right place
gustavovalverde Feb 1, 2022
5d4318d
imp (cd): do not checkout if not needed
gustavovalverde Feb 1, 2022
a89dd2f
test: run on push
gustavovalverde Feb 1, 2022
06269d7
refactor(docker): reduce build changes
gustavovalverde Feb 1, 2022
67eda8c
fix(cd): not checking out was limiting some variables
gustavovalverde Feb 1, 2022
bb89207
fix(cd): remove tests as a runtime dependency
gustavovalverde Feb 1, 2022
aa9191b
fix(cd): use default service account with cloud-platform scope
gustavovalverde Feb 1, 2022
2d42292
fix(cd): revert checkout actions
gustavovalverde Feb 1, 2022
d4c81bb
fix: use GA c2 instead of Preview c2d machine types
gustavovalverde Feb 1, 2022
9e522e1
fix(docker): Do not rebuild to download params and run tests
gustavovalverde Feb 1, 2022
8a67e1d
fix(cd): keep compatibility with gcr.io
gustavovalverde Feb 2, 2022
3ba0359
fix(cd): typo and scope
gustavovalverde Feb 2, 2022
b8c43e3
fix(cd): typos everywhere
gustavovalverde Feb 2, 2022
5989bb9
fix(cd): do not constraint the CPUs for bigger machines
gustavovalverde Feb 2, 2022
de70c6f
revert(cd): reduce PR diff as there's a separate one for tests
gustavovalverde Feb 3, 2022
b7e2f10
fix(docker): do not download zcash params twice
gustavovalverde Feb 4, 2022
bb5623e
feat(docker): add google OS Config agent
gustavovalverde Feb 4, 2022
9f6bc79
fix(docker): $HOME variables is not being expanded
gustavovalverde Feb 4, 2022
66a77fa
fix(docker): do not use variables while using COPY
gustavovalverde Feb 4, 2022
aa48d2c
fix(docker): allow to use zebrad as a command
gustavovalverde Feb 4, 2022
c89c966
fix(cd): use test .yml from main
gustavovalverde Feb 4, 2022
709b2d3
Merge branch 'main' into docker-actions-refactor
gustavovalverde Feb 4, 2022
7677517
feat: add an image to inherit from with zcash params
gustavovalverde Feb 8, 2022
476b48c
fix(cd): use the right image name and allow push to test
gustavovalverde Feb 8, 2022
87cfba9
fix(cd): use the right docker target and remove extra builds
gustavovalverde Feb 8, 2022
acc38fb
refactor(docker): use cached zcash params from previous build
gustavovalverde Feb 8, 2022
3a1c4a7
fix(cd): finalize for merging
gustavovalverde Feb 8, 2022
22005a6
imp(cd): add double safety measure for production
gustavovalverde Feb 8, 2022
e88f443
fix(cd): use specific SHA for containers
gustavovalverde Feb 8, 2022
2795bf2
Merge branch 'main' into docker-actions-refactor
gustavovalverde Feb 8, 2022
ef82699
fix(cd): use latest gcloud action version
gustavovalverde Feb 8, 2022
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
134 changes: 109 additions & 25 deletions .github/workflows/cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,29 @@ name: CD

on:
workflow_dispatch:
inputs:
network:
default: 'Mainnet'
gustavovalverde marked this conversation as resolved.
Show resolved Hide resolved
checkpoint_sync:
default: true
push:
branches:
- main

env:
NETWORK: Mainnet
gustavovalverde marked this conversation as resolved.
Show resolved Hide resolved
PROJECT_ID: ${{ secrets.GCP_PROJECT_ID }}
REGION: us-east1
ZONE: us-east1-b
MACHINE_TYPE: n2d-standard-4
DEPLOY_SA: cos-vm@${{ secrets.GCP_PROJECT_ID }}.iam.gserviceaccount.com
GAR_BASE: us-docker.pkg.dev/${{ secrets.GCP_PROJECT_ID }}/zebra
REGION: us-central1
ZONE: us-central1-a
MACHINE_TYPE: c2d-standard-4

jobs:
build:
name: Build images
timeout-minutes: 60
timeout-minutes: 180
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2.4.0
with:
Expand All @@ -27,25 +34,55 @@ jobs:
uses: rlespinasse/github-slug-action@v4

# Setup gcloud CLI
- name: Set up gcloud SDK environment
uses: google-github-actions/setup-gcloud@v0.4.0
- name: Authenticate to Google Cloud
id: auth
uses: google-github-actions/auth@v0.5.0
with:
credentials_json: ${{ secrets.GOOGLE_CREDENTIALS }}

# Setup Docker Buildx to allow use of docker cache layers from GH
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
with:
driver-opts: network=host

- name: Login to Google Artifact Registry
uses: docker/login-action@v1.12.0
with:
project_id: ${{ env.PROJECT_ID }}
service_account_key: ${{ secrets.GCLOUD_AUTH }}

# Build and push image to Google Container Registry
- name: Build
# Tagging w/ the commit SHA blocks the :latest tag on GCR
run: |
gcloud builds submit \
--config cloudbuild.yaml \
--substitutions SHORT_SHA="${{ env.GITHUB_SHA_SHORT }}",BRANCH_NAME="${{ env.GITHUB_HEAD_REF_SLUG || env.GITHUB_REF_SLUG }}"

deploy:
registry: us-docker.pkg.dev
username: _json_key
password: ${{ secrets.GOOGLE_CREDENTIALS }}

# Build and push image to Google Artifact Registry
- name: Build & push
id: docker_build
uses: docker/build-push-action@v2.8.0
with:
target: runtime
context: .
file: ./docker/Dockerfile.build
tags: |
${{ env.GAR_BASE }}/${{ env.GITHUB_HEAD_REF_SLUG || env.GITHUB_REF_SLUG }}:latest
${{ env.GAR_BASE }}/${{ env.GITHUB_HEAD_REF_SLUG || env.GITHUB_REF_SLUG }}:${{ env.GITHUB_SHA_SHORT }}
build-args: |
NETWORK=${{ github.event.inputs.network || env.NETWORK }}
SHORT_SHA=${{ env.GITHUB_SHA_SHORT }}
RUST_BACKTRACE=full
ZEBRA_SKIP_NETWORK_TESTS="1"
CHECKPOINT_SYNC=${{ github.event.inputs.checkpoint_sync || true }}
RUST_LOG=debug
gustavovalverde marked this conversation as resolved.
Show resolved Hide resolved
SENTRY_DSN=${{ secrets.SENTRY_ENDPOINT }}
push: true
cache-from: type=registry,ref=${{ env.GAR_BASE }}/${{ env.GITHUB_HEAD_REF_SLUG || env.GITHUB_REF_SLUG }}:buildcache
cache-to: type=registry,ref=${{ env.GAR_BASE }}/${{ env.GITHUB_HEAD_REF_SLUG || env.GITHUB_REF_SLUG }}:buildcache,mode=max

deploy-nodes:
name: Deploy mainnet nodes
needs: build
gustavovalverde marked this conversation as resolved.
Show resolved Hide resolved
runs-on: ubuntu-latest
timeout-minutes: 30
if: github.event_name == 'push'
gustavovalverde marked this conversation as resolved.
Show resolved Hide resolved

steps:
- uses: actions/checkout@v2.4.0
with:
Expand All @@ -55,23 +92,28 @@ jobs:
uses: rlespinasse/github-slug-action@v4

# Setup gcloud CLI
- name: Authenticate to Google Cloud
id: auth
uses: google-github-actions/auth@v0.5.0
with:
credentials_json: ${{ secrets.GOOGLE_CREDENTIALS }}

- name: Set up gcloud SDK environment
uses: google-github-actions/setup-gcloud@v0.4.0
with:
project_id: ${{ env.PROJECT_ID }}
service_account_key: ${{ secrets.GCLOUD_AUTH }}

# Create instance template from container image
- name: Create instance template
run: |
gcloud compute instance-templates create-with-container "zebrad-${{ env.GITHUB_HEAD_REF_SLUG || env.GITHUB_REF_SLUG }}-${{ env.GITHUB_SHA_SHORT }}" \
--container-image "gcr.io/${{ env.PROJECT_ID}}/${{ env.GITHUB_REPOSITORY_NAME_PART_SLUG }}/${{ env.GITHUB_HEAD_REF_SLUG || env.GITHUB_REF_SLUG }}:${{ env.GITHUB_SHA_SHORT }}" \
--create-disk name=zebrad-cache-${{ env.GITHUB_SHA_SHORT }},auto-delete=yes,size=100GB,type=pd-balanced \
gcloud compute instance-templates create-with-container zebrad-${{ env.GITHUB_HEAD_REF_SLUG || env.GITHUB_REF_SLUG }}-${{ env.GITHUB_SHA_SHORT }} \
--boot-disk-type=pd-ssd \
--container-image ${{ env.GAR_BASE }}/${{ env.GITHUB_HEAD_REF_SLUG || env.GITHUB_REF_SLUG }} \
gustavovalverde marked this conversation as resolved.
Show resolved Hide resolved
--create-disk name=zebrad-cache-${{ env.GITHUB_SHA_SHORT }},auto-delete=yes,size=100GB,type=pd-ssd \
gustavovalverde marked this conversation as resolved.
Show resolved Hide resolved
--container-mount-disk mount-path="/zebrad-cache",name=zebrad-cache-${{ env.GITHUB_SHA_SHORT }} \
--machine-type ${{ env.MACHINE_TYPE }} \
--service-account ${{ env.DEPLOY_SA }} \
--scopes cloud-platform \
--tags zebrad \
--tags zebrad

# Check if our destination instance group exists already
- name: Check if instance group exists
Expand Down Expand Up @@ -100,3 +142,45 @@ jobs:
"zebrad-${{ env.GITHUB_HEAD_REF_SLUG || env.GITHUB_REF_SLUG }}" \
--version template="zebrad-${{ env.GITHUB_HEAD_REF_SLUG || env.GITHUB_REF_SLUG }}-${{ env.GITHUB_SHA_SHORT }}" \
--region "${{ env.REGION }}"

deploy-instance:
name: Deploy single instance
needs: build
runs-on: ubuntu-latest
timeout-minutes: 30
if: github.event_name == 'workflow_dispatch'

steps:
- uses: actions/checkout@v2.4.0
with:
persist-credentials: false

- name: Inject slug/short variables
uses: rlespinasse/github-slug-action@v4

# Setup gcloud CLI
- name: Authenticate to Google Cloud
id: auth
uses: google-github-actions/auth@v0.5.0
with:
credentials_json: ${{ secrets.GOOGLE_CREDENTIALS }}

- name: Set up gcloud SDK environment
uses: google-github-actions/setup-gcloud@v0.4.0
with:
project_id: ${{ env.PROJECT_ID }}

# Create instance template from container image
- name: Manual deploy of a single instance running zebrad
run: |
gcloud compute instances create-with-container "zebrad-${{ env.GITHUB_HEAD_REF_SLUG || env.GITHUB_REF_SLUG }}-${{ env.GITHUB_SHA_SHORT }}" \
--boot-disk-size 100GB \
--boot-disk-type=pd-ssd \
--container-stdin \
--container-tty \
--container-image ${{ env.GAR_BASE }}/${{ env.GITHUB_HEAD_REF_SLUG || env.GITHUB_REF_SLUG }} \
gustavovalverde marked this conversation as resolved.
Show resolved Hide resolved
--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
53 changes: 0 additions & 53 deletions .github/workflows/manual-deploy.yml

This file was deleted.

17 changes: 12 additions & 5 deletions .github/workflows/regenerate-stateful-test-disks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ on:

env:
PROJECT_ID: ${{ secrets.GCP_PROJECT_ID }}
ZONE: europe-west1-b
MACHINE_TYPE: n2-standard-4
REGION: us-central1
ZONE: us-central1-a
MACHINE_TYPE: c2d-standard-4
DEPLOY_SA: cos-vm@${{ secrets.GCP_PROJECT_ID }}.iam.gserviceaccount.com

jobs:
Expand All @@ -25,11 +26,17 @@ jobs:
- name: Inject slug/short variables
uses: rlespinasse/github-slug-action@v4

- name: Set up gcloud
# Setup gcloud CLI
- name: Authenticate to Google Cloud
id: auth
uses: google-github-actions/auth@v0.5.0
with:
credentials_json: ${{ secrets.GOOGLE_CREDENTIALS }}

- name: Set up gcloud SDK environment
uses: google-github-actions/setup-gcloud@v0.4.0
with:
project_id: ${{ env.PROJECT_ID }}
service_account_key: ${{ secrets.GCLOUD_AUTH }}

# Creates Compute Engine virtual machine instance w/ disks
- name: Create instance
Expand All @@ -40,7 +47,7 @@ jobs:
--container-image rust:buster \
gustavovalverde marked this conversation as resolved.
Show resolved Hide resolved
--container-mount-disk mount-path='/${{ github.event.inputs.network }}',name="zebrad-cache-${{ env.GITHUB_SHA_SHORT }}-${{ github.event.inputs.network }}-canopy" \
--container-restart-policy never \
--create-disk name="zebrad-cache-${{ env.GITHUB_SHA_SHORT }}-${{ github.event.inputs.network }}-canopy",size=100GB,type=pd-balanced \
--create-disk name="zebrad-cache-${{ env.GITHUB_SHA_SHORT }}-${{ github.event.inputs.network }}-canopy",size=100GB,type=pd-ssd \
--machine-type ${{ env.MACHINE_TYPE }} \
--service-account ${{ env.DEPLOY_SA }} \
--scopes cloud-platform \
Expand Down
17 changes: 13 additions & 4 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ on:

env:
PROJECT_ID: ${{ secrets.GCP_PROJECT_ID }}
ZONE: europe-west1-b
MACHINE_TYPE: n2-standard-8
REGION: us-central1
ZONE: us-central1-a
MACHINE_TYPE: c2d-standard-8
DEPLOY_SA: cos-vm@${{ secrets.GCP_PROJECT_ID }}.iam.gserviceaccount.com

jobs:
Expand All @@ -32,18 +33,26 @@ jobs:
- name: Inject slug/short variables
uses: rlespinasse/github-slug-action@v4

- name: Set up gcloud
# Setup gcloud CLI
- name: Authenticate to Google Cloud
id: auth
uses: google-github-actions/auth@v0.5.0
with:
credentials_json: ${{ secrets.GOOGLE_CREDENTIALS }}

- name: Set up gcloud SDK environment
uses: google-github-actions/setup-gcloud@v0.4.0
with:
project_id: ${{ env.PROJECT_ID }}
service_account_key: ${{ secrets.GCLOUD_AUTH }}

# Creates Compute Engine virtual machine instance w/ disks
- name: Create instance
run: |
gcloud compute instances create-with-container "zebrad-tests-${{ env.GITHUB_HEAD_REF_SLUG || env.GITHUB_REF_SLUG }}-${{ env.GITHUB_SHA_SHORT }}" \
--boot-disk-size 100GB \
--boot-disk-type pd-ssd \
--container-stdin \
--container-tty \
--container-image rust:buster \
--container-mount-disk mount-path='/mainnet',name="zebrad-cache-${{ env.GITHUB_SHA_SHORT }}-mainnet-canopy" \
--container-restart-policy never \
Expand Down
13 changes: 11 additions & 2 deletions .github/workflows/zcashd-manual-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ on:
env:
PROJECT_ID: ${{ secrets.GCP_PROJECT_ID }}
REGION: us-central1
MACHINE_TYPE: n2-standard-4
ZONE: us-central1-a
MACHINE_TYPE: c2d-standard-4
DEPLOY_SA: cos-vm@${{ secrets.GCP_PROJECT_ID }}.iam.gserviceaccount.com

jobs:
Expand All @@ -29,17 +30,25 @@ jobs:
uses: rlespinasse/github-slug-action@v4

# Setup gcloud CLI
- name: Authenticate to Google Cloud
id: auth
uses: google-github-actions/auth@v0.5.0
with:
credentials_json: ${{ secrets.GOOGLE_CREDENTIALS }}

- name: Set up gcloud SDK environment
uses: google-github-actions/setup-gcloud@v0.4.0
with:
project_id: ${{ env.PROJECT_ID }}
service_account_key: ${{ secrets.GCLOUD_AUTH }}

# Create instance template from container image
- name: Create instance template
run: |
gcloud compute instance-templates create-with-container "zcashd-${{ env.GITHUB_HEAD_REF_SLUG || env.GITHUB_REF_SLUG }}-${{ env.GITHUB_SHA_SHORT }}" \
--boot-disk-size 100GB \
--boot-disk-type=pd-ssd \
--container-stdin \
--container-tty \
--container-image "electriccoinco/zcashd" \
--container-env ZCASHD_NETWORK="${{ github.event.inputs.network }}" \
--machine-type ${{ env.MACHINE_TYPE }} \
Expand Down
25 changes: 0 additions & 25 deletions cloudbuild.yaml

This file was deleted.

1 change: 1 addition & 0 deletions docker/.dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ target
Dockerfile
.dockerignore
.git
.github
.gitignore
Loading