forked from GoogleCloudPlatform/marketplace-k8s-app-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cloudbuild.yaml
237 lines (220 loc) · 7.26 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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
# This cloudbuild.yaml config file is triggered in two contexts:
#
#
# Trigger #1: Before master merge
#
# GoogleCloudPlatform/marketplace-k8s-app-tools push to any branch
# https://console.cloud.google.com/cloud-build/triggers?project=marketplace-k8s-app-tools
#
# This build trigger asserts the invariant that the source code can
# be built and pushed into a repository. Its success blocks pull
# request. gcr.io/marketplace-k8s-app-tools read access restricted.
#
#
# Trigger #2: After master merge
#
# GoogleCloudPlatform/marketplace-k8s-app-tools push to master branch
# https://console.cloud.google.com/cloud-build/triggers?project=cloud-marketplace-tools
#
# This build trigger asserts the invariant that each commit on the master
# branch of GoogleCloudPlatform/marketplace-k8s-app-tools will be built
# and tagged in gcr.io/cloud-marketplace-tools/k8s.
# The following variables will be provided by Cloud Build.
#
# $PROJECT_ID: build.ProjectId
# $BUILD_ID: build.BuildId
# $COMMIT_SHA: build.SourceProvenance.ResolvedRepoSource.Revision.CommitSha
# $SHORT_SHA : The first seven characters of COMMIT_SHA
# $REPO_NAME: build.Source.RepoSource.RepoName (only available for triggered builds)
# $BRANCH_NAME: build.Source.RepoSource.Revision.BranchName (only available for triggered builds)
# $TAG_NAME: build.Source.RepoSource.Revision.TagName (only available for triggered builds)
# $REVISION_ID: build.SourceProvenance.ResolvedRepoSource.Revision.CommitSha (only available for triggered builds)
#
# Source: https://cloud.google.com/cloud-build/docs/configuring-builds/substitute-variable-values
timeout: 1200s # 20m
options:
machineType: 'N1_HIGHCPU_8'
substitutions:
_CLUSTER_LOCATION: null
steps:
- id: &BuildDev Build dev
name: gcr.io/cloud-builders/docker
waitFor:
- '-'
args:
- build
- --tag
- gcr.io/$PROJECT_ID/k8s/dev:sha_$COMMIT_SHA
- --tag
- gcr.io/$PROJECT_ID/k8s/dev:sha_$SHORT_SHA
- --file
- marketplace/dev/Dockerfile
- .
- id: &BuildEnvsubst Build deployer_envsubst
name: gcr.io/cloud-builders/docker
waitFor:
- '-'
args:
- build
- --tag
- gcr.io/$PROJECT_ID/k8s/deployer_envsubst:sha_$COMMIT_SHA
- --tag
- gcr.io/$PROJECT_ID/k8s/deployer_envsubst:sha_$SHORT_SHA
- --file
- marketplace/deployer_envsubst_base/Dockerfile
- .
- id: &BuildEnvsubstOnBuild Build deployer_envsubst onbuild
name: gcr.io/cloud-builders/docker
waitFor:
- *BuildEnvsubst
args:
- build
- --build-arg
- FROM=gcr.io/$PROJECT_ID/k8s/deployer_envsubst:sha_$COMMIT_SHA
- --tag
- gcr.io/$PROJECT_ID/k8s/deployer_envsubst/onbuild:sha_$COMMIT_SHA
- --tag
- gcr.io/$PROJECT_ID/k8s/deployer_envsubst/onbuild:sha_$SHORT_SHA
- --file
- marketplace/deployer_envsubst_base/onbuild/Dockerfile
- .
- id: &BuildHelm Build deployer_helm
name: gcr.io/cloud-builders/docker
waitFor:
- '-'
args:
- build
- --tag
- gcr.io/$PROJECT_ID/k8s/deployer_helm:sha_$COMMIT_SHA
- --tag
- gcr.io/$PROJECT_ID/k8s/deployer_helm:sha_$SHORT_SHA
- --file
- marketplace/deployer_helm_base/Dockerfile
- .
- id: &BuildHelmOnbuild Build deployer_helm onbuild
name: gcr.io/cloud-builders/docker
waitFor:
- *BuildHelm
args:
- build
- --build-arg
- FROM=gcr.io/$PROJECT_ID/k8s/deployer_helm:sha_$COMMIT_SHA
- --tag
- gcr.io/$PROJECT_ID/k8s/deployer_helm/onbuild:sha_$COMMIT_SHA
- --tag
- gcr.io/$PROJECT_ID/k8s/deployer_helm/onbuild:sha_$SHORT_SHA
- --file
- marketplace/deployer_helm_base/onbuild/Dockerfile
- .
- id: &BuildHelm2 Build deployer_helm2
name: gcr.io/cloud-builders/docker
waitFor:
- '-'
args:
- build
- --tag
- gcr.io/$PROJECT_ID/k8s/deployer_helm2:sha_$COMMIT_SHA
- --tag
- gcr.io/$PROJECT_ID/k8s/deployer_helm2:sha_$SHORT_SHA
- --file
- marketplace/deployer_helm2_base/Dockerfile
- .
- id: &BuildHelm2Onbuild Build deployer_helm2 onbuild
name: gcr.io/cloud-builders/docker
waitFor:
- *BuildHelm2
args:
- build
- --build-arg
- FROM=gcr.io/$PROJECT_ID/k8s/deployer_helm2:sha_$COMMIT_SHA
- --tag
- gcr.io/$PROJECT_ID/k8s/deployer_helm2/onbuild:sha_$COMMIT_SHA
- --tag
- gcr.io/$PROJECT_ID/k8s/deployer_helm2/onbuild:sha_$SHORT_SHA
- --file
- marketplace/deployer_helm2_base/onbuild/Dockerfile
- .
- id: &BuildMarketplaceIntegrationChart Build marketplace-integration Chart
name: gcr.io/$PROJECT_ID/k8s/dev:sha_$COMMIT_SHA
waitFor:
- *BuildDev
entrypoint: bash
args:
- -exc
- |
mkdir charts-tgz/
helm init --client-only
helm package marketplace/charts/marketplace-integration/ \
--version "0.0.0+sha.$COMMIT_SHA" \
--destination charts-tgz/
gsutil cp gs://$PROJECT_ID-charts/index.yaml index.yaml
helm repo index --merge index.yaml charts-tgz/
- id: &InitializeCredentials Initialize Credentials
name: gcr.io/cloud-builders/gcloud
waitFor:
- '-'
entrypoint: bash
args:
- -exc
- |
# Use the 'c-$BUILD_ID' as the cluster name as it must start with a letter,
# and have a max length of 40 chars (BUILD_ID is 37). Then install App CRD.
gcloud container clusters create 'c-$BUILD_ID' --zone '${_CLUSTER_LOCATION}' --project '$PROJECT_ID' --labels=creation-timestamp=`date +%s`
gcloud container clusters get-credentials 'c-$BUILD_ID' --zone '${_CLUSTER_LOCATION}' --project '$PROJECT_ID'
kubectl apply -f "https://raw.githubusercontent.com/GoogleCloudPlatform/marketplace-k8s-app-tools/$COMMIT_SHA/crd/app-crd.yaml"
mkdir -p /workspace/.kube/
cp -r $$HOME/.kube/ /workspace/
mkdir -p /workspace/.config/gcloud/
cp -r $$HOME/.config/gcloud/ /workspace/.config/
- id: &Verify Verify
name: gcr.io/$PROJECT_ID/k8s/dev:sha_$COMMIT_SHA
waitFor:
- *InitializeCredentials
- *BuildDev
- *BuildEnvsubst
- *BuildEnvsubstOnBuild
- *BuildHelm
- *BuildHelmOnbuild
- *BuildHelm2
- *BuildHelm2Onbuild
env:
- 'KUBE_CONFIG=/workspace/.kube'
- 'GCLOUD_CONFIG=/workspace/.config/gcloud'
# Use local Docker network named cloudbuild as described here:
# https://cloud.google.com/cloud-build/docs/overview#build_configuration_and_build_steps
- 'EXTRA_DOCKER_PARAMS=--net cloudbuild'
- MARKETPLACE_TOOLS_TAG=testing-sha_$COMMIT_SHA
args:
- make
- -j10
- --output-sync
- tests/integration
- id: Cleanup
name: gcr.io/cloud-builders/gcloud
waitFor:
- *Verify
entrypoint: bash
args:
- -exc
- |
gcloud container clusters delete 'c-$BUILD_ID' --zone '${_CLUSTER_LOCATION}' --project '$PROJECT_ID' --quiet
images:
- gcr.io/$PROJECT_ID/k8s/dev:sha_$COMMIT_SHA
- gcr.io/$PROJECT_ID/k8s/dev:sha_$SHORT_SHA
- gcr.io/$PROJECT_ID/k8s/deployer_envsubst:sha_$COMMIT_SHA
- gcr.io/$PROJECT_ID/k8s/deployer_envsubst:sha_$SHORT_SHA
- gcr.io/$PROJECT_ID/k8s/deployer_envsubst/onbuild:sha_$COMMIT_SHA
- gcr.io/$PROJECT_ID/k8s/deployer_envsubst/onbuild:sha_$SHORT_SHA
- gcr.io/$PROJECT_ID/k8s/deployer_helm:sha_$COMMIT_SHA
- gcr.io/$PROJECT_ID/k8s/deployer_helm:sha_$SHORT_SHA
- gcr.io/$PROJECT_ID/k8s/deployer_helm/onbuild:sha_$COMMIT_SHA
- gcr.io/$PROJECT_ID/k8s/deployer_helm/onbuild:sha_$SHORT_SHA
- gcr.io/$PROJECT_ID/k8s/deployer_helm2:sha_$COMMIT_SHA
- gcr.io/$PROJECT_ID/k8s/deployer_helm2:sha_$SHORT_SHA
- gcr.io/$PROJECT_ID/k8s/deployer_helm2/onbuild:sha_$COMMIT_SHA
- gcr.io/$PROJECT_ID/k8s/deployer_helm2/onbuild:sha_$SHORT_SHA
artifacts:
objects:
location: gs://$PROJECT_ID-charts/
paths:
- charts-tgz/*