-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathcloudbuild.yaml
132 lines (126 loc) · 5.89 KB
/
cloudbuild.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
# Copyright 2022 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# For this cloud build I'd like to thank Alex Bielski!
# Parameters from external:
# - _DEPLOY_UNIT (module / appname)
# - _ARTIFACT_REPONAME (AR reponame, dflt to "cicd-plat")
# - LOCATION otherwise a personal _REGION :) - only works online
# - _REGION as the above fix :)
# - _VERSION addded on 9jun22
#
# Note for Ricc: when you add a _VARIABLE you need to change the invocation of build
# and issue a new building filosofy with different versions...
#
# Cache is in format: gs://$SKAFFOLD_BUCKET/skaffold-cache/$MODULE.txt
# Note $SKAFFOLD_BUCKET defaults to "${PROJECT_ID}-skaffoldcache"
#
# v1.3 10jun22: Added bash script. Also added IDs and dependencies as per
# https://cloud.google.com/build/docs/configuring-builds/configure-build-step-order
# v1.2 25may22: Changed REGION to _DEPLOY_REGION for step 4 since my original
# region wasnt big enough. In turn this forced me to change Build
# triggers
steps:
- name: gcr.io/cloud-builders/gsutil
id: PullCache
args: ['cp', 'gs://$PROJECT_ID-skaffoldcache/skaffold-cache/$_DEPLOY_UNIT.txt', '/workspace/cache']
# - name: gcr.io/k8s-skaffold/skaffold:v1.38.0 # Sander told me to point to 1.37 - same as CD
# - name: gcr.io/k8s-skaffold/skaffold:v1.37.1-lts # not sure why i removed this..
# - name: gcr.io/k8s-skaffold/skaffold:v1.37.1-lts # 2022-07-11 doesnt work wuith aopp02: Step #1 - "SkaffoldBuildUsingCache": time="2022-07-11T12:58:11Z" level=warning msg="Your Skaffold version might be too old. Download the latest version (1.39.1) from:\n https://github.com/GoogleContainerTools/skaffold/releases/tag/v1.39.1\n" subtask=-1 task=DevLoop
# 20220715 Note from Alex 1.38.0 uis NOT cached sop it takes 30-60sec to downlaod which is not ideal.
- name: gcr.io/k8s-skaffold/skaffold:v1.37.2-lts
id: SkaffoldBuildUsingCache
waitFor:
- PullCache
args:
- "skaffold"
- "build"
- "--file-output=/workspace/artifacts.json"
- "--default-repo=${_REGION}-docker.pkg.dev/$PROJECT_ID/$_ARTIFACT_REPONAME"
- "--cache-file=/workspace/cache"
- "--module=$_DEPLOY_UNIT"
- name: gcr.io/cloud-builders/gsutil
id: PushCacheToGCS
waitFor:
- SkaffoldBuildUsingCache
args: ['cp', '/workspace/cache', 'gs://$PROJECT_ID-skaffoldcache/skaffold-cache/$_DEPLOY_UNIT.txt']
#############################################################################
# Note: This works perfectly and deploys to CD without version name. To have version name you need bash.
# Commenting it out now since it consumes time and resources (and delays everything by 30+ sec) but feel free
# to uncomment at any time.
# Thanks to abielski and Ed Thiele!! Remove previous when this works of course
# https://cloud.google.com/build/docs/configuring-builds/run-bash-scripts#running_inline_bash_scripts
#############################################################################
# - name: gcr.io/cloud-builders/gcloud
# - id: PushToCloudDeployWithVersion
# args:
# - "deploy"
# - "releases"
# - "create"
# - "$_DEPLOY_UNIT-$$DATE-$$TIME-ohne-version" # tip from Edward: this is more human readable
# # - "$_DEPLOY_UNIT-$$DATE-$$TIME" # tip from Edward: this is more human readable
# # - "$_DEPLOY_UNIT-$SHORT_SHA" # This is better in PROD, but if you dont do a new git commit it will fail
# - "--delivery-pipeline=$_DEPLOY_UNIT"
# - "--build-artifacts=/workspace/artifacts.json"
# - "--skaffold-file=apps/$_DEPLOY_UNIT/skaffold.yaml"
# - "--region=${_DEPLOY_REGION}"
#############################################################################
# This instead is the MAGIC one which gives a VERSION file dependant name to the release
#############################################################################
- name: gcr.io/cloud-builders/gcloud
id: PushToCloudDeployDEVWithVersion # needs bash
waitFor:
- PushCacheToGCS
dir: /workspace/
entrypoint: bash
# copied from https://cloud.google.com/build/docs/configuring-builds/substitute-variable-values
env:
- FOO=bar
- 'CBENV_BUILD_ID=$BUILD_ID'
- 'PROJECT_ID=$PROJECT_ID'
- 'REV=$REVISION_ID'
- 'CBENV_DATETIME1=$$DATE-$$TIME'
- "CBENV_DATETIME2=$$DATE-$$TIME"
- RELEASE_FILE_PATH=/workspace/.cb.releasename
args:
- '-c'
- cloud-build/01-on-commit-build.sh "$_DEPLOY_UNIT" "$_DEPLOY_REGION" 'dt1-$$DATE-$$TIME' "dt2-$$DATE-$$TIME"
## Also consider using Ubuntu for ENV: https://cloud.google.com/build/docs/configuring-builds/substitute-variable-values
# steps:
# # Uses the ubuntu build step:
# # to run a shell script; and
# # set env variables for its execution
# - name: 'ubuntu'
# args: ['bash', './myscript.sh']
#-
- name: gcr.io/google.com/cloudsdktool/cloud-sdk
id: IfTestPassPushToCloudDeployStaging
waitFor:
- PushToCloudDeployDEVWithVersion
dir: /workspace/
entrypoint: bash
env:
- FOO=bar
- 'CBENV_BUILD_ID=$BUILD_ID'
- 'PROJECT_ID=$PROJECT_ID'
- 'REV=$REVISION_ID'
- 'CBENV_DATETIME1=$$DATE-$$TIME'
- "CBENV_DATETIME2=$$DATE-$$TIME"
- RELEASE_FILE_PATH=/workspace/.cb.releasename
- "ARTIFACT_REPONAME=$_ARTIFACT_REPONAME"
args:
- '-c'
- cloud-build/02-dev-to-staging-auto-promo.sh "$_DEPLOY_UNIT" "$_DEPLOY_REGION" "$_ARTIFACT_REPONAME"
options:
# This allows for missing ENV variables.
substitution_option: 'ALLOW_LOOSE'