-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcloudbuild-deploy.yaml
52 lines (52 loc) · 2.01 KB
/
cloudbuild-deploy.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# Overview: build and create a release via Google Cloud Deploy for GKE
# NOTE: currently requires SCM triggering due to dependency on the COMMIT_SHA variable
steps:
# Build and tag using commit sha
- name: 'gcr.io/cloud-builders/docker'
args: ['build', '.', '-t', 'us-central1-docker.pkg.dev/$PROJECT_ID/pop-stats/pop-stats:${COMMIT_SHA}', '-f', 'Dockerfile']
dir: 'app'
# Push the container image to Artifact Registry
- name: 'gcr.io/cloud-builders/docker'
args: ['push', 'us-central1-docker.pkg.dev/$PROJECT_ID/pop-stats/pop-stats:${COMMIT_SHA}']
# Generate SBOM for the image
- name: gcr.io/google.com/cloudsdktool/cloud-sdk
entrypoint: bash
args:
- -c
- |
set -ex
gcloud artifacts sbom export \
--uri=us-central1-docker.pkg.dev/$PROJECT_ID/pop-stats/pop-stats:${COMMIT_SHA}
# Create release in Google Cloud Deploy using the digest of the newly built image
- name: gcr.io/google.com/cloudsdktool/cloud-sdk
entrypoint: bash
args:
- -c
- |
set -ex
gcloud artifacts docker images describe \
'us-central1-docker.pkg.dev/$PROJECT_ID/pop-stats/pop-stats:${COMMIT_SHA}' \
--format 'value(image_summary.digest)' > digest
gcloud deploy releases create rel-${SHORT_SHA} \
--delivery-pipeline pop-stats-pipeline \
--region us-central1 \
--annotations commitId=${REVISION_ID} \
--images pop-stats=us-central1-docker.pkg.dev/$PROJECT_ID/pop-stats/pop-stats:${COMMIT_SHA}@$(cat digest)
while :
do
STATE=$(gcloud deploy rollouts describe rel-${SHORT_SHA}-to-staging-0001 \
--delivery-pipeline pop-stats-pipeline \
--region us-central1 \
--release rel-${SHORT_SHA} \
--format 'value(state)')
if [[ "$$STATE" == "FAILED" ]]; then
exit 1
elif [[ "$$STATE" == "SUCCEEDED" ]]; then
exit 0
fi
sleep 5
done
images:
- us-central1-docker.pkg.dev/$PROJECT_ID/pop-stats/pop-stats:${COMMIT_SHA}
options:
requestedVerifyOption: VERIFIED