Fix CD workflow using cloudbuild.yaml (#637)
* Fix variable substitutions in CD workflow and gcloud build config * Docker needs everything lowercase * Store container image in GCR * Don't use GITHUB_REPOSITORY
This commit is contained in:
parent
8b5ec155f0
commit
56361654c6
|
|
@ -4,7 +4,7 @@ on:
|
||||||
push:
|
push:
|
||||||
branches:
|
branches:
|
||||||
- main
|
- main
|
||||||
- gcloud
|
- cloudbuild
|
||||||
|
|
||||||
env:
|
env:
|
||||||
PROJECT_ID: zealous-zebra
|
PROJECT_ID: zealous-zebra
|
||||||
|
|
@ -20,13 +20,12 @@ jobs:
|
||||||
|
|
||||||
- name: Set project and image names
|
- name: Set project and image names
|
||||||
run: |
|
run: |
|
||||||
SHORT_BRANCH_NAME=$(expr $GITHUB_REF : '.*/\(.*\)') && \
|
BRANCH_NAME=$(expr $GITHUB_REF : '.*/\(.*\)') && \
|
||||||
SHORT_BRANCH_NAME=${SHORT_BRANCH_NAME,,} && \
|
|
||||||
BRANCH_NAME=$GITHUB_REPOSITORY/$SHORT_BRANCH_NAME && \
|
|
||||||
BRANCH_NAME=${BRANCH_NAME,,} && \
|
BRANCH_NAME=${BRANCH_NAME,,} && \
|
||||||
echo "::set-env name=SHORT_BRANCH_NAME::$SHORT_BRANCH_NAME" && \
|
REPOSITORY=${GITHUB_REPOSITORY,,} && \
|
||||||
echo "::set-env name=BRANCH_NAME::$BRANCH_NAME" && \
|
echo "::set-env name=BRANCH_NAME::$BRANCH_NAME" && \
|
||||||
echo "::set-env name=SHORT_SHA::$(git rev-parse --short=7 $GITHUB_SHA)"
|
echo "::set-env name=SHORT_SHA::$(git rev-parse --short=7 $GITHUB_SHA)" && \
|
||||||
|
echo "::set-env name=REPOSITORY::$REPOSITORY"
|
||||||
|
|
||||||
# Setup gcloud CLI
|
# Setup gcloud CLI
|
||||||
- name: Set up gcloud Cloud SDK environment
|
- name: Set up gcloud Cloud SDK environment
|
||||||
|
|
@ -42,13 +41,13 @@ jobs:
|
||||||
run: |
|
run: |
|
||||||
gcloud builds submit \
|
gcloud builds submit \
|
||||||
--config cloudbuild.yaml \
|
--config cloudbuild.yaml \
|
||||||
--substitutions SHORT_SHA="$SHORT_SHA"
|
--substitutions SHORT_SHA="$SHORT_SHA",BRANCH_NAME="$BRANCH_NAME"
|
||||||
|
|
||||||
# Create instance template from container image
|
# Create instance template from container image
|
||||||
- name: Create instance template
|
- name: Create instance template
|
||||||
run: |
|
run: |
|
||||||
gcloud compute instance-templates create-with-container "zebrad-$SHORT_BRANCH_NAME-$SHORT_SHA" \
|
gcloud compute instance-templates create-with-container "zebrad-$BRANCH_NAME-$SHORT_SHA" \
|
||||||
--container-image "gcr.io/$PROJECT_ID/$BRANCH_NAME:$SHORT_SHA" \
|
--container-image "gcr.io/$PROJECT_ID/$REPOSITORY/$BRANCH_NAME:$SHORT_SHA" \
|
||||||
--machine-type n1-highmem-8 \
|
--machine-type n1-highmem-8 \
|
||||||
--service-account cos-vm@zealous-zebra.iam.gserviceaccount.com \
|
--service-account cos-vm@zealous-zebra.iam.gserviceaccount.com \
|
||||||
--scopes cloud-platform \
|
--scopes cloud-platform \
|
||||||
|
|
@ -77,15 +76,15 @@ jobs:
|
||||||
id: does-group-exist
|
id: does-group-exist
|
||||||
continue-on-error: true
|
continue-on-error: true
|
||||||
run: |
|
run: |
|
||||||
gcloud compute instance-groups list | grep "zebrad-$SHORT_BRANCH_NAME"
|
gcloud compute instance-groups list | grep "zebrad-$BRANCH_NAME"
|
||||||
|
|
||||||
# Deploy new managed instance group using the new instance template
|
# Deploy new managed instance group using the new instance template
|
||||||
- name: Create managed instance group
|
- name: Create managed instance group
|
||||||
if: steps.does-group-exist.outcome == 'failure'
|
if: steps.does-group-exist.outcome == 'failure'
|
||||||
run: |
|
run: |
|
||||||
gcloud compute instance-groups managed create \
|
gcloud compute instance-groups managed create \
|
||||||
"zebrad-$SHORT_BRANCH_NAME" \
|
"zebrad-$BRANCH_NAME" \
|
||||||
--template "zebrad-$SHORT_BRANCH_NAME-$SHORT_SHA" \
|
--template "zebrad-$BRANCH_NAME-$SHORT_SHA" \
|
||||||
--health-check zebrad-tracing-filter \
|
--health-check zebrad-tracing-filter \
|
||||||
--initial-delay 30 \
|
--initial-delay 30 \
|
||||||
--region us-central1 \
|
--region us-central1 \
|
||||||
|
|
@ -96,6 +95,6 @@ jobs:
|
||||||
if: steps.does-group-exist.outcome == 'success'
|
if: steps.does-group-exist.outcome == 'success'
|
||||||
run: |
|
run: |
|
||||||
gcloud compute instance-groups managed rolling-action start-update \
|
gcloud compute instance-groups managed rolling-action start-update \
|
||||||
"zebrad-$SHORT_BRANCH_NAME" \
|
"zebrad-$BRANCH_NAME" \
|
||||||
--version template="zebrad-$SHORT_BRANCH_NAME-$SHORT_SHA" \
|
--version template="zebrad-$BRANCH_NAME-$SHORT_SHA" \
|
||||||
--region us-central1 \
|
--region us-central1 \
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,8 @@
|
||||||
steps:
|
steps:
|
||||||
- name: 'gcr.io/cloud-builders/docker'
|
- name: 'gcr.io/cloud-builders/docker'
|
||||||
args: ['build', '-t', 'gcr.io/$PROJECT_ID/zcashfoundation/$REPO_NAME/$BRANCH_NAME:$SHORT_SHA', '.']
|
args: ['build', '-t', 'gcr.io/$PROJECT_ID/zcashfoundation/zebra/$BRANCH_NAME:$SHORT_SHA', '.']
|
||||||
|
|
||||||
|
images: ['gcr.io/$PROJECT_ID/zcashfoundation/zebra/$BRANCH_NAME:$SHORT_SHA']
|
||||||
|
|
||||||
options:
|
options:
|
||||||
machineType: 'N1_HIGHCPU_32'
|
machineType: 'N1_HIGHCPU_32'
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue