forked from NHSDigital/integration-adaptor-mhs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
executable file
·533 lines (518 loc) · 34 KB
/
Jenkinsfile
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
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
pipeline {
agent{
label 'jenkins-workers'
}
environment {
BUILD_TAG = sh label: 'Generating build tag', returnStdout: true, script: 'python3 pipeline/scripts/tag.py ${GIT_BRANCH} ${BUILD_NUMBER} ${GIT_COMMIT}'
BUILD_TAG_LOWER = sh label: 'Lowercase build tag', returnStdout: true, script: "echo -n ${BUILD_TAG} | tr '[:upper:]' '[:lower:]'"
ENVIRONMENT_ID = "build"
MHS_INBOUND_QUEUE_NAME = "${ENVIRONMENT_ID}-inbound"
LOCAL_INBOUND_IMAGE_NAME = "local/mhs-inbound:${BUILD_TAG}"
LOCAL_OUTBOUND_IMAGE_NAME = "local/mhs-outbound:${BUILD_TAG}"
LOCAL_ROUTE_IMAGE_NAME = "local/mhs-route:${BUILD_TAG}"
LOCAL_FAKE_SPINE_IMAGE_NAME = "local/fake-spine:${BUILD_TAG}"
INBOUND_IMAGE_NAME = "${DOCKER_REGISTRY}/mhs/inbound:${BUILD_TAG}"
OUTBOUND_IMAGE_NAME = "${DOCKER_REGISTRY}/mhs/outbound:${BUILD_TAG}"
ROUTE_IMAGE_NAME = "${DOCKER_REGISTRY}/mhs/route:${BUILD_TAG}"
FAKE_SPINE_IMAGE_NAME = "${DOCKER_REGISTRY}/fake-spine:${BUILD_TAG}"
}
stages {
stage('Build & test Common') {
steps {
dir('common') {
buildModules('Installing common dependencies')
executeUnitTestsWithCoverage()
}
}
}
stage('Build & test MHS Common') {
steps {
dir('mhs/common') {
buildModules('Installing mhs common dependencies')
executeUnitTestsWithCoverage()
}
}
}
stage('Build MHS') {
parallel {
stage('Inbound') {
stages {
stage('Build') {
steps {
dir('mhs/inbound') {
buildModules('Installing inbound dependencies')
}
}
}
stage('Unit test') {
steps {
dir('mhs/inbound') {
executeUnitTestsWithCoverage()
}
}
}
stage('Build and Push image') {
when {
expression { currentBuild.resultIsBetterOrEqualTo('SUCCESS') }
}
steps {
buildAndPushImage('${LOCAL_INBOUND_IMAGE_NAME}', '${INBOUND_IMAGE_NAME}', 'mhs/inbound/Dockerfile')
}
}
}
}
stage('Outbound') {
stages {
stage('Build') {
steps {
dir('mhs/outbound') {
buildModules('Installing outbound dependencies')
}
}
}
stage('Unit test') {
steps {
dir('mhs/outbound') {
executeUnitTestsWithCoverage()
}
}
}
stage('Build and Push image') {
when {
expression { currentBuild.resultIsBetterOrEqualTo('SUCCESS') }
}
steps {
buildAndPushImage('${LOCAL_OUTBOUND_IMAGE_NAME}', '${OUTBOUND_IMAGE_NAME}', 'mhs/outbound/Dockerfile')
}
}
}
}
stage('Route') {
stages {
stage('Build') {
steps {
dir('mhs/spineroutelookup') {
buildModules('Installing route lookup dependencies')
}
}
}
stage('Unit test') {
steps {
dir('mhs/spineroutelookup') {
executeUnitTestsWithCoverage()
}
}
}
stage('Build and Push image') {
when {
expression { currentBuild.resultIsBetterOrEqualTo('SUCCESS') }
}
steps {
buildAndPushImage('${LOCAL_ROUTE_IMAGE_NAME}', '${ROUTE_IMAGE_NAME}', 'mhs/spineroutelookup/Dockerfile')
}
}
}
}
stage('Fake Spine') {
stages {
stage('Build and Push image') {
steps {
buildAndPushImage('${LOCAL_FAKE_SPINE_IMAGE_NAME}', '${FAKE_SPINE_IMAGE_NAME}', 'integration-tests/fake_spine/Dockerfile')
}
}
}
}
}
}
stage('Test') {
// NIAD-189: Parallel component and integration tests disabled due to intermittent build failures
//parallel {
stages {
stage('Run Component Tests (SpineRouteLookup)') {
options {
lock('local-docker-compose-environment')
}
stages {
stage('Deploy component locally (SpineRouteLookup)') {
steps {
sh label: 'Setup component test environment', script: './integration-tests/setup_component_test_env.sh'
sh label: 'Start containers', script: '''
docker-compose -f docker-compose.yml -f docker-compose.component.override.yml down -v
docker-compose -f docker-compose.yml -f docker-compose.component.override.yml -p custom_network down -v
. ./component-test-source.sh
docker-compose -f docker-compose.yml -f docker-compose.component.override.yml build
docker-compose -f docker-compose.yml -f docker-compose.component.override.yml -p ${BUILD_TAG_LOWER} up -d'''
}
}
stage('Component Tests (SpineRouteLookup)') {
steps {
sh label: 'Run component tests', script: '''
docker build -t local/mhs-componenttest:$BUILD_TAG -f ./component-test.Dockerfile .
docker run --rm --network "${BUILD_TAG_LOWER}_default" \
--env "MHS_ADDRESS=http://outbound" \
--env "AWS_ACCESS_KEY_ID=test" \
--env "AWS_SECRET_ACCESS_KEY=test" \
--env "MHS_DB_ENDPOINT_URL=http://dynamodb:8000" \
--env "FAKE_SPINE_ADDRESS=http://fakespine" \
--env "MHS_INBOUND_QUEUE_BROKERS=amqp://rabbitmq:5672" \
--env "MHS_INBOUND_QUEUE_NAME=inbound" \
--env "SCR_ADDRESS=http://scradaptor" \
local/mhs-componenttest:$BUILD_TAG
'''
}
}
}
post {
always {
sh label: 'Docker status', script: 'docker ps --all'
sh label: 'Dump container logs to files', script: '''
mkdir -p logs
docker logs ${BUILD_TAG_LOWER}_route_1 > logs/route_1.log
docker logs ${BUILD_TAG_LOWER}_outbound_1 > logs/outbound_1.log
docker logs ${BUILD_TAG_LOWER}_inbound_1 > logs/inbound_1.log
docker logs ${BUILD_TAG_LOWER}_fakespine_1 > logs/fakespine_1.log
docker logs ${BUILD_TAG_LOWER}_rabbitmq_1 > logs/rabbitmq_1.log
docker logs ${BUILD_TAG_LOWER}_redis_1 > logs/redis_1.log
docker logs ${BUILD_TAG_LOWER}_dynamodb_1 > logs/dynamodb_1.log
'''
archiveArtifacts artifacts: 'logs/*.log', fingerprint: true
sh label: 'Docker compose down', script: 'docker-compose -f docker-compose.yml -f docker-compose.component.override.yml -p ${BUILD_TAG_LOWER} down -v'
}
}
}
stage('Run Component Tests (SDS API)') {
options {
lock('local-docker-compose-environment')
}
stages {
stage('Deploy component locally (SDS API)') {
steps {
sh label: 'Setup component test environment', script: './integration-tests/setup_component_test_env.sh'
sh label: 'Start containers', script: '''
docker-compose -f docker-compose.yml -f docker-compose.component.override.yml -f docker-compose.component-sds.override.yml down -v
docker-compose -f docker-compose.yml -f docker-compose.component.override.yml -f docker-compose.component-sds.override.yml -p custom_network down -v
. ./component-test-source.sh
docker-compose -f docker-compose.yml -f docker-compose.component.override.yml -f docker-compose.component-sds.override.yml build
docker-compose -f docker-compose.yml -f docker-compose.component.override.yml -f docker-compose.component-sds.override.yml -p ${BUILD_TAG_LOWER} up -d
'''
}
}
stage('Component Tests (SDS API)') {
steps {
sh label: 'Run component tests', script: '''
docker build -t local/mhs-componenttest:$BUILD_TAG -f ./component-test.Dockerfile .
docker run --rm --network "${BUILD_TAG_LOWER}_default" \
--env "MHS_ADDRESS=http://outbound" \
--env "AWS_ACCESS_KEY_ID=test" \
--env "AWS_SECRET_ACCESS_KEY=test" \
--env "MHS_DB_ENDPOINT_URL=http://dynamodb:8000" \
--env "FAKE_SPINE_ADDRESS=http://fakespine" \
--env "MHS_INBOUND_QUEUE_BROKERS=amqp://rabbitmq:5672" \
--env "MHS_INBOUND_QUEUE_NAME=inbound" \
--env "SCR_ADDRESS=http://scradaptor" \
local/mhs-componenttest:$BUILD_TAG
'''
}
}
}
post {
always {
sh label: 'Docker status', script: 'docker ps --all'
sh label: 'Docker inspect network', script: 'docker network inspect ${BUILD_TAG_LOWER}_default'
sh label: 'Dump container logs to files', script: '''
mkdir -p logs
docker logs ${BUILD_TAG_LOWER}_outbound_1 > logs/outbound_2.log
docker logs ${BUILD_TAG_LOWER}_inbound_1 > logs/inbound_2.log
docker logs ${BUILD_TAG_LOWER}_fakespine_1 > logs/fakespine_2.log
docker logs ${BUILD_TAG_LOWER}_rabbitmq_1 > logs/rabbitmq_2.log
docker logs ${BUILD_TAG_LOWER}_dynamodb_1 > logs/dynamodb_2.log
docker logs ${BUILD_TAG_LOWER}_sds-api-mock_1 > logs/sdsapimock_2.log
'''
archiveArtifacts artifacts: 'logs/*.log', fingerprint: true
sh label: 'Docker compose down', script: 'docker-compose -f docker-compose.yml -f docker-compose.component.override.yml -f docker-compose.component-sds.override.yml -p ${BUILD_TAG_LOWER} down -v'
}
}
}
stage('Run Integration Tests (SpineRouteLookup)') {
options {
lock('exemplar-test-environment')
}
stages {
stage('Deploy MHS (SpineRouteLookup)') {
steps {
dir('pipeline/terraform/mhs-environment') {
sh label: 'Initialising Terraform', script: """
terraform init \
-backend-config="bucket=${TF_STATE_BUCKET}" \
-backend-config="region=${TF_STATE_BUCKET_REGION}" \
-backend-config="key=${ENVIRONMENT_ID}-mhs.tfstate" \
-backend-config="dynamodb_table=${ENVIRONMENT_ID}-${TF_MHS_LOCK_TABLE_NAME}" \
-input=false -no-color
"""
sh label: 'Applying Terraform configuration', script: """
terraform apply -no-color -auto-approve \
-var environment_id=${ENVIRONMENT_ID} \
-var build_id=${BUILD_TAG} \
-var supplier_vpc_id=${SUPPLIER_VPC_ID} \
-var opentest_vpc_id=${OPENTEST_VPC_ID} \
-var internal_root_domain=${INTERNAL_ROOT_DOMAIN} \
-var mhs_outbound_service_minimum_instance_count=3 \
-var mhs_outbound_service_maximum_instance_count=9 \
-var mhs_inbound_service_minimum_instance_count=3 \
-var mhs_inbound_service_maximum_instance_count=9 \
-var mhs_route_service_minimum_instance_count=3 \
-var mhs_route_service_maximum_instance_count=9 \
-var task_role_arn=${TASK_ROLE} \
-var execution_role_arn=${TASK_EXECUTION_ROLE} \
-var task_scaling_role_arn=${TASK_SCALING_ROLE} \
-var ecr_address=${DOCKER_REGISTRY} \
-var mhs_outbound_validate_certificate=${MHS_OUTBOUND_VALIDATE_CERTIFICATE} \
-var mhs_log_level=DEBUG \
-var mhs_outbound_spineroutelookup_verify_certificate="False" \
-var mhs_outbound_http_proxy=${MHS_OUTBOUND_HTTP_PROXY} \
-var mhs_state_table_read_capacity=5 \
-var mhs_state_table_write_capacity=5 \
-var mhs_sync_async_table_read_capacity=5 \
-var mhs_sync_async_table_write_capacity=5 \
-var mhs_spine_org_code=${SPINE_ORG_CODE} \
-var inbound_queue_brokers="${MHS_INBOUND_QUEUE_BROKERS}" \
-var inbound_queue_name="${MHS_INBOUND_QUEUE_NAME}" \
-var inbound_queue_username_arn=${INBOUND_QUEUE_USERNAME_ARN} \
-var inbound_queue_password_arn=${INBOUND_QUEUE_PASSWORD_ARN} \
-var party_key_arn=${PARTY_KEY_ARN} \
-var client_cert_arn=${CLIENT_CERT_ARN} \
-var client_key_arn=${CLIENT_KEY_ARN} \
-var ca_certs_arn=${CA_CERTS_ARN} \
-var route_ca_certs_arn=${ROUTE_CA_CERTS_ARN} \
-var outbound_alb_certificate_arn=${OUTBOUND_ALB_CERT_ARN} \
-var route_alb_certificate_arn=${ROUTE_ALB_CERT_ARN} \
-var mhs_resynchroniser_max_retries=${MHS_RESYNC_RETRIES} \
-var mhs_resynchroniser_interval=${MHS_RESYNC_INTERVAL} \
-var spineroutelookup_service_sds_url=${SPINEROUTELOOKUP_SERVICE_LDAP_URL} \
-var spineroutelookup_service_search_base=${SPINEROUTELOOKUP_SERVICE_SEARCH_BASE} \
-var spineroutelookup_service_disable_sds_tls=${SPINEROUTELOOKUP_SERVICE_DISABLE_TLS} \
-var elasticache_node_type="cache.t2.micro" \
-var mhs_forward_reliable_endpoint_url=${MHS_FORWARD_RELIABLE_ENDPOINT_URL} \
-var mhs_outbound_routing_lookup_method="SPINE_ROUTE_LOOKUP" \
-var mhs_sds_api_url="" \
-var mhs_sds_api_key_arn=${MHS_SDS_API_KEY_ARN} \
"""
script {
env.MHS_ADDRESS = sh (
label: 'Obtaining outbound LB DNS name',
returnStdout: true,
script: "echo \"https://\$(terraform output outbound_lb_domain_name)\""
).trim()
env.MHS_OUTBOUND_TARGET_GROUP = sh (
label: 'Obtaining outbound LB target group ARN',
returnStdout: true,
script: "terraform output outbound_lb_target_group_arn"
).trim()
env.MHS_INBOUND_TARGET_GROUP = sh (
label: 'Obtaining inbound LB target group ARN',
returnStdout: true,
script: "terraform output inbound_lb_target_group_arn"
).trim()
env.MHS_ROUTE_TARGET_GROUP = sh (
label: 'Obtaining route LB target group ARN',
returnStdout: true,
script: "terraform output route_lb_target_group_arn"
).trim()
env.MHS_STATE_TABLE_NAME = sh (
label: 'Obtaining the table name used for the MHS state',
returnStdout: true,
script: "terraform output mhs_state_table_name"
).trim()
env.MHS_SYNC_ASYNC_TABLE_NAME = sh (
label: 'Obtaining the table name used for the MHS sync/async state',
returnStdout: true,
script: "terraform output mhs_sync_async_table_name"
).trim()
}
}
}
}
stage('Integration Tests (SpineRouteLookup)') {
steps {
dir('integration-tests/integration_tests') {
sh label: 'Installing integration test dependencies', script: 'pipenv install --dev --deploy --ignore-pipfile'
// Wait for MHS load balancers to have healthy targets
dir('../../pipeline/scripts/check-target-group-health') {
sh script: 'pipenv install'
timeout(13) {
waitUntil {
script {
def r = sh script: 'sleep 10; AWS_DEFAULT_REGION=eu-west-2 pipenv run main ${MHS_OUTBOUND_TARGET_GROUP} ${MHS_INBOUND_TARGET_GROUP} ${MHS_ROUTE_TARGET_GROUP}', returnStatus: true
return (r == 0);
}
}
}
}
sh label: 'Running integration tests', script: 'pipenv run inttests'
}
}
}
}
}
stage('Run Integration Tests (SDS API)') {
options {
lock('exemplar-test-environment')
}
stages {
stage('Deploy MHS (SDS API)') {
steps {
dir('pipeline/terraform/mhs-environment') {
sh label: 'Initialising Terraform', script: """
terraform init \
-backend-config="bucket=${TF_STATE_BUCKET}" \
-backend-config="region=${TF_STATE_BUCKET_REGION}" \
-backend-config="key=${ENVIRONMENT_ID}-mhs.tfstate" \
-backend-config="dynamodb_table=${ENVIRONMENT_ID}-${TF_MHS_LOCK_TABLE_NAME}" \
-input=false -no-color
"""
sh label: 'Applying Terraform configuration', script: """
terraform apply -no-color -auto-approve \
-var environment_id=${ENVIRONMENT_ID} \
-var build_id=${BUILD_TAG} \
-var supplier_vpc_id=${SUPPLIER_VPC_ID} \
-var opentest_vpc_id=${OPENTEST_VPC_ID} \
-var internal_root_domain=${INTERNAL_ROOT_DOMAIN} \
-var mhs_outbound_service_minimum_instance_count=3 \
-var mhs_outbound_service_maximum_instance_count=9 \
-var mhs_inbound_service_minimum_instance_count=3 \
-var mhs_inbound_service_maximum_instance_count=9 \
-var mhs_route_service_minimum_instance_count=3 \
-var mhs_route_service_maximum_instance_count=9 \
-var task_role_arn=${TASK_ROLE} \
-var execution_role_arn=${TASK_EXECUTION_ROLE} \
-var task_scaling_role_arn=${TASK_SCALING_ROLE} \
-var ecr_address=${DOCKER_REGISTRY} \
-var mhs_outbound_validate_certificate=${MHS_OUTBOUND_VALIDATE_CERTIFICATE} \
-var mhs_log_level=DEBUG \
-var mhs_outbound_spineroutelookup_verify_certificate="False" \
-var mhs_outbound_http_proxy=${MHS_OUTBOUND_HTTP_PROXY} \
-var mhs_state_table_read_capacity=5 \
-var mhs_state_table_write_capacity=5 \
-var mhs_sync_async_table_read_capacity=5 \
-var mhs_sync_async_table_write_capacity=5 \
-var mhs_spine_org_code=${SPINE_ORG_CODE} \
-var inbound_queue_brokers="${MHS_INBOUND_QUEUE_BROKERS}" \
-var inbound_queue_name="${MHS_INBOUND_QUEUE_NAME}" \
-var inbound_queue_username_arn=${INBOUND_QUEUE_USERNAME_ARN} \
-var inbound_queue_password_arn=${INBOUND_QUEUE_PASSWORD_ARN} \
-var party_key_arn=${PARTY_KEY_ARN} \
-var client_cert_arn=${CLIENT_CERT_ARN} \
-var client_key_arn=${CLIENT_KEY_ARN} \
-var ca_certs_arn=${CA_CERTS_ARN} \
-var route_ca_certs_arn=${ROUTE_CA_CERTS_ARN} \
-var outbound_alb_certificate_arn=${OUTBOUND_ALB_CERT_ARN} \
-var route_alb_certificate_arn=${ROUTE_ALB_CERT_ARN} \
-var mhs_resynchroniser_max_retries=${MHS_RESYNC_RETRIES} \
-var mhs_resynchroniser_interval=${MHS_RESYNC_INTERVAL} \
-var spineroutelookup_service_sds_url=${SPINEROUTELOOKUP_SERVICE_LDAP_URL} \
-var spineroutelookup_service_search_base=${SPINEROUTELOOKUP_SERVICE_SEARCH_BASE} \
-var spineroutelookup_service_disable_sds_tls=${SPINEROUTELOOKUP_SERVICE_DISABLE_TLS} \
-var elasticache_node_type="cache.t2.micro" \
-var mhs_forward_reliable_endpoint_url=${MHS_FORWARD_RELIABLE_ENDPOINT_URL} \
-var mhs_outbound_routing_lookup_method="SDS_API" \
-var mhs_sds_api_url=${MHS_SDS_API_URL} \
-var mhs_sds_api_key_arn=${MHS_SDS_API_KEY_ARN} \
"""
script {
env.MHS_ADDRESS = sh (
label: 'Obtaining outbound LB DNS name',
returnStdout: true,
script: "echo \"https://\$(terraform output outbound_lb_domain_name)\""
).trim()
env.MHS_OUTBOUND_TARGET_GROUP = sh (
label: 'Obtaining outbound LB target group ARN',
returnStdout: true,
script: "terraform output outbound_lb_target_group_arn"
).trim()
env.MHS_INBOUND_TARGET_GROUP = sh (
label: 'Obtaining inbound LB target group ARN',
returnStdout: true,
script: "terraform output inbound_lb_target_group_arn"
).trim()
env.MHS_ROUTE_TARGET_GROUP = sh (
label: 'Obtaining route LB target group ARN',
returnStdout: true,
script: "terraform output route_lb_target_group_arn"
).trim()
env.MHS_STATE_TABLE_NAME = sh (
label: 'Obtaining the table name used for the MHS state',
returnStdout: true,
script: "terraform output mhs_state_table_name"
).trim()
env.MHS_SYNC_ASYNC_TABLE_NAME = sh (
label: 'Obtaining the table name used for the MHS sync/async state',
returnStdout: true,
script: "terraform output mhs_sync_async_table_name"
).trim()
}
}
}
}
stage('Integration Tests (SDS API)') {
steps {
dir('integration-tests/integration_tests') {
sh label: 'Installing integration test dependencies', script: 'pipenv install --dev --deploy --ignore-pipfile'
// Wait for MHS load balancers to have healthy targets
dir('../../pipeline/scripts/check-target-group-health') {
sh script: 'pipenv install'
timeout(13) {
waitUntil {
script {
def r = sh script: 'sleep 10; AWS_DEFAULT_REGION=eu-west-2 pipenv run main ${MHS_OUTBOUND_TARGET_GROUP} ${MHS_INBOUND_TARGET_GROUP} ${MHS_ROUTE_TARGET_GROUP}', returnStatus: true
return (r == 0);
}
}
}
}
sh label: 'Running integration tests', script: """
export SKIP_FORWARD_RELIABLE_INT_TEST=true
pipenv run inttests
"""
}
}
}
}
}
} // parallel
}
}
post {
always {
cobertura coberturaReportFile: '**/coverage.xml'
junit '**/test-reports/*.xml'
sh 'docker-compose -f docker-compose.yml -f docker-compose.component.override.yml -p ${BUILD_TAG_LOWER} down -v'
sh 'docker volume prune --force'
// Prune Docker images for current CI build.
// Note that the * in the glob patterns doesn't match /
sh 'docker image rm -f $(docker images "*/*:*${BUILD_TAG}" -q) $(docker images "*/*/*:*${BUILD_TAG}" -q) || true'
}
}
}
void executeUnitTestsWithCoverage() {
sh label: 'Running unit tests', script: 'pipenv run unittests-cov'
sh label: 'Displaying code coverage report', script: 'pipenv run coverage-report'
sh label: 'Exporting code coverage report', script: 'pipenv run coverage-report-xml'
// SonarQube disabled as atm it's not set up on AWS
// sh label: 'Running SonarQube analysis', script: "sonar-scanner -Dsonar.host.url=${SONAR_HOST} -Dsonar.login=${SONAR_TOKEN}"
}
void buildModules(String action) {
sh label: action, script: 'pipenv install --dev --deploy --ignore-pipfile'
}
int ecrLogin(String aws_region) {
String ecrCommand = "aws ecr get-login --region ${aws_region}"
String dockerLogin = sh (label: "Getting Docker login from ECR", script: ecrCommand, returnStdout: true).replace("-e none","") // some parameters that AWS provides and docker does not recognize
return sh(label: "Logging in with Docker", script: dockerLogin, returnStatus: true)
}
void buildAndPushImage(String localImageName, String imageName, String dockerFile, String context = '.') {
sh label: 'Running docker build', script: 'docker build -t ' + localImageName + ' -f ' + dockerFile + ' ' + context
if (ecrLogin(TF_STATE_BUCKET_REGION) != 0 ) { error("Docker login to ECR failed") }
sh label: 'Tag ecr image', script: 'docker tag ' + localImageName + ' ' + imageName
String dockerPushCommand = "docker push " + imageName
if (sh (label: "Pushing image", script: dockerPushCommand, returnStatus: true) !=0) { error("Docker push image failed") }
sh label: 'Deleting local ECR image', script: 'docker rmi ' + imageName
}