-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathcloudbuild.yaml
100 lines (89 loc) · 3.21 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
steps:
- id: Lock
name: golang:1.23.0
entrypoint: bash
args:
- -ec
- |
if [[ "$COMMIT_SHA" = '' ]]; then
echo "no COMMIT_SHA, not locking"
exit 0
fi
go run golang.org/x/website/cmd/locktrigger@latest \
-project $PROJECT_ID -build $BUILD_ID -repo https://go.googlesource.com/oscar
- id: CheckEnv
name: bash
args:
- -ec
- |
if [[ "$SHORT_SHA" = '' ]]; then
echo >&2 "missing SHORT_SHA; use --substitutions on command line"
exit 1
fi
if [[ ! ${_ENV} =~ ^(devel|prod)$ ]]; then
echo >&2 "_ENV must be one of: devel, prod'"
exit 1
fi
if [[ ! ${_ENABLE_SYNC} =~ ^(true|false)$ ]]; then
echo >&2 "_ENABLE_SYNC must be one of: true, false'"
exit 1
fi
if [[ ! ${_ENABLE_CHANGES} =~ ^(true|false)$ ]]; then
echo >&2 "_ENABLE_CHANGES must be one of: true, false'"
exit 1
fi
- id: Test
name: golang:1.23.0
entrypoint: bash
args:
- -ec
# Run tests for all submodules.
- find . -name go.mod -execdir go test ./... \;
- id: Build
name: gcr.io/cloud-builders/docker
entrypoint: bash
args:
- -ec
- |
env=${_ENV}
tag=$env-$(date +%Y%m%dt%H%M%S)-$SHORT_SHA
image=gcr.io/${PROJECT_ID}/gaby:$tag
firestore_db=$env
enable_sync=${_ENABLE_SYNC}
enable_changes=${_ENABLE_CHANGES}
# Convert the commented runsc config files to valid json.
sed '/^[ \t]*#/d' internal/bisect/bisect_config.json.commented > internal/bisect/bisect_config.json
sed '/^[ \t]*#/d' internal/sandbox/config.json.commented > internal/sandbox/config.json
echo "building image $image with firestore_db $firestore_db (enable_sync=$enable_sync, enable_changes=$enable_changes)"
docker build -t $image \
--build-arg FIRESTORE_DB="$firestore_db" \
--build-arg ENABLE_SYNC="$enable_sync" \
--build-arg ENABLE_CHANGES="$enable_changes" \
-f internal/gaby/Dockerfile .
docker push $image
# Save image name for later steps.
echo $image > /workspace/image-$env.txt
- id: Deploy
name: gcr.io/cloud-builders/gcloud
entrypoint: bash
args:
- -ec
- |
env=${_ENV}
image=$(cat /workspace/image-$env.txt)
service=gaby-$env
echo "deploying service $service from image $image"
# Use second generation of the execution environment
# to run gvisor (runsc).
# TODO(hyangah): when enabling bisects, increase memory and cpu to match
# what is specified in deploy-cloud-run.sh (--memory 32G --cpu 8)
gcloud run deploy --project $PROJECT_ID $service --image $image --region us-central1 \
--memory 4G --execution-environment gen2
# If there was a rollback, `gcloud run deploy` will create a revision
# but not point traffic to it. The following command ensures that the
# new revision will get traffic.
gcloud run services update-traffic $service --to-latest --region us-central1
substitutions:
_ENV: "devel"
_ENABLE_SYNC: "false"
_ENABLE_CHANGES: "false"