-
Notifications
You must be signed in to change notification settings - Fork 21
/
cloudbuild.yaml
159 lines (142 loc) · 4.98 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
# Copyright 2023 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.
# timeout needs to be longer than the total run time, with some padding to allow
# enough time to gracefully tear down resources. Otherwise if Cloud Build aborts
# a build in the middle of Packer or Terraform GCP resources will be left behind.
timeout: 18000s # 5h
substitutions:
_REGION: ${LOCATION}
_ZONE: ${LOCATION}-a
_NETWORK: projects/${PROJECT_ID}/global/networks/default
_SUBNETWORK: projects/${PROJECT_ID}/regions/${_REGION}/subnetworks/default
_WORKER_POOL: ""
# This is to support running the various tests (e.g. smoke tests) with an
# existing image. Useful when developing the tests themselves.
# At the moment the image build step is unconditional, so you'll need to
# comment out the image build step while developing tests.
_IMAGE_NAME: nfs-test-${BUILD_ID}
options:
dynamicSubstitutions: true
pool:
name: ${_WORKER_POOL}
env:
- CI=cloudbuild
- PROJECT_ID=${PROJECT_ID}
- REGION=${_REGION}
- ZONE=${_ZONE}
- NETWORK=${_NETWORK}
- SUBNETWORK=${_SUBNETWORK}
- BUILD_ID=${BUILD_ID}
- IMAGE_NAME=${_IMAGE_NAME}
steps:
- name: golang:1.20
id: filter-exports:test
dir: image/resources/filter-exports
script: make test
waitFor: ['-']
timeout: 1200s # 20m
- name: golang:1.20
id: knfsd-agent:test
dir: image/resources/knfsd-agent
script: make test
waitFor: ['-']
timeout: 1200s # 20m
- name: golang:1.20
id: knfsd-metrics-agent:test
dir: image/resources/knfsd-metrics-agent
script: make test
waitFor: ['-']
timeout: 1200s # 20m
- name: golang:1.20
id: netapp-exports:test
dir: image/resources/netapp-exports
script: make test
waitFor: ['-']
timeout: 1200s # 20m
- name: golang:1.20
id: mig-scaler:test
dir: tools/mig-scaler
script: make test
waitFor: ['-']
timeout: 1200s # 20m
- name: gcr.io/cloud-builders/docker
id: knfsd-fsidd:database-up
dir: image/resources/knfsd-fsidd
script: ./test.sh up
waitFor: ['-']
timeout: 1200s # 20m
- name: golang:1.20
id: knfsd-fsidd:test
dir: image/resources/knfsd-fsidd
script: ./test.sh run
waitFor: ['knfsd-fsidd:database-up']
timeout: 1200s # 20m
- name: gcr.io/cloud-builders/docker
id: knfsd-fsidd:database-down
dir: image/resources/knfsd-fsidd
script: ./test.sh down
waitFor: ['knfsd-fsidd:test']
timeout: 1200s # 20m
# For a production build you would want to set an image_family, and use a more
# readable image_name (if you leave image_name blank packer will default it to
# "{image_family}-{timestamp}").
# Using BUILD_ID for test images to easily associate a test image with a
# specific build. Though this isn't very useful in normal use as BUILD_ID is
# just a random UUID.
# Not using an image_family for the test builds, as you wouldn't want to
# deploy the latest test build. It might be the latest main or the latest pull
# request, who knows?
# If you wanted to run these tests yourself as part of CI/CD before releasing
# an image for general use, to avoid building the image twice, once the tests
# are complete you could copy the image to a proper image_family and more
# usable name (such as using a timestamp or version tag).
- name: hashicorp/packer:1.9
id: knfsd-image:build
script: |
packer init image &&
packer build \
-var-file=image/cloudbuild.pkrvars.hcl \
-var project=${PROJECT_ID} \
-var zone=${ZONE} \
-var build_instance_name=nfs-build-${BUILD_ID} \
-var image_family="" \
-var image_name=${IMAGE_NAME} \
-var subnetwork=${SUBNETWORK} \
image
timeout: 7200s # 2h
- name: ${_DOCKER_REPOSITORY}/knfsd-terratest:1.0
id: knfsd-image:test
dir: image/smoke-tests
script: make test
env:
- TF_VAR_project=${PROJECT_ID}
- TF_VAR_region=${_REGION}
- TF_VAR_zone=${_ZONE}
- TF_VAR_network=${_NETWORK}
- TF_VAR_subnetwork=${_SUBNETWORK}
- TF_VAR_proxy_image=${_IMAGE_NAME}
timeout: 3600s # 1h
- name: ${_DOCKER_REPOSITORY}/knfsd-terratest:1.0
id: examples:tests
dir: testing/examples
script: make test
env:
- TF_VAR_project=${PROJECT_ID}
- TF_VAR_region=${_REGION}
- TF_VAR_zone=${_ZONE}
- TF_VAR_network=${_NETWORK}
- TF_VAR_subnetwork=${_SUBNETWORK}
- TF_VAR_proxy_image=${_IMAGE_NAME}
- TF_VAR_proxy_service_account=${_PROXY_SERVICE_ACCOUNT}
timeout: 3600s # 1h