-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcloudbuild.yaml
210 lines (190 loc) · 6.37 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
# Copyright 2020 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.
---
steps:
################################
# Steps for Dataproc Hub Example
################################
- id: 'manage_context'
name: gcr.io/cloud-builders/git
entrypoint: 'bash'
args:
- '-c'
- |
if [ -z "$COMMIT_SHA" ]; then
echo "COMMIT_SHA is empty, uses the subsitition _BUILD_FOLDERS instead."
IFS=$_BUILD_FOLDERS_SEP read -r -a folders <<< "$_BUILD_FOLDERS"
for fld in "${folders[@]}"
do
echo "$fld" >> /workspace/changed_dirs.txt
done
exit 0
fi
echo "***********************"
echo "Branch: $BRANCH_NAME"
echo "Commit: $COMMIT_SHA"
echo "***********************"
# Saves list of dirs changed by this commit.
git diff --no-commit-id --dirstat -r $COMMIT_SHA --output /workspace/changed_dirs.txt
# Steps for Dataproc Custom Image
- id: 'build_dataproc_custom_image'
name: 'gcr.io/$PROJECT_ID/dataproc-custom-image'
entrypoint: 'bash'
env:
- 'CUSTOM_IMAGE_NAME=${_DCI_CUSTOM_IMAGE_NAME}'
- 'DATAPROC_VERSION=$_DCI_DATAPROC_VERSION'
- 'BASE_IMAGE_URI=$_DCI_BASE_IMAGE_URI'
- 'CUSTOMIZATION_SCRIPT_PATH=$_DCI_CUSTOMIZATION_SCRIPT_PATH'
- 'ZONE=$_DCI_ZONE'
- 'GCS_LOGS=$_DCI_GCS_LOGS'
- 'FAMILY=$_DCI_FAMILY'
- 'PROJECT_ID=$PROJECT_ID'
- 'OAUTH=$_DCI_OAUTH'
- 'MACHINE_TYPE=$_DCI_MACHINE_TYPE'
- 'NO_SMOKE_TEST=$_DCI_NO_SMOKE_TEST'
- 'NETWORK=$_DCI_NETWORK'
- 'SUBNETWORK=$_DCI_SUBNETWORK'
- 'NO_EXTERNAL_IP=$_DCI_NO_EXTERNAL_IP'
- 'SERVICE_ACCOUNT=$_DCI_SERVICE_ACCOUNT'
- 'EXTRA_SOURCES=$_DCI_EXTRA_SOURCES'
- 'DISK_SIZE=$_DCI_DISK_SIZE'
- 'ACCELERATOR=$_DCI_ACCELERATOR'
- 'BASE_IMAGE_URI=$_DCI_BASE_IMAGE_URI'
- 'STORAGE_LOCATION=$_DCI_STORAGE_LOCATION'
- 'SHUTDOWN_INSTANCE_TIMER_SEC=$_DCI_SHUTDOWN_INSTANCE_TIMER_SEC'
- 'DRY_RUN=$_DCI_DRY_RUN'
args:
- '-c'
- |
grep ${_FOLDER_DATAPROCHUB}/dataproc-custom-image-builder/ "/workspace/changed_dirs.txt" || exit 0
echo "Building dataproc-custom-image-builder..."
chmod +x /usr/local/bin/dataproc-custom-image.sh
bash /usr/local/bin/dataproc-custom-image.sh
# Steps for DataprocHub
- id: 'build_dataprochub'
name: 'gcr.io/cloud-builders/docker'
waitFor:
- build_dataproc_custom_image
entrypoint: 'bash'
args:
- '-c'
- |
working_dir=${_FOLDER_DATAPROCHUB}/dataprochub-builder/
grep "${working_dir}" "/workspace/changed_dirs.txt" || exit 0
echo "Building dataprochub-builder..."
docker build --network=cloudbuild \
-t gcr.io/$PROJECT_ID/$_DHB_BASE_IMAGE:$_DHB_TAG \
${working_dir}
- id: 'refresh_instance_group'
name: 'gcr.io/cloud-builders/gcloud'
entrypoint: 'bash'
args:
- '-c'
- |
grep ${_FOLDER_DATAPROCHUB}/dataprochub-builder/ "/workspace/changed_dirs.txt" || exit 0
if [ ! "$_DHB_UPDATE_MIG" = true ] ; then
echo 'Not performing a rolling update.'
exit 0
fi
gcloud compute instance-groups managed rolling-action replace ${_DHB_MIG_NAME} \
--region ${_DHB_REGION} \
--project ${PROJECT_ID} \
--quiet || echo "Managed instance group ${_DHB_MIG_NAME} does not exist"
# Steps for MIG Infrastructure done by Terraform
- id: 'terraform-init'
name: 'hashicorp/terraform:$_MIG_TERRAFORM_VERSION'
entrypoint: 'sh'
args:
- '-c'
- |
working_dir=${_FOLDER_DATAPROCHUB}/infrastructure-builder/mig/
grep ${working_dir} "/workspace/changed_dirs.txt" || exit 0
cd ${working_dir}
echo "--------- cat ---------"
ls
echo "--------- cat ---------"
terraform init -backend-config=bucket=${_MIG_TERRAFORM_STATE_BUCKET}
- id: 'terraform-refresh'
name: 'hashicorp/terraform:${_MIG_TERRAFORM_VERSION}'
entrypoint: 'sh'
args:
- '-c'
- |
working_dir=${_FOLDER_DATAPROCHUB}/infrastructure-builder/mig/
grep ${working_dir} "/workspace/changed_dirs.txt" || exit 0
cd ${working_dir}
terraform refresh -state=${_MIG_TERRAFORM_STATE_BUCKET}/terraform/state/default.tfstate
- id: 'terraform-rm-jupyterhub-mig-template'
name: 'hashicorp/terraform:${_MIG_TERRAFORM_VERSION}'
env:
- "TF_VAR_project-name=${PROJECT_ID}"
entrypoint: 'sh'
args:
- '-c'
- |
working_dir=${_FOLDER_DATAPROCHUB}/infrastructure-builder/mig/
grep ${working_dir} "/workspace/changed_dirs.txt" || exit 0
cd ${working_dir}
terraform state rm module.jupyterhub_mig_template
- id: 'terraform-plan'
name: 'hashicorp/terraform:${_MIG_TERRAFORM_VERSION}'
env:
- "TF_VAR_project-name=${PROJECT_ID}"
entrypoint: 'sh'
args:
- '-c'
- |
working_dir=${_FOLDER_DATAPROCHUB}/infrastructure-builder/mig/
grep ${working_dir} "/workspace/changed_dirs.txt" || exit 0
cd ${working_dir}
terraform plan
- id: 'terraform-apply'
name: 'hashicorp/terraform:${_MIG_TERRAFORM_VERSION}'
env:
- "TF_VAR_project-name=${PROJECT_ID}"
entrypoint: 'sh'
args:
- '-c'
- |
working_dir=${_FOLDER_DATAPROCHUB}/infrastructure-builder/mig/
grep ${working_dir} "/workspace/changed_dirs.txt" || exit 0
cd ${working_dir}
terraform apply -auto-approve
#
# Steps for GKE Hub Example
#
# TODO
#
# Substitutions if using trigger and not cloudbuild_manual.yaml
# TODO(developer): Sets the relevant options.
#
# substitutions:
# _FOLDER_DATAPROCHUB: dataproc-hub-example/build/
# _PREFIX_GKE_HUB_EXAMPLE: gke-hub-example/build/
# _DCI_CUSTOM_IMAGE_PREFIX: dataprochub-dataproc-base
# _DCI_DATAPROC_VERSION: 1.4.16-debian9
# _DCI_ZONE: us-central1-a
# _DCI_CUSTOMIZATION_SCRIPT_PATH: dataproc-hub-example/build/dataproc-custom-image-builder/customization-script.sh
# _DCI_GCS_LOGS: ${GCS_DATAPROC_CUSTOM_IMAGES}/logs
# _DCI_DISK_SIZE: 100
# _DHB_UPDATE_MIG: false
# _DHB_BASE_IMAGE: dataprochub
# _DHB_TAG: latest
# _DHB_MIG_NAME: jupyterhub-mig
# _DHB_REGION: europe-west1
# _MIG_TERRAFORM_VERSION: 0.12.24
# _MIG_TERRAFORM_STATE_BUCKET: ${GCS_TFSTATE}
options:
# Required for dataproc_custom_image
substitution_option: 'ALLOW_LOOSE'