forked from gpii-ops/gpii-infra
-
Notifications
You must be signed in to change notification settings - Fork 0
/
.gitlab-ci.yml
319 lines (303 loc) · 9.41 KB
/
.gitlab-ci.yml
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
stages:
- setup
- lint
- unit-tests
- common-stg
- common-stg-test
- promote-common-to-prd
- common-prd
- dev
- plan-all-stg
- promote-to-stg
- stg
- plan-all-prd
- promote-to-prd
- prd
common-setup:
stage: setup
tags:
- common
script:
- terraform -version
- terragrunt -version
- docker version
- docker-compose version
- docker images | grep exekube
- ruby --version
- bundle version
- rake --version
only:
- master@gpii-ops/gpii-infra
gcp-setup:
stage: setup
tags:
- gcp
script:
- docker version
- docker-compose version
- docker images | grep exekube
- ruby --version
- bundle version
- rake --version
only:
- master@gpii-ops/gpii-infra
terraform-fmt-check:
stage: lint
tags:
- common
script:
- docker run --rm -v "$(pwd):/data" -w /data gcr.io/gpii-common-prd/gpii__exekube:0.9.11-google_gpii.0 -- terraform fmt --check=true
only:
- master@gpii-ops/gpii-infra
gcp-unit-tests:
stage: unit-tests
tags:
- gcp
script:
- docker run --rm -v "$(pwd):/data" -w /data/shared/rakefiles/tests gcr.io/gpii-common-prd/gpii__exekube:0.9.11-google_gpii.0 -- sh -c "bundle install --with test && rake"
only:
- master@gpii-ops/gpii-infra
common-stg:
stage: common-stg
tags:
- common
script:
- cd common/live/stg
- rake clobber
- rake configure_serviceaccount_ci_restore
- rake apply_common_infra
- rake init_registry
- rake apply_infra
after_script:
- cd common/live/stg
- rake destroy_sa_keys
environment:
name: stg
only:
- master@gpii-ops/gpii-infra
common-stg-test-gcp-dev:
stage: common-stg-test
tags:
- common
variables:
# These variables are duplicated in common/live/stg/Rakefile
ORGANIZATION_ID: "327626828918"
TF_VAR_organization_name: "gpii2test"
TF_VAR_organization_domain: "test.gpii.net"
TF_VAR_common_project_id: "gpii2test-common-stg"
# We override default infra region for dev environments
# due to GCP resource exhaustion issues:
# https://issues.gpii.net/browse/GPII-3697
TF_VAR_infra_region: "us-east4"
USER: "doe"
# Normally we don't enforce binauth in dev environments, e.g. since it makes
# it harder for developers to test custom images which they can't upload to
# GCR. However, we want to know as early as possible if a developer
# introduced a new image that will fail in environments like stg and prd
# with binauth enforcement enabled. So, we override the setting for CI dev
# envs.
TF_VAR_binary_authorization_evaluation_mode: "ALWAYS_DENY"
script:
- cd gcp/live/dev
- rake clobber
- rake configure_serviceaccount_ci_restore
- rake destroy_hard_and_deploy_ci
after_script:
- cd gcp/live/dev
# Remove all SA keys except current one to prevent hitting 10 keys per SA limit (GPII-3299)
- rake destroy_sa_keys || true
- rake clobber || true
only:
- master@gpii-ops/gpii-infra
common-promote-common-to-prd:
stage: promote-common-to-prd
tags:
- common
script:
- export DATESTAMP="$(date -u '+%Y%m%d%H%M%S')" # e.g. 20170603220542. Uses UTC.
- echo "DATESTAMP is $DATESTAMP" # So it's visible in the log
- git tag "deploy-common-stg-$DATESTAMP"
# gitlab is not clever enough to clean up an added remote and git complains
# if we add a remote that already exists.
- git remote | grep -q "^origin-rw" || git remote add origin-rw [email protected]:gpii-ops/gpii-infra
- git push --tags origin-rw
when: manual
allow_failure: false
only:
- master@gpii-ops/gpii-infra
common-prd:
stage: common-prd
tags:
- common
variables:
RAKE_REALLY_RUN_IN_PRD: "true"
script:
- cd common/live/prd
- rake clobber
- rake configure_serviceaccount_ci_restore
- rake apply_common_infra
- rake init_registry
- rake apply_infra
after_script:
- cd common/live/prd
- rake destroy_sa_keys RAKE_REALLY_DESTROY_IN_PRD=true
environment:
name: prd
only:
- master@gpii-ops/gpii-infra
gcp-dev:
stage: dev
tags:
- gcp
variables:
# We override default infra region for dev environments
# due to GCP resource exhaustion issues:
# https://issues.gpii.net/browse/GPII-3697
TF_VAR_infra_region: "us-east1"
# Normally we don't enforce binauth in dev environments, e.g. since it makes
# it harder for developers to test custom images which they can't upload to
# GCR. However, we want to know as early as possible if a developer
# introduced a new image that will fail in environments like stg and prd
# with binauth enforcement enabled. So, we override the setting for CI dev
# envs.
TF_VAR_binary_authorization_evaluation_mode: "ALWAYS_DENY"
script:
- cd gcp/live/dev
- rake clobber
- rake configure_serviceaccount_ci_restore
- rake destroy_hard_and_deploy_ci
after_script:
- cd gcp/live/dev
# Remove all SA keys except current one to prevent hitting 10 keys per SA limit (GPII-3299)
- rake destroy_sa_keys || true
- rake clobber || true
only:
- master@gpii-ops/gpii-infra
gcp-plan-all-stg:
stage: plan-all-stg
tags:
- gcp
environment:
name: stg
script:
- cd gcp/live/stg
- rake clobber
- rake configure_serviceaccount_ci_restore
# Next step is required to restore local tiller certs and prevent
# terraform from failing during helm_release.release status checks
- rake fetch_helm_certs
# Infra requires special treatment because of secrets configuration
- rake plain_sh['rake plan_infra'] || true
# Sync GKE Istio state so that the plan reflects real changes
- rake plain_sh['rake sync_gke_istio_state'] || true
- rake sh['xk plan-all live/stg/k8s 2> /dev/null'] || true
only:
- master@gpii-ops/gpii-infra
gcp-promote-to-stg:
stage: promote-to-stg
tags:
- gcp
script:
- export DATESTAMP="$(date -u '+%Y%m%d%H%M%S')" # e.g. 20170603220542. Uses UTC.
- echo "DATESTAMP is $DATESTAMP" # So it's visible in the log
- git tag "deploy-gcp-stg-$DATESTAMP"
# gitlab is not clever enough to clean up an added remote and git complains
# if we add a remote that already exists.
- git remote | grep -q "^origin-rw" || git remote add origin-rw [email protected]:gpii-ops/gpii-infra
- git push --tags origin-rw
only:
- master@gpii-ops/gpii-infra
gcp-stg:
stage: stg
tags:
- gcp
environment:
name: stg
script:
- cd gcp/live/stg
- rake clobber
- rake configure_serviceaccount_ci_restore
# Rotate Terraform state key and secrets KMS key to excercise secrets management
- rake rotate_tfstate_key
- rake rotate_secrets_key
- rake
- rake test_preferences_read
- rake test_flowmanager
- rake test_morphic_write
- rake test_morphic_read
after_script:
# Clean up even if something failed.
- cd gcp/live/stg
- rake display_cluster_state
- rake display_universal_image_info || true
# Remove all SA keys except current one to prevent hitting 10 keys per SA limit (GPII-3299)
- rake destroy_sa_keys || true
only:
- master@gpii-ops/gpii-infra
gcp-plan-all-prd:
stage: plan-all-prd
variables:
RAKE_REALLY_RUN_IN_PRD: "true"
tags:
- gcp
environment:
name: prd
script:
- cd gcp/live/prd
- rake clobber
- rake configure_serviceaccount_ci_restore
# Next step is required to restore local tiller certs and prevent
# terraform from failing during helm_release.release status checks
- rake fetch_helm_certs
# Infra requires special treatment because of secrets configuration
- rake plain_sh['rake plan_infra'] || true
# Sync GKE Istio state so that the plan reflects real changes
- rake plain_sh['rake sync_gke_istio_state'] || true
- rake sh['xk plan-all live/prd/k8s 2> /dev/null'] || true
only:
- master@gpii-ops/gpii-infra
gcp-promote-to-prd:
stage: promote-to-prd
tags:
- gcp
script:
- export DATESTAMP="$(date -u '+%Y%m%d%H%M%S')" # e.g. 20170603220542. Uses UTC.
- echo "DATESTAMP is $DATESTAMP" # So it's visible in the log
- git tag "deploy-gcp-prd-$DATESTAMP"
# gitlab is not clever enough to clean up an added remote and git complains
# if we add a remote that already exists.
- git remote | grep -q "^origin-rw" || git remote add origin-rw [email protected]:gpii-ops/gpii-infra
- git push --tags origin-rw
when: manual
allow_failure: false
only:
- master@gpii-ops/gpii-infra
gcp-prd:
stage: prd
variables:
RAKE_REALLY_RUN_IN_PRD: "true"
tags:
- gcp
environment:
name: prd
script:
- cd gcp/live/prd
- rake clobber
- rake configure_serviceaccount_ci_restore
# Rotate Terraform state key and secrets KMS key to exercise secrets management
- rake rotate_tfstate_key RAKE_REALLY_DESTROY_IN_PRD=true
- rake rotate_secrets_key RAKE_REALLY_DESTROY_IN_PRD=true
- rake
- rake test_preferences_read RAKE_REALLY_DESTROY_IN_PRD=true
- rake test_flowmanager RAKE_REALLY_DESTROY_IN_PRD=true
- rake test_morphic_write RAKE_REALLY_DESTROY_IN_PRD=true
- rake test_morphic_read RAKE_REALLY_DESTROY_IN_PRD=true
after_script:
# Clean up even if something failed.
- cd gcp/live/prd
- rake display_cluster_state
- rake display_universal_image_info || true
# Remove all SA keys except current one to prevent hitting 10 keys per SA limit (GPII-3299)
- rake destroy_sa_keys RAKE_REALLY_DESTROY_IN_PRD=true || true
only:
- master@gpii-ops/gpii-infra