-
Notifications
You must be signed in to change notification settings - Fork 813
/
cloudbuild.yaml
421 lines (393 loc) · 13.3 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
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
---
# Copyright 2017 Google LLC All Rights Reserved.
#
# 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.
#
# Google Cloud Builder CI configuration
#
steps:
#
# Cancel the previous build for the same branch
#
- name: gcr.io/cloud-builders/gcloud-slim:latest
id: cancelot
entrypoint: bash
args: [./ci/cancelot.sh, --current_build_id, $BUILD_ID]
#
# Print Docker version
#
- name: gcr.io/cloud-builders/docker:24.0.6
id: docker-version
args: [--version]
#
# Restore any caches
#
- name: us-docker.pkg.dev/$PROJECT_ID/ci/restore_cache
id: htmltest-restore-cache
args: [--bucket=gs://$_CACHE_BUCKET, --key=$_HTMLTEST_CACHE_KEY]
waitFor: ['-']
- name: us-docker.pkg.dev/$PROJECT_ID/ci/restore_cache
id: cpp-sdk-build-restore-cache
args:
- --bucket=gs://$_CACHE_BUCKET
- --key=$_CPP_SDK_BUILD_CACHE_KEY-$( checksum sdks/cpp/CMakeLists.txt )
waitFor: ['-']
- name: us-docker.pkg.dev/$PROJECT_ID/ci/restore_cache
id: cpp-sdk-conformance-restore-cache
args:
- --bucket=gs://$_CACHE_BUCKET
- --key=$_CPP_SDK_CONFORMANCE_CACHE_KEY-$( checksum sdks/cpp/CMakeLists.txt )
waitFor: ['-']
- name: us-docker.pkg.dev/$PROJECT_ID/ci/restore_cache
id: rust-sdk-build-restore-cache
args:
- --bucket=gs://$_CACHE_BUCKET
- --key=$_RUST_SDK_BUILD_CACHE_KEY-$( checksum test/sdk/rust/Cargo.toml )
waitFor: ['-']
#
# Creates the initial make + docker build platform
#
- name: ubuntu
args:
- bash
- -c
- "echo 'FROM gcr.io/cloud-builders/docker:24.0.6\nRUN apt-get install make\nENTRYPOINT\
\ [\"/usr/bin/make\"]' > Dockerfile.build"
waitFor: ['-']
- name: gcr.io/cloud-builders/docker:24.0.6
id: build-make-docker
args: [build, -f, Dockerfile.build, -t, make-docker, .] # we need docker and make to run everything.
#
# pull the main build image if it exists
#
- name: make-docker
id: pull-build-image
dir: build
env: ['REGISTRY=${_REGISTRY}']
args: [pull-build-image]
waitFor:
- build-make-docker
#
# pull the sdk base image, if it exists
#
- name: make-docker
id: pull-build-sdk-base-image
dir: build
env: ['REGISTRY=${_REGISTRY}']
args: [pull-build-sdk-base-image]
waitFor:
- build-make-docker
#
# Ensure that there is the sdk base image, so that both tests
# and build can use them
#
- name: make-docker
id: ensure-build-sdk-image-base
waitFor: [pull-build-sdk-base-image]
dir: build
args: [ensure-build-sdk-image-base]
#
# Preventing SDKs failure in CI
#
- name: make-docker
id: test-gen-all-sdk-grpc
waitFor: [ensure-build-sdk-image-base]
dir: build
args: [test-gen-all-sdk-grpc]
#
# Preventing Broken PR Merges in CI
#
- name: make-docker
id: test-gen-crd-code
waitFor: [pull-build-image]
dir: build
args: [test-gen-crd-code]
#
# Runs the linter -- but also builds the build image, if not able to download
#
- name: make-docker
id: lint
waitFor:
- pull-build-image
- test-gen-crd-code
- test-gen-all-sdk-grpc
dir: build
args: [lint] # pull the build image if it exists
#
# Push the build image, can run while we do other things.
#
- name: make-docker
waitFor: [lint]
dir: build
env: ['REGISTRY=${_REGISTRY}']
args: [push-build-image] # push the build image (which won't do anything if it's already there)
#
# Push the sdk base build image, which can also run while we do other things
#
- name: make-docker
waitFor: [ensure-build-sdk-image-base]
dir: build
env: ['REGISTRY=${_REGISTRY}']
args: [push-build-sdk-base-image]
#
# Build all the images and sdks, and push them up to the repository
#
- name: make-docker
id: build-images
waitFor: [lint]
dir: build
env: ['REGISTRY=${_REGISTRY}']
args: [-j, '4', build-images]
- name: make-docker
id: push-images
waitFor: [build-images]
dir: build
env: ['REGISTRY=${_REGISTRY}']
args: [-j, '4', push]
- name: make-docker
id: build-sdks
waitFor:
- lint
- cpp-sdk-build-restore-cache
- ensure-build-sdk-image-base
dir: build
args: [-j, '4', --output-sync=recurse, build-sdks]
#
# Example version checks
#
- name: make-docker
id: check-example-versions
dir: build
args: [check-example-versions]
waitFor:
- push-images
#
# Run the all the automated tests (except e2e) in parallel
#
- name: make-docker
id: tests
waitFor:
- lint
- ensure-build-sdk-image-base
- htmltest-restore-cache
- build-sdks
dir: build
args: [-j, '5', --output-sync=target, test]
#
# SDK conformance tests
#
- name: make-docker
id: sdk-conformance
dir: build
env: ['REGISTRY=${_REGISTRY}']
args: [-j, '5', --output-sync=target, run-sdk-conformance-tests]
waitFor:
- build-images
- tests
#
# Site preview
#
- name: make-docker # build a preview of the website
id: site-static
waitFor: [tests]
dir: build
args: [site-static-preview, site-gen-app-yaml, SERVICE=preview]
# deploy the preview of the website; # don't promote, as it can cause failures
# when two deploys try and promote at the same time.
- name: gcr.io/cloud-builders/gcloud
id: deploy-site-static
waitFor: [site-static]
dir: site
args: [app, deploy, .app.yaml, --no-promote, --version=$SHORT_SHA]
env:
- GOPATH=/workspace/go
- GO111MODULE=on
#
# End to end tests
#
# wait for us to be the oldest ongoing build before we run e2es
- name: gcr.io/cloud-builders/gcloud
id: e2e-wait-to-become-leader
waitFor: [push-images]
script: |
#!/usr/bin/env bash
TS='date --utc +%FT%TZ' # e.g. 2023-01-26T13:30:37Z
echo "$(${TS}): Waiting to become oldest running build"
while true; do
# Filter to running builds with tag 'ci', which covers any builds running e2es.
BUILD_FILTER="status=WORKING AND tags='ci'"
OLDEST=$(gcloud builds list --filter "${BUILD_FILTER}" --format="value(id,startTime)" --sort-by=startTime --limit=1)
echo "$(${TS}): Oldest is (id startTime): ${OLDEST}"
if echo ${OLDEST} | grep -q "${BUILD_ID}"; then
echo "$(${TS}): That's us, we're done!"
break
fi
sleep 60
done
timeout: 10800s # 3h - if you change this, change the global timeout as well
env:
- CLOUDSDK_CORE_PROJECT=$PROJECT_ID
- BUILD_ID=$BUILD_ID
- TRIGGER_NAME=$TRIGGER_NAME
# cancel all the orphan e2e test cloud builds, fail to cancel any of the build will fail this whole build
- name: gcr.io/cloud-builders/gcloud
id: cancel-orphan-e2e-tests
waitFor: [e2e-wait-to-become-leader]
script: |
#!/usr/bin/env bash
until gcloud builds list --ongoing --filter "tags:'e2e-test'" --format="value(id)" | xargs --no-run-if-empty gcloud builds cancel
do
echo "== encountered error; assuming retryable error and trying again =="
sleep 5
done
# kick off the child e2e test cloud builds in parallel, fail this build if any of the child build fails
- name: gcr.io/cloud-builders/gcloud
id: submit-e2e-test-cloud-build
entrypoint: bash
args:
- -c
- |
set -e
set -o pipefail
pids=()
cloudProducts=("generic" "gke-autopilot")
declare -A versionsAndRegions=( [1.29]=europe-west1 [1.30]=asia-east1 [1.31]=us-east1 )
# Keep in sync with (the inverse of) pkg/util/runtime/features.go:featureDefaults
featureWithGate="PlayerAllocationFilter=true&PlayerTracking=true&CountsAndLists=false&RollingUpdateFix=true&PortRanges=true&PortPolicyNone=true&ScheduledAutoscaler=true&DisableResyncOnSDKServer=false&AutopilotPassthroughPort=false&GKEAutopilotExtendedDurationPods=false&Example=true"
featureWithoutGate=""
# Use this if specific feature gates can only be supported on specific Kubernetes versions.
declare -A featureWithGateByVersion=( [1.29]="${featureWithGate}" [1.30]="${featureWithGate}" [1.31]="${featureWithGate}")
for cloudProduct in ${cloudProducts[@]}
do
for version in "${!versionsAndRegions[@]}"
do
withGate=${featureWithGateByVersion[$version]}
region=${versionsAndRegions[$version]}
if [ $cloudProduct = generic ]
then
testCluster="standard-e2e-test-cluster-${version//./-}"
else
testCluster="gke-autopilot-e2e-test-cluster-${version//./-}"
fi
testClusterLocation="${region}"
{ stdbuf -oL -eL gcloud builds submit . --suppress-logs --config=./ci/e2e-test-cloudbuild.yaml \
--substitutions _FEATURE_WITH_GATE=$withGate,_FEATURE_WITHOUT_GATE=$featureWithoutGate,_CLOUD_PRODUCT=$cloudProduct,_TEST_CLUSTER_NAME=$testCluster,_TEST_CLUSTER_LOCATION=$testClusterLocation,_REGISTRY=${_REGISTRY},_PARENT_COMMIT_SHA=${COMMIT_SHA},_PARENT_BUILD_ID=${BUILD_ID} \
|& stdbuf -i0 -oL -eL grep -v " tarball " \
|& stdbuf -i0 -oL -eL sed "s/^/${cloudProduct}-${version}: /"; } &
pids+=($!)
done
done
# If any of the subprocess exit with nonzero code, exit the main process and kill all subprocesses
for pid in "${pids[@]}"; do
if wait -n; then
:
else
status=$?
echo "One of the e2e test child cloud build exited with nonzero status $status. Aborting."
for pid in "${pids[@]}"; do
# Send a termination signal to all the children, and ignore errors
# due to children that no longer exist.
kill "$pid" 2> /dev/null || :
echo "killed $pid"
done
exit "$status"
fi
done
echo "all done"
waitFor:
- cancel-orphan-e2e-tests
#
# Store caches, to speed up subsequent builds (considerably)
#
- name: us-docker.pkg.dev/$PROJECT_ID/ci/save_cache
args:
- --bucket=gs://$_CACHE_BUCKET
- --key=$_CPP_SDK_BUILD_CACHE_KEY-$( checksum sdks/cpp/CMakeLists.txt )
- --path=sdks/cpp/.build # CPP SDK build
id: cpp-sdk-build-save-cache
waitFor:
- build-sdks
- name: us-docker.pkg.dev/$PROJECT_ID/ci/save_cache
args:
- --bucket=gs://$_CACHE_BUCKET
- --key=$_CPP_SDK_CONFORMANCE_CACHE_KEY-$( sdks/cpp/CMakeLists.txt )
- --path=test/sdk/cpp/sdk # CPP conformance test build
id: cpp-sdk-conformance-save-cache
waitFor:
- sdk-conformance
- name: us-docker.pkg.dev/$PROJECT_ID/ci/save_cache
args:
- --bucket=gs://$_CACHE_BUCKET
- --key=$_RUST_SDK_BUILD_CACHE_KEY-$( checksum test/sdk/rust/Cargo.toml )
- --path=test/sdk/rust/.cargo # Rust conformance test build
- --path=test/sdk/rust/.cargo-targets
- --no-clobber
id: rust-build-save-cache
waitFor:
- sdk-conformance
- name: us-docker.pkg.dev/$PROJECT_ID/ci/save_cache
args:
- --bucket=gs://$_CACHE_BUCKET
- --key=$_HTMLTEST_CACHE_KEY
- --path=site/tmp # htmltest URL checks
id: htmltest-save-cache
waitFor:
- tests
#
# Zip up artifacts and push to storage
#
- name: gcr.io/cloud-builders/gsutil
waitFor: [build-sdks, tests]
dir: sdks/cpp/.archives
args: [-m, cp, '*.tar.gz', gs://agones-artifacts/cpp-sdk]
- name: gcr.io/cloud-builders/gsutil
waitFor: [build-images, tests]
dir: cmd/sdk-server/bin
args: [-m, cp, '*.zip', gs://agones-artifacts/sdk-server]
#
# Cleanup services "preview", "development", "default"
#
- name: gcr.io/cloud-builders/gcloud
id: cleanup-services
waitFor: [e2e-wait-to-become-leader]
allowFailure: true
entrypoint: bash
args:
- -c
- |
set -e
set -o pipefail
for service in preview development default; do
echo "Cleaning up $service service..."
gcloud app versions list --service=$service --filter="traffic_split<1" --sort-by=~last_deployed_time.datetime --format="table[no-heading](version.id)" | tail -n +50 | xargs --no-run-if-empty gcloud app versions delete --service=$service --quiet
done
substitutions:
_CACHE_BUCKET: agones-build-cache
_HTMLTEST_CACHE_KEY: htmltest-0.10.1
_CPP_SDK_BUILD_CACHE_KEY: cpp-sdk-build
_CPP_SDK_CONFORMANCE_CACHE_KEY: cpp-sdk-conformance
_RUST_SDK_BUILD_CACHE_KEY: rust-sdk-build
_REGISTRY: us-docker.pkg.dev/${PROJECT_ID}/ci
tags: [ci, 'commit-${COMMIT_SHA}']
timeout: 18000s # 5h: 3h (e2e-wait-to-become-leader) + 1.5h (e2e timeout) + 0.5h (everything else)
queueTtl: 259200s # 72h
images:
- ${_REGISTRY}/agones-controller
- ${_REGISTRY}/agones-extensions
- ${_REGISTRY}/agones-sdk
- ${_REGISTRY}/agones-ping
- ${_REGISTRY}/agones-allocator
logsBucket: gs://agones-build-logs
options:
machineType: E2_HIGHCPU_32
dynamic_substitutions: true