-
Notifications
You must be signed in to change notification settings - Fork 1
/
config.yml
498 lines (480 loc) · 13.9 KB
/
config.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
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
version: 2.1
orbs:
hmpps: ministryofjustice/hmpps@7.1.0
slack: circleci/slack@4.12.1
parameters:
alerts-slack-channel:
type: string
default: pecs-dev
aliases:
- ¬ify_slack_on_failure
slack/notify:
event: fail
branch_pattern: main
channel: pecs-dev
custom: |
{
"blocks": [
{
"type": "context",
"elements": [
{
"type": "mrkdwn",
"text": ":circleci-${CCI_STATUS}: CircleCI job *${CIRCLE_JOB}* ${CCI_STATUS}"
}
]
},
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "*${CIRCLE_PROJECT_REPONAME}* failed ${CIRCLE_JOB}"
},
"accessory": {
"type": "button",
"text": {
"type": "plain_text",
"text": "View job"
},
"url": "${CIRCLE_BUILD_URL}"
}
}
]
}
- ¬ify_slack_on_release_start
slack/notify:
channel: $BUILD_NOTIFICATIONS_CHANNEL_ID
custom: '{
"blocks": [
{
"type": "section",
"fields": [
{
"type": "mrkdwn",
"text": "*API is being prepared for release :building_construction:*"
}
]
},
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "A new release was created by ${CIRCLE_USERNAME}"
},
"fields": [
{
"type": "mrkdwn",
"text": "@here"
}
]
},
{
"type": "actions",
"elements": [
{
"type": "button",
"text": {
"type": "plain_text",
"text": "Changelog"
},
"url": "https://github.com/ministryofjustice/hmpps-book-secure-move-api/blob/main/CHANGELOG.md"
}
]
}
]
}'
- ¬ify_slack_of_approval
slack/notify:
channel: $BUILD_NOTIFICATIONS_CHANNEL_ID
custom: '{
"blocks": [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "API release *requires your approval* before it can be deployed :eyes:"
},
"fields": [
{
"type": "mrkdwn",
"text": "${BUILD_NOTIFICATIONS_MENTION_ID}"
}
]
},
{
"type": "actions",
"elements": [
{
"type": "button",
"text": {
"type": "plain_text",
"text": "View Workflow"
},
"url": "https://circleci.com/workflow-run/${CIRCLE_WORKFLOW_ID}"
}
]
}
]
}'
- ¬ify_slack_on_release_end
slack/notify:
channel: $BUILD_NOTIFICATIONS_CHANNEL_ID
custom: '{
"blocks": [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "*API has been deployed* :rocket:"
},
"fields": [
{
"type": "mrkdwn",
"text": "@here This release was successfully deployed to production"
}
]
},
{
"type": "actions",
"elements": [
{
"type": "button",
"text": {
"type": "plain_text",
"text": "Release"
},
"url": "https://github.com/ministryofjustice/hmpps-book-secure-move-api/releases"
}
]
}
]
}'
- &all_tags
filters:
tags:
only: /.*/
- &test_only
filters:
branches:
ignore:
- main
tags:
ignore: /.*/
- &only_main
filters:
branches:
only:
- main
- &only_for_deployment
filters:
tags:
only: /^v.*/
branches:
only:
- main
- dev-auth-from-docs
- /.*-deploydev/
- &only_deploy_tags
filters:
tags:
only: /^v.*/
branches:
ignore: /.*/
# Not so keen on using references, but keeping them for now in case they have DRYness benefits.
# Likely to flatten then into the respective commands section.
references:
_save-cache: &save-cache
save_cache:
key: v2-dependencies-{{ checksum "Gemfile.lock" }}
paths:
- vendor/bundle
_restore-cache: &restore-cache
restore_cache:
keys:
- v2-dependencies-{{ checksum "Gemfile.lock" }}
- v2-dependencies-
_install-dependencies: &install-dependencies
run:
name: Install dependencies
command: |
bundler_version=$(cat Gemfile.lock | tail -1 | tr -d " ")
gem install bundler -v $bundler_version
bundle config --local path vendor/bundle
bundle check || bundle install --jobs=4 --retry=3
_wait-for-db: &wait-for-db
run:
name: Wait for DB
command: dockerize -wait tcp://localhost:5432 -timeout 1m
_wait-for-wiremock: &wait-for-wiremock
run:
name: Wait for wiremock
command: dockerize -wait tcp://localhost:8888 -timeout 1m
_create-db: &create-db
run:
name: Database setup
command: bundle exec rake db:create
_migrate-db: &migrate-db
run:
name: Database migrations
command: bundle exec rake db:migrate RAILS_ENV=test
_api_docs: &api_docs
run:
name: Generate API Docs
command: bundle exec rails rswag:specs:swaggerize
_load_wiremock_mappings: &load_wiremock_mappings
run:
name: Load mappings into wiremock
command: |
echo "Loading wiremock mappings..."
find spec/wiremock/prison-api/mappings/*.json -exec curl -vv --request POST --url http://localhost:8888/__admin/mappings --header 'content-type: application/json' --data-binary "@{}" \;
curl -vv http://localhost:8888/__admin/mappings
echo "Done"
_notify_sentry_release: ¬ify_sentry_release
run:
name: Create release and notify Sentry of deploy
command: |
curl -sL https://sentry.io/get-cli/ | bash
export SENTRY_RELEASE=$(sentry-cli releases propose-version)
sentry-cli releases new -p $SENTRY_PROJECT $SENTRY_RELEASE
sentry-cli releases set-commits $SENTRY_RELEASE --auto
sentry-cli releases finalize $SENTRY_RELEASE
sentry-cli releases deploys $SENTRY_RELEASE new -e $SENTRY_ENVIRONMENT
environment:
SENTRY_ENVIRONMENT: <<parameters.env>>
_rspec: &rspec
run:
name: Run rspec tests
command: |
TESTS=$(circleci tests glob "spec/**/*_spec.rb" | circleci tests split )
echo ${TESTS}
bundle exec rspec ${TESTS}
#COVERAGE=1 bundle exec rspec
_rubocop: &rubocop
run:
name: Run rubocop
command: bundle exec rubocop
_attach-tmp-workspace: &attach-tmp-workspace
attach_workspace:
at: .
executors:
basic-executor:
docker:
- image: cimg/base:2022.11
cloud-platform-executor:
docker:
- image: ${ECR_ENDPOINT}/cloud-platform/tools:circleci
environment:
GITHUB_TEAM_NAME_SLUG: book-a-secure-move
REPO_NAME: hmpps-book-secure-move-api
test-executor:
docker:
# Check https://circleci.com/docs/2.0/language-ruby/ for more details
- image: cimg/ruby:3.2.2
environment:
BUNDLER_VERSION: 2.4.20
RAILS_ENV: test
RACK_ENV: test
DATABASE_URL: "postgres://postgres@localhost/hmpps-book-secure-move-api"
EXTERNAL_URL: mocked_in_tests
ENCRYPTOR_SALT: "2EREZ8Xub/vt0ya1ZM6YKUwIMN72MbmqeWMq7KS4BV8oSJJc27rDpZYmA6AQGYcS"
EXTERNAL_WIREMOCK: "true"
- image: cimg/postgres:12.11
environment:
POSTGRES_USER: postgres
POSTGRES_DB: hmpps-book-secure-move-api
LANG: C.utf8
- image: wiremock/wiremock:2.32.0-alpine
command: --port 8888
commands:
build-base:
description: "Checkout app code and fetch dependencies for running tests"
steps:
- *restore-cache
- *install-dependencies
- *save-cache
seed-database:
description: "Create and seed the Database"
steps:
- *create-db
- *migrate-db
jobs:
notify_of_approval:
resource_class: small
executor: basic-executor
steps:
- *notify_slack_of_approval
notify_of_release:
resource_class: small
executor: basic-executor
steps:
- *notify_slack_on_release_start
setup_test_environment:
resource_class: small
executor: test-executor
steps:
- checkout
- setup_remote_docker
- build-base
- seed-database
api_docs:
resource_class: small
executor: test-executor
parallelism: 1
steps:
- checkout
- *attach-tmp-workspace
- build-base
- *create-db
- *migrate-db
- *api_docs
- persist_to_workspace:
root: .
paths:
- swagger/v1/swagger.yaml
- swagger/v2/swagger.yaml
- *notify_slack_on_failure
rspec_tests:
executor: test-executor
parallelism: 1
steps:
- checkout
- build-base
- *create-db
- *migrate-db
- *wait-for-db
- *attach-tmp-workspace
- *wait-for-wiremock
- *load_wiremock_mappings
- *rspec
linters:
resource_class: medium
executor: test-executor
steps:
- checkout
- build-base
- *attach-tmp-workspace
- *rubocop
workflows:
version: 2
test-build-deploy:
jobs:
- notify_of_release:
context:
- hmpps-common-vars
<<: *only_deploy_tags
- setup_test_environment:
<<: *all_tags
- api_docs:
context:
- hmpps-common-vars
<<: *all_tags
requires:
- setup_test_environment
- rspec_tests:
<<: *all_tags
requires:
- setup_test_environment
- linters:
<<: *all_tags
requires:
- setup_test_environment
- hmpps/build_docker:
<<: *test_only
requires:
- api_docs
- rspec_tests
- linters
name: test_build_image
image_name: "quay.io/hmpps/hmpps-book-secure-move-api"
publish: false
additional_docker_build_args: >
--label build.git.sha=${CIRCLE_SHA1}
--label build.git.branch=${CIRCLE_BRANCH}
--label build.date=$(date -Is)
--build-arg APP_BUILD_DATE=$(date -Is)
--build-arg APP_BUILD_TAG=${CIRCLE_BRANCH}
--build-arg APP_GIT_COMMIT=${CIRCLE_SHA1}
- hmpps/build_docker:
<<: *only_for_deployment
requires:
- api_docs
- rspec_tests
- linters
name: build_image
image_name: "quay.io/hmpps/hmpps-book-secure-move-api"
additional_docker_build_args: >
--label build.git.sha=${CIRCLE_SHA1}
--label build.git.branch=${CIRCLE_BRANCH}
--label build.date=$(date -Is)
--build-arg APP_BUILD_DATE=$(date -Is)
--build-arg APP_BUILD_TAG=${CIRCLE_BRANCH}
--build-arg APP_GIT_COMMIT=${CIRCLE_SHA1}
- hmpps/deploy_env:
<<: *only_main
name: deploy_staging
env: "staging"
context:
- hmpps-common-vars
- basm-api-staging
requires:
- build_image
- hmpps/deploy_env:
<<: *only_deploy_tags
name: deploy_uat
env: "uat"
context:
- hmpps-common-vars
- basm-api-uat
requires:
- build_image
- hmpps/deploy_env:
<<: *only_deploy_tags
name: deploy_preprod
env: "preprod"
context:
- hmpps-common-vars
- basm-api-preprod
requires:
- build_image
- hold_production:
<<: *only_deploy_tags
type: approval
requires:
- build_image
- notify_of_approval:
context:
- hmpps-common-vars
<<: *only_deploy_tags
requires:
- build_image
- hmpps/deploy_env:
<<: *only_deploy_tags
name: deploy_production
env: "production"
context:
- hmpps-common-vars
- basm-api-production
requires:
- hold_production
security:
triggers:
- schedule:
cron: "0 7 * * 1-5"
filters:
branches:
only:
- main
jobs:
- hmpps/gradle_owasp_dependency_check:
slack_channel: << pipeline.parameters.alerts-slack-channel >>
context:
- hmpps-common-vars
- hmpps/trivy_latest_scan:
slack_channel: << pipeline.parameters.alerts-slack-channel >>
context:
- hmpps-common-vars
- hmpps/veracode_policy_scan:
slack_channel: << pipeline.parameters.alerts-slack-channel >>
context:
- veracode-credentials
- hmpps-common-vars