-
Notifications
You must be signed in to change notification settings - Fork 1
/
.gitlab-ci.yml
368 lines (342 loc) · 10.5 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
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
---
# == Notes ==
# GitLab automatically passes artifacts from previous stages by default
# This CI definition uses a GitLab provided include template
# Secret variables
# - Set required secret variables at: https://gitlab.data.bas.ac.uk/magic/add-metadata-toolbox/settings/ci_cd
# - Variables are grouped by section in KEY: "value" format (e.g. FOO: "bar")
# Sensitive values are represented by "[Sensitive]"
#
# - CSW server connection strings
# > APP_CSW_CONNECTION_STRING_PASSWORD_PUBLISHED: "[Sensitive]"
# > APP_CSW_CONNECTION_STRING_PASSWORD_UNPUBLISHED: "[Sensitive]"
#
# - Private key for the 'bas-magic-shared-deployment-identity'
# > PODMAN_HOST_SSH_PRIVATE_KEY (protected, file): "[Sensitive]"
#
# - PyPi (production) - create tokens at https://pypi.org/manage/account/
# > PYPI_TOKEN (protected): "[Sensitive]"
#
# - PyPi (staging) - create tokens at https://test.pypi.org/manage/account/
# > PYPI_TEST_TOKEN (protected): "[Sensitive]"
#
# - Nomad deploy token
# create a deploy token at https://gitlab.data.bas.ac.uk/MAGIC/add-metadata-toolbox/-/settings/repository
# - name: 'MAGIC Nomad'
# - username: 'nomad'
# - scopes: 'read_registry'
# > NOMAD_DEPLOY_TOKEN (protected): "[Sensitive]"
#
# - Sentry - create tokens at https://sentry.io/settings/antarctica/developer-settings/bas-gitlab-4ffa11/
# > SENTRY_AUTH_TOKEN: "[Sensitive]"
#
# == Includes ==
include:
- template: 'Workflows/MergeRequest-Pipelines.gitlab-ci.yml'
# == Global settings ==
stages:
- 💥 setup
- 🧪 test
- 📦 package
- 🏗 build
- 🔍 review
- 🧹 post-review
- 🚚 publish
- 🚀 release
variables:
GIT_DEPTH: 100
DOCKER_HOST: tcp://docker:2376
DOCKER_CERT_PATH: /certs/client
DOCKER_DRIVER: overlay2
DOCKER_TLS_VERIFY: 1
GITLAB_REGISTRY: docker-registry.data.bas.ac.uk
PODMAN_HOST: bslws01.nerc-bas.ac.uk
APP_NAME: scar-add-metadata-toolbox
APP_PACKAGE: scar-add-metadata-toolbox
SENTRY_ORG: antarctica
SENTRY_PROJECT: add-metadata-editor
APP_STATIC_SITE_S3_BUCKET: add-catalogue-integration.data.bas.ac.uk
APP_CSW_CONNECTION_STRING_PUBLISHED: postgresql://pycsw_production:$APP_CSW_CONNECTION_STRING_PASSWORD_PUBLISHED@bsldb.nerc-bas.ac.uk/pycsw_production
APP_CSW_CONNECTION_STRING_UNPUBLISHED: postgresql://pycsw_production:$APP_CSW_CONNECTION_STRING_PASSWORD_UNPUBLISHED@bsldb.nerc-bas.ac.uk/pycsw_production
image:
name: docker-registry.data.bas.ac.uk/magic/add-metadata-toolbox:latest
entrypoint: [""]
# == Jobs ==
version:
stage: 💥 setup
image:
name: docker-registry.data.bas.ac.uk/magic/infrastructure/python-version-parser:latest
entrypoint: [""]
before_script:
- "python3 /usr/src/app/python_version_parser $(git describe --tags) > _version && export VERSION=$(cat _version)"
- "export VERSION=${VERSION:-0.0.0}"
script:
- 'echo $VERSION'
- 'echo "VERSION=$VERSION" >> build.env'
needs: []
artifacts:
reports:
dotenv: build.env
rules:
- changes:
- 'scar_add_metadata_toolbox/**/*.*'
pytest:
stage: 🧪 test
variables:
FLASK_ENV: testing
script:
- "pytest -o junit_family=xunit2 --junitxml=test-results.xml --random-order"
needs: []
artifacts:
reports:
junit: test-results.xml
rules:
- changes:
- '**/*.py'
coverage:
stage: 🧪 test
variables:
FLASK_ENV: testing
script:
- "pytest --cov=scar_add_metadata_toolbox --cov-fail-under=100 ."
after_script:
- "coverage html"
needs: []
artifacts:
paths:
- htmlcov
expire_in: 1 week
when: always
rules:
- changes:
- '**/*.py'
black:
stage: 🧪 test
script:
- "black --check scar_add_metadata_toolbox/"
needs: []
rules:
- changes:
- '**/*.py'
bandit:
stage: 🧪 test
script:
- "bandit -r ."
needs: []
rules:
- changes:
- '**/*.py'
package:
stage: 📦 package
script:
- "poetry version $VERSION"
- "poetry build"
needs:
- job: version
artifacts: true
artifacts:
paths:
- dist
expire_in: 1 month
rules:
- changes:
- 'scar_add_metadata_toolbox/**/*.*'
container:
stage: 🏗 build
image:
name: docker:19.03-dind
entrypoint: [""]
before_script:
- 'if [ -z "$CI_COMMIT_TAG" ]; then export IMAGE_ALIAS="review:$CI_COMMIT_REF_SLUG"; else export IMAGE_ALIAS="release:$CI_COMMIT_TAG"; fi'
- 'echo "$CI_REGISTRY_PASSWORD" | docker login -u "$CI_REGISTRY_USER" "$CI_REGISTRY" --password-stdin'
- 'cp -r ./dist/*.whl ./support/docker-packaging/'
- 'cd support/docker-packaging/'
script:
- 'docker build . -t $CI_REGISTRY_IMAGE/build:$CI_COMMIT_SHA -t $CI_REGISTRY_IMAGE/$IMAGE_ALIAS --build-arg APP_PACKAGE_VERSION="$APP_PACKAGE==$VERSION"'
- 'docker push $CI_REGISTRY_IMAGE/build:$CI_COMMIT_SHA'
- 'docker push $CI_REGISTRY_IMAGE/$IMAGE_ALIAS'
services:
- docker:dind
tags:
- dnd
needs:
- job: package
artifacts: true
- job: version
artifacts: true
rules:
- changes:
- 'scar_add_metadata_toolbox/**/*.*'
- 'support/docker-provisioning/**/*.*'
podman-wrapper:
stage: 🏗 build
image:
name: hashicorp/terraform:0.12.24
entrypoint: [""]
before_script:
- "cd provisioning/podman"
- "export TF_VAR_registry_image=$CI_REGISTRY_IMAGE/release:$CI_COMMIT_REF_SLUG"
- "export TF_VAR_app_csw_connection_string_published=$APP_CSW_CONNECTION_STRING_PUBLISHED"
- "export TF_VAR_app_csw_connection_string_unpublished=$APP_CSW_CONNECTION_STRING_UNPUBLISHED"
- "export TF_VAR_app_s3_static_site_bucket=$APP_STATIC_SITE_S3_BUCKET"
script:
- 'terraform init'
- 'terraform validate'
- 'terraform apply -auto-approve'
- 'chmod +x scar-add-metadata-toolbox'
needs: []
artifacts:
paths:
- provisioning/podman/scar-add-metadata-toolbox
- provisioning/podman/dot.env
expire_in: 1 month
rules:
- if: '$CI_COMMIT_TAG != null'
review:
stage: 🔍 review
image:
name: hashicorp/terraform:0.12.24
entrypoint: [""]
before_script:
- "cd provisioning/nomad-review-apps"
- "export TF_VAR_job_name=$APP_NAME-ra-$CI_COMMIT_REF_SLUG"
- "export TF_VAR_registry_image=$CI_REGISTRY_IMAGE/review:$CI_COMMIT_REF_SLUG"
- "export TF_VAR_registry_token=$NOMAD_DEPLOY_TOKEN"
- "export TF_VAR_app_csw_connection_string_published=$APP_CSW_CONNECTION_STRING_PUBLISHED"
- "export TF_VAR_app_csw_connection_string_unpublished=$APP_CSW_CONNECTION_STRING_UNPUBLISHED"
- "export TF_VAR_app_s3_static_site_bucket=$APP_STATIC_SITE_S3_BUCKET"
script:
- 'terraform init'
- 'terraform validate'
- 'terraform apply -auto-approve'
needs:
- job: container
artifacts:
paths:
- "provisioning/nomad-review-apps/terraform.tfstate"
expire_in: 1 month
rules:
- if: '$CI_COMMIT_TAG == null'
changes:
- 'scar_add_metadata_toolbox/**/*.*'
- 'support/docker-provisioning/**/*.*'
- 'support/pycsw/**/*.*'
environment:
name: review/$CI_COMMIT_REF_NAME
url: http://bsl-nomad-magic-dev-s3.nerc-bas.ac.uk:4646/ui/jobs/$APP_NAME-ra-$CI_COMMIT_REF_SLUG
on_stop: stop-review
stop-review:
stage: 🧹 post-review
image:
name: hashicorp/terraform:0.12.24
entrypoint: [""]
before_script:
- "cd provisioning/nomad-review-apps"
script:
- 'terraform init'
- 'terraform validate'
- 'terraform destroy -auto-approve'
needs:
- job: review
artifacts: true
rules:
- if: '$CI_COMMIT_TAG == null'
changes:
- 'scar_add_metadata_toolbox/**/*.*'
- 'support/docker-provisioning/**/*.*'
- 'support/pycsw/**/*.*'
when: manual
environment:
name: review/$CI_COMMIT_REF_NAME
action: stop
pypi-testing:
stage: 🚚 publish
before_script:
- "poetry config pypi-token.pypi-testing $PYPI_TEST_TOKEN --local"
script:
- "poetry version $VERSION"
- "poetry publish --repository pypi-testing --no-interaction"
needs:
- job: version
artifacts: true
- job: package
artifacts: true
rules:
- if: '$CI_COMMIT_TAG == null && $CI_COMMIT_BRANCH != "master"'
changes:
- 'scar_add_metadata_toolbox/**/*.*'
pypi:
stage: 🚚 publish
before_script:
- "poetry config pypi-token.pypi $PYPI_TOKEN --local"
- "poetry version $VERSION"
script:
- "poetry publish --repository pypi --no-interaction"
needs:
- job: version
artifacts: true
- job: package
artifacts: true
rules:
- if: '$CI_COMMIT_TAG != null'
podman:
stage: 🚀 release
image: kroniak/ssh-client
before_script:
- 'mkdir -p ~/.ssh'
- 'chmod 700 ~/.ssh'
- 'ssh-keyscan -H $PODMAN_HOST > ~/.ssh/known_hosts'
- 'mv $PODMAN_HOST_SSH_PRIVATE_KEY ~/.ssh/id_rsa'
- 'chmod 400 ~/.ssh/id_rsa'
script:
- 'ssh geoweb@$PODMAN_HOST -C "mkdir -p /users/geoweb/.config/scar-add-metadata-toolbox/"'
- 'ssh geoweb@$PODMAN_HOST -C "mkdir -p /users/geoweb/projects/scar-add-metadata-toolbox/records"'
- 'scp provisioning/podman/scar-add-metadata-toolbox geoweb@$PODMAN_HOST:/users/geoweb/bin/'
- 'scp provisioning/podman/dot.env geoweb@$PODMAN_HOST:/users/geoweb/.config/scar-add-metadata-toolbox/.env'
- 'ssh geoweb@$PODMAN_HOST -C "chmod 600 /users/geoweb/.config/scar-add-metadata-toolbox/.env"'
needs:
- job: podman-wrapper
artifacts: true
rules:
- if: '$CI_COMMIT_TAG != null'
nomad:
stage: 🚀 release
image:
name: hashicorp/terraform:0.12.24
entrypoint: [""]
before_script:
- "cd provisioning/nomad"
- "export TF_VAR_registry_image=$CI_REGISTRY_IMAGE/release:$CI_COMMIT_TAG"
- "export TF_VAR_registry_token=$NOMAD_DEPLOY_TOKEN"
- "export TF_VAR_app_csw_connection_string_published=$APP_CSW_CONNECTION_STRING_PUBLISHED"
- "export TF_VAR_app_csw_connection_string_unpublished=$APP_CSW_CONNECTION_STRING_UNPUBLISHED"
- "export TF_VAR_app_s3_static_site_bucket=$APP_STATIC_SITE_S3_BUCKET"
script:
- 'terraform init'
- 'terraform validate'
- 'terraform apply -auto-approve'
needs:
- job: container
rules:
- if: '$CI_COMMIT_TAG != null'
sentry:
stage: 🚀 release
image:
name: getsentry/sentry-cli
entrypoint: [""]
before_script:
- "export SENTRY_VERSION=$SENTRY_PROJECT@$VERSION"
- 'if [ -z "$CI_COMMIT_TAG" ]; then export SENTRY_ENVIRONMENT="review-$CI_MERGE_REQUEST_ID"; else export SENTRY_ENVIRONMENT="production"; fi'
- 'export SENTRY_ENVIRONMENT=`echo review-$CI_COMMIT_REF_SLUG | cut -c -64`'
script:
- "sentry-cli releases new --finalize $SENTRY_VERSION"
- "sentry-cli releases deploys $SENTRY_VERSION new -e $SENTRY_ENVIRONMENT"
- "sentry-cli releases set-commits --auto $SENTRY_VERSION"
needs:
- job: version
artifacts: true
rules:
- if: '$CI_COMMIT_TAG != null'
- if: '$CI_COMMIT_BRANCH != "master"'
changes:
- 'scar_add_metadata_toolbox/**/*.*'