1. ministryofjustice/hmpps@10.3.0

ministryofjustice/hmpps@10.3.0

Sections
HMPPS projects reusable circleci config
Created: April 30, 2020Version Published: March 3, 2025Releases: 128
Org Usage:
< 25

Orb Quick Start Guide

Use CircleCI version 2.1 at the top of your .circleci/config.yml file.

1 version: 2.1

Add the orbs stanza below your version, invoking the orb:

1 2 orbs: hmpps: ministryofjustice/hmpps@10.3.0

Use hmpps elements in your existing workflows and jobs.

Opt-in to use of uncertified orbs on your organization’s Security settings page.

Usage Examples

deployment_with_slack_and_changelog

Deployment with Slack notifications and git changelog

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 version: '2.1' orbs: hmpps: ministryofjustice/hmpps@3.5 workflows: build-test-and-deploy: jobs: - hmpps/build_docker: image_name: example_image_name name: build_docker snyk-scan: true snyk-threshold: high - hmpps/deploy_env: context: - hmpps-common-vars env: dev name: deploy_dev requires: - build_docker show_changelog: true slack_channel_name: your-notification-channel slack_notification: true

example

CircleCI orb used to store common jobs/commands used by MoJ DPS team projects.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 version: '2.1' orbs: hmpps: ministryofjustice/hmpps@2.2 workflows: build-test-and-deploy: jobs: - hmpps/npm_security_audit: context: - hmpps-common-vars slack_channel: your_channel_or_leave_out_for_default - hmpps/helm_lint - hmpps/build_docker: image_name: example_image_name name: build_docker snyk-fail-build: false snyk-scan: true snyk-threshold: high - hmpps/deploy_env: chart_name: example_app env: dev name: deploy_dev requires: - build_docker

slack_notification

Deployment with Slack notifications

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 version: '2.1' orbs: hmpps: ministryofjustice/hmpps@2.2 workflows: build-test-and-deploy: jobs: - hmpps/build_docker: image_name: example_image_name name: build_docker snyk-scan: true snyk-threshold: high - hmpps/deploy_env: context: - hmpps-common-vars env: dev name: deploy_dev requires: - build_docker slack_channel_name: your-notification-channel slack_notification: true

Jobs

build_docker

Build docker image, also creates an app version string and pushes image to repo.

Show job Source
PARAMETER
DESCRIPTION
REQUIRED
DEFAULT
TYPE
additional_docker_build_args
-
No
''
string
additional_docker_tag
Additional docker tag that can be used to specify stable tags
No
''
string
dockerfile_dir
-
No
.
string
git-lfs
-
No
false
boolean
image_name
-
No
quay.io/hmpps/${CIRCLE_PROJECT_REPONAME}
string
jira_update
When true, updates any referenced Jira tickets with build status. Note that Jira integration must be enabled in your CircleCI project settings.
No
false
boolean
no_output_timeout
Configure the no_output_timeout setting for the container build step
No
30m
string
persist_container_image
Make the built container image available for subsequent jobs
No
false
boolean
pipeline_id
Required if jira_update is set (otherwise the Notify Jira job will pass but do nothing), passed in as << pipeline.id >>
No
''
string
pipeline_number
Required if jira_update is set, passed in as << pipeline.number >>
No
0
integer
publish
-
No
true
boolean
snyk-args
-
No
''
string
snyk-fail-build
-
No
true
boolean
snyk-org
-
No
digital-probation-services
string
snyk-scan
-
No
false
boolean
snyk-target-file
-
No
Dockerfile
string
snyk-threshold
-
No
high
enum

build_multiplatform_docker

Build docker image, also creates an app version string and pushes image to repo.

Show job Source
PARAMETER
DESCRIPTION
REQUIRED
DEFAULT
TYPE
additional_docker_build_args
-
No
''
string
dockerfile_dir
-
No
.
string
git-lfs
-
No
false
boolean
image_name
-
No
quay.io/hmpps/${CIRCLE_PROJECT_REPONAME}
string
jira_update
When true, updates any referenced Jira tickets with build status. Note that Jira integration must be enabled in your CircleCI project settings.
No
false
boolean
no_output_timeout
Configure the no_output_timeout setting for the container build step
No
30m
string
pipeline_id
Required if jira_update is set (otherwise the Notify Jira job will pass but do nothing), passed in as << pipeline.id >>
No
''
string
pipeline_number
Required if jira_update is set, passed in as << pipeline.number >>
No
0
integer
snyk-args
-
No
''
string
snyk-fail-build
-
No
true
boolean
snyk-org
-
No
digital-probation-services
string
snyk-scan
-
No
false
boolean
snyk-target-file
-
No
Dockerfile
string
snyk-threshold
-
No
high
enum

database_schema_report

Job to generate a schema report for a postgres database using schemaspy. Runs against postgres in docker An HTML report is generated and is available on the artifacts tab of the circleci job

Show job Source
PARAMETER
DESCRIPTION
REQUIRED
DEFAULT
TYPE
database_name
Name of the database
No
postgres
string
host
Host name of the database
No
localhost
string
initialise_database
A command which will initialise the database schema
No
./gradlew check
string
jdk_tag
-
No
'21.0'
string
localstack_tag
-
No
'3.0'
string
password
Database password
No
dev
string
port
Port number of the database
No
5432
integer
postgres_driver_version
Postgres driver version
No
42.7.3
string
postgres_tag
-
No
'16.1'
string
schema
Schema name
No
public
string
schemaspy_version
Schemaspy version
No
6.2.4
string
user
Database user name
No
root
string

deploy_env

Deploy via helm, using chart found in the helm_deploy dir of the repo. Optionally send a slack notification.

Show job Source
PARAMETER
DESCRIPTION
REQUIRED
DEFAULT
TYPE
changelog_git_paths
When set it will limit the file changes shown in the changelog to the specified paths only. This is useful for multi-project builds where otherwise it will show all changes from all projects.
No
''
string
chart_name
-
No
PROJECT_NAME
string
chart_version
-
No
latest
string
env
-
No
dev
string
helm_additional_args
-
No
''
string
helm_dir
-
No
helm_deploy
string
helm_repo
For using non local helm chart set to URL of helm repo
No
local
string
helm_timeout
-
No
5m
string
jira_env_type
Environment type to use when updating Jira
No
development
enum
jira_update
When true, updates any referenced Jira tickets with deployment information. Note that Jira integration must be enabled in your CircleCI project settings.
No
false
boolean
k8s_deployment_name
The Deployment resource's name in Kubernetes to interrogate for the previous deployment's version
No
PROJECT_NAME
string
pipeline_id
Required if jira_update is set (otherwise the Notify Jira job will pass but do nothing), passed in as << pipeline.id >>
No
''
string
pipeline_number
Required if jira_update is set, passed in as << pipeline.number >>
No
0
integer
release_name
-
No
PROJECT_NAME
string
show_changelog
When true, displays what is new since the previous deployment in the job, and in Slack, if applicable
No
true
boolean
slack_channel_name
Slack channel to use for deployment notifications.
No
dps-releases
string
slack_notification
When true, notifies a Slack channel after every deployment done with this job.
No
false
boolean

gradle_owasp_dependency_check

Job for running OWASP Dependency Check, looking for package dependencies with security vulnerabilities

Show job Source
PARAMETER
DESCRIPTION
REQUIRED
DEFAULT
TYPE
cache_key
Specify a custom cache key.
No
v2
string
cve_data_directory
The plugin database directory.
No
~/.gradle/dependency-check-data
string
java_options
-
No
>- -Xmx1024m -XX:ParallelGCThreads=2 -XX:ConcGCThreads=2 -Djava.util.concurrent.ForkJoinPool.common.parallelism=2 -Dorg.gradle.daemon=false -Dkotlin.compiler.execution.strategy=in-process
string
jdk_tag
-
No
'17.0'
string
no_output_timeout
Specify period of time has passed with no output.
No
15m
string
persist_to_workspace
Persist reports to workspace for further processing.
No
false
boolean
slack_channel
Slack channel to use for notifications.
No
dps_alerts_security
string
task
Task name.
No
dependencyCheckAnalyze
string

helm_lint

Helm lint - Check for syntax and render issues within the helm Chart

Show job Source
PARAMETER
DESCRIPTION
REQUIRED
DEFAULT
TYPE
chart_name
-
No
${CIRCLE_PROJECT_REPONAME}
string
env
-
No
dev
string
helm_additional_args
-
No
''
string
helm_dir
-
No
helm_deploy
string

npm_outdated

Node.js projects using npm - check if package dependencies are outdated

Show job Source
PARAMETER
DESCRIPTION
REQUIRED
DEFAULT
TYPE
dependencies_to_check
Dependencies to check if they are outdated.
No
typescript govuk-frontend
string
node_tag
-
No
'20.16'
string
slack_channel
Slack channel to use for notifications.
No
dps_alerts_security
string

npm_security_audit

Node.js projects using npm - auditing package dependencies for security vulnerabilities

Show job Source
PARAMETER
DESCRIPTION
REQUIRED
DEFAULT
TYPE
node_tag
-
No
'20.16'
string
slack_channel
Slack channel to use for notifications.
No
dps_alerts_security
string

publish_docker

Pushes the built container image to the repository. NOTE: You MUST have ran your `build_docker` job with the parameter `persist_container_image` set to `true`.

Show job Source
PARAMETER
DESCRIPTION
REQUIRED
DEFAULT
TYPE
publish_latest_tag
-
No
true
boolean

sentry_release_and_deploy

Notify Sentry.io of a release and deployment within your codebase

Show job Source
PARAMETER
DESCRIPTION
REQUIRED
DEFAULT
TYPE
sentry_create_release
Tell sentry-cli to work out the commits on this release - this should only be done ONCE, ideally when you push to DEV.
No
false
boolean
sentry_environment
-
Yes
-
string
sentry_org
-
No
ministryofjustice
string
sentry_project
-
Yes
-
string

smoke_test

Runs the smoke test for this project

Show job Source
PARAMETER
DESCRIPTION
REQUIRED
DEFAULT
TYPE
cachekey
-
No
gradle-
string
cachepath
-
No
~/.gradle
string
command
-
No
./gradlew testSmoke -Dtestlogger.showStandardStreams=true
string
gradlefile
-
No
build.gradle.kts
string
jdk_tag
-
No
'11.0'
string

trigger_job

Trigger and (optionally) follow a pipeline in another CircleCI project.

Show job Source
PARAMETER
DESCRIPTION
REQUIRED
DEFAULT
TYPE
branch
Name of the branch to target
No
main
string
build_parameters
Parameters to pass to the triggered pipeline (in a JSON string)
No
'{}'
string
fail_build
Fail the build if the triggered pipeline fails
No
true
boolean
follow_pipeline
Follow the triggered pipeline and capture the result
No
true
boolean
follow_timeout
Number of seconds to wait for the triggered pipeline to complete
No
500
integer
organization
Name of the CircleCI organization
No
ministryofjustice
string
repository
Name of the repository
Yes
-
string
token
CircleCI Auth token for API access, either the string value, or an environment variable (i.e. $AUTH_TOKEN) that can be read via a context.
Yes
-
string
vcs_type
Chosen VCS (either github or bitbucket)
No
github
string

trivy_latest_scan

Scan the latest tag (docker container image) for CVEs using Trivy. This is intended to be a scheduled job that runs maybe daily and can alert teams to new found issues on running applications that might not be in active development. Uses the latest Docker Trivy image.

Show job Source
PARAMETER
DESCRIPTION
REQUIRED
DEFAULT
TYPE
additional_args
Additional CLI args to pass into the trivy command
No
''
string
cache_key
Cache key for the vulnerability database - change to break the cache.
No
v1
string
cve_severities_to_check
What severity of CVE to look for? Options are UNKNOWN,LOW,MEDIUM,HIGH,CRITICAL.
No
HIGH,CRITICAL
string
db_repo_1
Database repository for vulnerability database - main
No
ghcr.io/aquasecurity/trivy-db:2
string
db_repo_2
Database repository for vulnerability database - backup
No
public.ecr.aws/aquasecurity/trivy-db
string
image_name
-
No
quay.io/hmpps/${CIRCLE_PROJECT_REPONAME}
string
slack_channel
Slack channel to use for notifications.
No
dps_alerts_security
string
trivy_template
-
No
| ------- {{- range . }} {{- $location := .Target }} {{- range .Vulnerabilities }} Severity: {{ .Severity }} CVE: {{ .VulnerabilityID }} Title: "{{ .Title }}" PkgName: {{ .PkgName }} InstalledVersion: {{ .InstalledVersion }} FixedVersion: {{ .FixedVersion }} Location: {{ $location }} ------- {{- end }} {{- end }}
string

trivy_pipeline_scan

Scan the built docker container for CVEs using Trivy.

Show job Source
PARAMETER
DESCRIPTION
REQUIRED
DEFAULT
TYPE
additional_args
Additional CLI args to pass into the trivy command
No
''
string
cache_key
Cache key for the vulnerability database - change to break the cache.
No
v1
string
cve_severities_to_check
What severity of CVE to look for? Options are UNKNOWN,LOW,MEDIUM,HIGH,CRITICAL.
No
HIGH,CRITICAL
string
db_repo_1
Database repository for vulnerability database - main
No
ghcr.io/aquasecurity/trivy-db:2
string
db_repo_2
Database repository for vulnerability database - backup
No
public.ecr.aws/aquasecurity/trivy-db
string
fail_build
Fail the build if any CVEs are detected.
No
true
boolean

veracode_pipeline_scan

Veracode SAST pipeline scan

Show job Source
PARAMETER
DESCRIPTION
REQUIRED
DEFAULT
TYPE
additional_docker_build_args
-
No
''
string
docker_image_app_dir
Directory inside the docker image where the application artifacts are saved
No
/app
string
java_options
-
No
>- -Xmx1024m -XX:ParallelGCThreads=2 -XX:ConcGCThreads=2 -Djava.util.concurrent.ForkJoinPool.common.parallelism=2 -Dorg.gradle.daemon=false -Dkotlin.compiler.execution.strategy=in-process
string
jdk_tag
-
No
'17.0'
string
slack_channel
Slack channel to use for notifications.
No
dps_alerts_security
string

veracode_policy_scan

Veracode SAST policy scan

Show job Source
PARAMETER
DESCRIPTION
REQUIRED
DEFAULT
TYPE
additional_docker_build_args
-
No
''
string
docker_image_app_dir
Directory inside the docker image where the application artifacts are saved
No
/app
string
java_options
-
No
>- -Xmx1024m -XX:ParallelGCThreads=2 -XX:ConcGCThreads=2 -Djava.util.concurrent.ForkJoinPool.common.parallelism=2 -Dorg.gradle.daemon=false -Dkotlin.compiler.execution.strategy=in-process
string
jdk_tag
-
No
'17.0'
string
slack_channel
Slack channel to use for notifications.
No
dps_alerts_security
string
teams
Comma-separated list of team names associated with the specified application. Validates against the names of existing teams for this account.
No
hmpps-tech
string

Commands

create_app_version

Creates an application version string, formatted [DATE].[CIRCLE_BUILD_NUM].[SHORT_SHA1] e.g 2020-04-24.487.fb30e99" Also uses mem/rememborb orb to remember the version as the env var APP_VERSION - which can be recalled in subsequent steps or jobs e.g. mem/recall

Show command Source

install_aws_cli

Install AWS cli

Show command Source
PARAMETER
DESCRIPTION
REQUIRED
DEFAULT
TYPE
version
-
No
'2'
enum

install_git_lfs

Install Git LFS

Show command Source

install_helm

Install helm client

Show command Source
PARAMETER
DESCRIPTION
REQUIRED
DEFAULT
TYPE
version
-
No
v3.4.2
string

install_trivy

Install Trivy

Show command Source

k8s_setup

Install kubectl and configure

Show command Source
PARAMETER
DESCRIPTION
REQUIRED
DEFAULT
TYPE
ca-cert
-
No
KUBE_ENV_CACERT
env_var_name
cluster-name
-
No
KUBE_ENV_NAME
env_var_name
kube-api
-
No
KUBE_ENV_API
env_var_name
kube-namespace
-
No
KUBE_ENV_NAMESPACE
env_var_name
kube-token
-
No
KUBE_ENV_TOKEN
env_var_name
kube-user
-
No
circleci
string

recall_container_image

Recalls the built container image (tagged as "${IMAGE_NAME}:${APP_VERSION}" in the environment) within the circleci workspace so that it can be used in a subsequent job. NOTE: You MUST have ran your `build_docker` job with the parameter `persist_container_image` set to `true`.

Show command Source

slack_message_results

Takes a text file containing output/results and turn into an environment variable which is suitable for interpolating into a slack custom message template. All slack special chars converted to html entities. Non json friendly chars are escaped.

Show command Source
PARAMETER
DESCRIPTION
REQUIRED
DEFAULT
TYPE
env_var
-
No
SLACK_TXT
string
file
-
No
results.txt
string

veracode_prepare_artifacts

This command collects app artifacts and creates a zip file which is then used by veracode SAST scan.

Show command Source
PARAMETER
DESCRIPTION
REQUIRED
DEFAULT
TYPE
additional_docker_build_args
-
No
''
string
docker_image_app_dir
Directory inside the docker image where the application artifacts are saved
No
/app
string

wait_till_ready

Wait for a specified port to be ready i.e. has started listening for requests. Defaults to 4566 - localstack default port. Requires curl to be installed in the image.

Show command Source
PARAMETER
DESCRIPTION
REQUIRED
DEFAULT
TYPE
host
-
No
localhost
string
port
-
No
4566
integer

wait_till_ready_postgres

Wait for postgres to be ready. Defaults to port 5432 on localhost.

Show command Source
PARAMETER
DESCRIPTION
REQUIRED
DEFAULT
TYPE
host
-
No
localhost
string
port
-
No
5432
integer

Executors

default

Default executor for deployment jobs

Show executor Source
PARAMETER
DESCRIPTION
REQUIRED
DEFAULT
TYPE
resource_class
-
No
medium
string
tag
-
Yes
-
string

default_small

Executor for deployment jobs using the small resource class

Show executor Source
PARAMETER
DESCRIPTION
REQUIRED
DEFAULT
TYPE
tag
-
Yes
-
string

java

Show executor Source
PARAMETER
DESCRIPTION
REQUIRED
DEFAULT
TYPE
java_options
-
No
>- -Xmx512m -XX:ParallelGCThreads=2 -XX:ConcGCThreads=2 -Djava.util.concurrent.ForkJoinPool.common.parallelism=2 -Dorg.gradle.daemon=false -Dkotlin.compiler.execution.strategy=in-process
string
resource_class
-
No
medium
string
tag
-
Yes
-
string

java_localstack_postgres

Show executor Source
PARAMETER
DESCRIPTION
REQUIRED
DEFAULT
TYPE
java_options
-
No
>- -Xmx512m -XX:ParallelGCThreads=2 -XX:ConcGCThreads=2 -Djava.util.concurrent.ForkJoinPool.common.parallelism=2 -Dorg.gradle.daemon=false -Dkotlin.compiler.execution.strategy=in-process -Dorg.gradle.workers.max=1
string
jdk_tag
-
Yes
-
string
localstack_tag
-
Yes
-
string
localstack_type
-
No
localstack
string
postgres_password
-
No
dev
string
postgres_port
-
No
5432
integer
postgres_tag
-
Yes
-
string
postgres_username
-
No
root
string
resource_class
-
No
medium
string
services
-
No
sqs,sns
string

java_localstack_postgres_with_db_name

Show executor Source
PARAMETER
DESCRIPTION
REQUIRED
DEFAULT
TYPE
java_options
-
No
>- -Xmx512m -XX:ParallelGCThreads=2 -XX:ConcGCThreads=2 -Djava.util.concurrent.ForkJoinPool.common.parallelism=2 -Dorg.gradle.daemon=false -Dkotlin.compiler.execution.strategy=in-process -Dorg.gradle.workers.max=1
string
jdk_tag
-
Yes
-
string
localstack_tag
-
Yes
-
string
localstack_type
-
No
localstack
string
postgres_db
-
No
postgres
string
postgres_password
-
No
dev
string
postgres_port
-
No
5432
integer
postgres_tag
-
Yes
-
string
postgres_username
-
No
root
string
resource_class
-
No
medium
string
services
-
No
sqs,sns
string

java_mssql

Show executor Source
PARAMETER
DESCRIPTION
REQUIRED
DEFAULT
TYPE
java_options
-
No
>- -Xmx512m -XX:ParallelGCThreads=2 -XX:ConcGCThreads=2 -Djava.util.concurrent.ForkJoinPool.common.parallelism=2 -Dorg.gradle.daemon=false -Dkotlin.compiler.execution.strategy=in-process -Dorg.gradle.workers.max=1
string
jdk_tag
-
Yes
-
string
mssql_tag
-
Yes
-
string
resource_class
-
No
medium
string
sa_password
-
No
yourStrong(!)Password
string

java_postgres

Show executor Source
PARAMETER
DESCRIPTION
REQUIRED
DEFAULT
TYPE
java_options
-
No
>- -Xmx512m -XX:ParallelGCThreads=2 -XX:ConcGCThreads=2 -Djava.util.concurrent.ForkJoinPool.common.parallelism=2 -Dorg.gradle.daemon=false -Dkotlin.compiler.execution.strategy=in-process -Dorg.gradle.workers.max=1
string
jdk_tag
-
Yes
-
string
postgres_db
-
No
postgres
string
postgres_password
-
No
dev
string
postgres_port
-
No
5432
integer
postgres_tag
-
Yes
-
string
postgres_username
-
No
root
string
resource_class
-
No
medium
string

localstack

Show executor Source
PARAMETER
DESCRIPTION
REQUIRED
DEFAULT
TYPE
java_options
-
No
>- -Xmx512m -XX:ParallelGCThreads=2 -XX:ConcGCThreads=2 -Djava.util.concurrent.ForkJoinPool.common.parallelism=2 -Dorg.gradle.daemon=false -Dkotlin.compiler.execution.strategy=in-process -Dorg.gradle.workers.max=1
string
jdk_tag
-
Yes
-
string
localstack_tag
-
Yes
-
string
localstack_type
-
No
localstack
string
resource_class
-
No
medium
string
services
-
No
sqs,sns
string

node

Default executor for node.js jobs

Show executor Source
PARAMETER
DESCRIPTION
REQUIRED
DEFAULT
TYPE
resource_class
-
No
medium
string
tag
-
Yes
-
string

node_redis

Executor for node.js jobs with redis image

Show executor Source
PARAMETER
DESCRIPTION
REQUIRED
DEFAULT
TYPE
node_tag
-
Yes
-
string
redis_tag
-
Yes
-
string
resource_class
-
No
medium
string

node_redis_postgres

Executor for node.js jobs with redis and postgres image

Show executor Source
PARAMETER
DESCRIPTION
REQUIRED
DEFAULT
TYPE
node_tag
-
Yes
-
string
postgres_db
-
No
postgres
string
postgres_password
-
No
dev
string
postgres_port
-
No
5432
integer
postgres_tag
-
Yes
-
string
postgres_username
-
No
root
string
redis_tag
-
Yes
-
string
resource_class
-
No
medium
string

Orb Source

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 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 # This code is licensed from CircleCI to the user under the MIT license. # See here for details: https://circleci.com/developer/orbs/licensing version: 2.1 description: | HMPPS projects reusable circleci config display: home_url: https://github.com/ministryofjustice/hmpps-circleci-orb source_url: https://github.com/ministryofjustice/hmpps-circleci-orb orbs: aws-cli: circleci/aws-cli@1.2.1 gradle: circleci/gradle@2.2.0 helm: circleci/helm@1.2.0 jira: circleci/jira@2.1.0 kubernetes: circleci/kubernetes@1.3.0 mem: circleci/rememborb@0.0.2 owasp: entur/owasp@0.0.17 slack: circleci/slack@4.12.5 snyk: snyk/snyk@1.1.2 commands: create_app_version: description: | Creates an application version string, formatted [DATE].[CIRCLE_BUILD_NUM].[SHORT_SHA1] e.g 2020-04-24.487.fb30e99" Also uses mem/rememborb orb to remember the version as the env var APP_VERSION - which can be recalled in subsequent steps or jobs e.g. mem/recall steps: - run: command: | DATE=$(date '+%Y-%m-%d') SHORT_SHA1=$(echo $CIRCLE_SHA1 | cut -c1-7) VERSION=${DATE}.${CIRCLE_BUILD_NUM}.${SHORT_SHA1} echo "Created version string: ${VERSION}" echo "export VERSION=$VERSION" >> $BASH_ENV name: Create app version string - mem/remember: env_var: APP_VERSION value: ${VERSION} install_aws_cli: description: Install AWS cli parameters: version: default: "2" enum: - "1" - "2" type: enum steps: - aws-cli/install: version: <<parameters.version>> install_git_lfs: description: Install Git LFS steps: - run: command: | curl -s https://packagecloud.io/install/repositories/github/git-lfs/script.deb.sh | sudo bash DEBIAN_FRONTEND=noninteractive sudo apt-get install -y --no-install-recommends git-lfs git lfs install name: Install Git LFS install_helm: description: Install helm client parameters: version: default: v3.4.2 type: string steps: - helm/install-helm-client: version: <<parameters.version>> install_trivy: description: Install Trivy steps: - run: command: | curl -sfL https://raw.githubusercontent.com/aquasecurity/trivy/main/contrib/install.sh | sh -s -- -b /tmp name: Install Trivy k8s_setup: description: Install kubectl and configure parameters: ca-cert: default: KUBE_ENV_CACERT type: env_var_name cluster-name: default: KUBE_ENV_NAME type: env_var_name kube-api: default: KUBE_ENV_API type: env_var_name kube-namespace: default: KUBE_ENV_NAMESPACE type: env_var_name kube-token: default: KUBE_ENV_TOKEN type: env_var_name kube-user: default: circleci type: string steps: - kubernetes/install - run: command: | echo -n "${<<parameters.ca-cert>>}" | base64 -d > /tmp/cluster_ca.crt kubectl config set-cluster "${<<parameters.cluster-name>>}" \ --certificate-authority="/tmp/cluster_ca.crt" \ --server="${<<parameters.kube-api>>}" kubectl config set-credentials <<parameters.kube-user>> \ --token="${<<parameters.kube-token>>}" kubectl config set-context circleci \ --cluster="${<<parameters.cluster-name>>}" \ --user="<<parameters.kube-user>>" \ --namespace="${<<parameters.kube-namespace>>}" kubectl config use-context circleci name: Setup kubectl recall_container_image: description: | Recalls the built container image (tagged as "${IMAGE_NAME}:${APP_VERSION}" in the environment) within the circleci workspace so that it can be used in a subsequent job. NOTE: You MUST have ran your `build_docker` job with the parameter `persist_container_image` set to `true`. steps: - attach_workspace: at: ~/app - run: command: docker load --input docker_cache/build_image.tar name: Extract saved container image - mem/recall: env_var: IMAGE_NAME - mem/recall: env_var: APP_VERSION slack_message_results: description: | Takes a text file containing output/results and turn into an environment variable which is suitable for interpolating into a slack custom message template. All slack special chars converted to html entities. Non json friendly chars are escaped. parameters: env_var: default: SLACK_TXT type: string file: default: results.txt type: string steps: - run: command: | if [[ -f << parameters.file >> ]]; then echo "Processing file: << parameters.file >>" echo "Exporting to env var: << parameters.env_var >>" SLACK_TXT=$(cat << parameters.file >> | \ sed 's/&/\&amp;/g; s/</\&lt;/g; s/>/\&gt;/g;' | \ jq -Rs . | \ sed -E 's/("$)|(^")//g') echo "export << parameters.env_var >>='${SLACK_TXT}'" >> $BASH_ENV else echo "File not found: << parameters.file >>" fi name: Slack - Process Results Text when: always veracode_prepare_artifacts: description: | This command collects app artifacts and creates a zip file which is then used by veracode SAST scan. parameters: additional_docker_build_args: default: "" type: string docker_image_app_dir: default: /app description: Directory inside the docker image where the application artifacts are saved type: string steps: - setup_remote_docker: docker_layer_caching: true - checkout - run: command: | export DOCKER_BUILDKIT=1 IMAGE_ID=$(docker build -q . --build-arg BUILD_NUMBER=$CIRCLE_SHA1 --build-arg GIT_REF=$CIRCLE_SHA1 --build-arg GIT_BRANCH=$CIRCLE_BRANCH << parameters.additional_docker_build_args >>) docker cp $(docker create --rm ${IMAGE_ID}):<< parameters.docker_image_app_dir >> ./temp_app name: Build temp docker image and copy app files no_output_timeout: 20m - run: command: | cd temp_app zip -r ../source.zip . -x "*node_modules*" -x "*agent.jar*" -x "*vendor/bundle*" name: Zip files ready for Veracode scan wait_till_ready: description: Wait for a specified port to be ready i.e. has started listening for requests. Defaults to 4566 - localstack default port. Requires curl to be installed in the image. parameters: host: default: localhost type: string port: default: 4566 type: integer steps: - run: command: curl -4 --connect-timeout 30 --retry-connrefused --retry 20 --retry-delay 5 http://<<parameters.host>>:<<parameters.port>> name: Wait for port to be ready wait_till_ready_postgres: description: Wait for postgres to be ready. Defaults to port 5432 on localhost. parameters: host: default: localhost type: string port: default: 5432 type: integer steps: - run: command: | COMMAND="pg_isready -h <<parameters.host>> -p <<parameters.port>>" for i in {1..10}; do $COMMAND && break sleep 5 done $COMMAND name: Wait for postgres to be ready executors: default: description: | Default executor for deployment jobs docker: - image: cimg/python:<<parameters.tag>> parameters: resource_class: default: medium type: string tag: type: string resource_class: <<parameters.resource_class>> working_directory: ~/app default_small: description: | Executor for deployment jobs using the small resource class docker: - image: cimg/python:<<parameters.tag>> parameters: tag: type: string resource_class: small working_directory: ~/app java: docker: - image: cimg/openjdk:<<parameters.tag>> environment: _JAVA_OPTIONS: <<parameters.java_options>> parameters: java_options: default: -Xmx512m -XX:ParallelGCThreads=2 -XX:ConcGCThreads=2 -Djava.util.concurrent.ForkJoinPool.common.parallelism=2 -Dorg.gradle.daemon=false -Dkotlin.compiler.execution.strategy=in-process type: string resource_class: default: medium type: string tag: type: string resource_class: <<parameters.resource_class>> working_directory: ~/app java_localstack_postgres: docker: - image: cimg/openjdk:<<parameters.jdk_tag>> - environment: - SERVICES=<<parameters.services>> - ES_PORT_EXTERNAL=4571 - DEBUG=${DEBUG- } - DOCKER_HOST=unix:///var/run/docker.sock - AWS_EXECUTION_ENV=True - PERSISTENCE=1 image: localstack/<<parameters.localstack_type>>:<<parameters.localstack_tag>> - environment: - POSTGRES_PASSWORD=<< parameters.postgres_password >> - POSTGRES_USER=<< parameters.postgres_username >> - PGPORT=<< parameters.postgres_port >> image: postgres:<< parameters.postgres_tag >> environment: _JAVA_OPTIONS: <<parameters.java_options>> parameters: java_options: default: -Xmx512m -XX:ParallelGCThreads=2 -XX:ConcGCThreads=2 -Djava.util.concurrent.ForkJoinPool.common.parallelism=2 -Dorg.gradle.daemon=false -Dkotlin.compiler.execution.strategy=in-process -Dorg.gradle.workers.max=1 type: string jdk_tag: type: string localstack_tag: type: string localstack_type: default: localstack type: string postgres_password: default: dev type: string postgres_port: default: 5432 type: integer postgres_tag: type: string postgres_username: default: root type: string resource_class: default: medium type: string services: default: sqs,sns type: string resource_class: <<parameters.resource_class>> working_directory: ~/app java_localstack_postgres_with_db_name: docker: - image: cimg/openjdk:<<parameters.jdk_tag>> - environment: - SERVICES=<<parameters.services>> - ES_PORT_EXTERNAL=4571 - DEBUG=${DEBUG- } - DOCKER_HOST=unix:///var/run/docker.sock - AWS_EXECUTION_ENV=True - PERSISTENCE=1 image: localstack/<<parameters.localstack_type>>:<<parameters.localstack_tag>> - environment: - POSTGRES_PASSWORD=<< parameters.postgres_password >> - POSTGRES_USER=<< parameters.postgres_username >> - POSTGRES_DB=<< parameters.postgres_db >> - PGPORT=<< parameters.postgres_port >> image: postgres:<< parameters.postgres_tag >> environment: _JAVA_OPTIONS: <<parameters.java_options>> parameters: java_options: default: -Xmx512m -XX:ParallelGCThreads=2 -XX:ConcGCThreads=2 -Djava.util.concurrent.ForkJoinPool.common.parallelism=2 -Dorg.gradle.daemon=false -Dkotlin.compiler.execution.strategy=in-process -Dorg.gradle.workers.max=1 type: string jdk_tag: type: string localstack_tag: type: string localstack_type: default: localstack type: string postgres_db: default: postgres type: string postgres_password: default: dev type: string postgres_port: default: 5432 type: integer postgres_tag: type: string postgres_username: default: root type: string resource_class: default: medium type: string services: default: sqs,sns type: string resource_class: <<parameters.resource_class>> working_directory: ~/app java_mssql: docker: - image: cimg/openjdk:<<parameters.jdk_tag>> - environment: - SA_PASSWORD=<<parameters.sa_password>> - ACCEPT_EULA=y - DOCKER_HOST=unix:///var/run/docker.sock - TMPDIR=/private image: mcr.microsoft.com/mssql/server:<<parameters.mssql_tag>> environment: _JAVA_OPTIONS: <<parameters.java_options>> parameters: java_options: default: -Xmx512m -XX:ParallelGCThreads=2 -XX:ConcGCThreads=2 -Djava.util.concurrent.ForkJoinPool.common.parallelism=2 -Dorg.gradle.daemon=false -Dkotlin.compiler.execution.strategy=in-process -Dorg.gradle.workers.max=1 type: string jdk_tag: type: string mssql_tag: type: string resource_class: default: medium type: string sa_password: default: yourStrong(!)Password type: string resource_class: <<parameters.resource_class>> working_directory: ~/app java_postgres: docker: - image: cimg/openjdk:<<parameters.jdk_tag>> - environment: - POSTGRES_PASSWORD=<< parameters.postgres_password >> - POSTGRES_USER=<< parameters.postgres_username >> - POSTGRES_DB=<< parameters.postgres_db >> - PGPORT=<< parameters.postgres_port >> image: postgres:<< parameters.postgres_tag >> environment: _JAVA_OPTIONS: <<parameters.java_options>> parameters: java_options: default: -Xmx512m -XX:ParallelGCThreads=2 -XX:ConcGCThreads=2 -Djava.util.concurrent.ForkJoinPool.common.parallelism=2 -Dorg.gradle.daemon=false -Dkotlin.compiler.execution.strategy=in-process -Dorg.gradle.workers.max=1 type: string jdk_tag: type: string postgres_db: default: postgres type: string postgres_password: default: dev type: string postgres_port: default: 5432 type: integer postgres_tag: type: string postgres_username: default: root type: string resource_class: default: medium type: string resource_class: <<parameters.resource_class>> working_directory: ~/app localstack: docker: - image: cimg/openjdk:<<parameters.jdk_tag>> - environment: - SERVICES=<<parameters.services>> - ES_PORT_EXTERNAL=4571 - DEBUG=${DEBUG- } - DOCKER_HOST=unix:///var/run/docker.sock - AWS_EXECUTION_ENV=True - PERSISTENCE=1 image: localstack/<<parameters.localstack_type>>:<<parameters.localstack_tag>> environment: _JAVA_OPTIONS: <<parameters.java_options>> parameters: java_options: default: -Xmx512m -XX:ParallelGCThreads=2 -XX:ConcGCThreads=2 -Djava.util.concurrent.ForkJoinPool.common.parallelism=2 -Dorg.gradle.daemon=false -Dkotlin.compiler.execution.strategy=in-process -Dorg.gradle.workers.max=1 type: string jdk_tag: type: string localstack_tag: type: string localstack_type: default: localstack type: string resource_class: default: medium type: string services: default: sqs,sns type: string resource_class: <<parameters.resource_class>> working_directory: ~/app node: description: | Default executor for node.js jobs docker: - image: cimg/node:<<parameters.tag>> parameters: resource_class: default: medium type: string tag: type: string resource_class: <<parameters.resource_class>> working_directory: ~/app node_redis: description: | Executor for node.js jobs with redis image docker: - image: cimg/node:<<parameters.node_tag>> - image: cimg/redis:<<parameters.redis_tag>> parameters: node_tag: type: string redis_tag: type: string resource_class: default: medium type: string resource_class: <<parameters.resource_class>> working_directory: ~/app node_redis_postgres: description: | Executor for node.js jobs with redis and postgres image docker: - image: cimg/node:<<parameters.node_tag>> - image: cimg/redis:<<parameters.redis_tag>> - environment: - POSTGRES_PASSWORD=<< parameters.postgres_password >> - POSTGRES_USER=<< parameters.postgres_username >> - POSTGRES_DB=<< parameters.postgres_db >> - PGPORT=<< parameters.postgres_port >> image: cimg/postgres:<< parameters.postgres_tag >> parameters: node_tag: type: string postgres_db: default: postgres type: string postgres_password: default: dev type: string postgres_port: default: 5432 type: integer postgres_tag: type: string postgres_username: default: root type: string redis_tag: type: string resource_class: default: medium type: string resource_class: <<parameters.resource_class>> working_directory: ~/app jobs: build_docker: description: | Build docker image, also creates an app version string and pushes image to repo. executor: name: default tag: "3.10" parameters: additional_docker_build_args: default: "" type: string additional_docker_tag: default: "" description: Additional docker tag that can be used to specify stable tags type: string dockerfile_dir: default: . type: string git-lfs: default: false type: boolean image_name: default: quay.io/hmpps/${CIRCLE_PROJECT_REPONAME} type: string jira_update: default: false description: When true, updates any referenced Jira tickets with build status. Note that Jira integration must be enabled in your CircleCI project settings. type: boolean no_output_timeout: default: 30m description: Configure the no_output_timeout setting for the container build step type: string persist_container_image: default: false description: Make the built container image available for subsequent jobs type: boolean pipeline_id: default: "" description: Required if jira_update is set (otherwise the Notify Jira job will pass but do nothing), passed in as << pipeline.id >> type: string pipeline_number: default: 0 description: Required if jira_update is set, passed in as << pipeline.number >> type: integer publish: default: true type: boolean snyk-args: default: "" type: string snyk-fail-build: default: true type: boolean snyk-org: default: digital-probation-services type: string snyk-scan: default: false type: boolean snyk-target-file: default: Dockerfile type: string snyk-threshold: default: high enum: - low - medium - high type: enum steps: - when: condition: << parameters.git-lfs >> steps: - install_git_lfs - checkout - setup_remote_docker: docker_layer_caching: true - create_app_version - run: command: | IMAGE_NAME="<< parameters.image_name >>" echo "export IMAGE_NAME=$IMAGE_NAME" >> $BASH_ENV name: Create IMAGE_NAME env var - mem/remember: env_var: IMAGE_NAME value: ${IMAGE_NAME} - run: command: | docker build --pull \ --rm=false << parameters.dockerfile_dir >> \ --build-arg BUILD_NUMBER=$APP_VERSION \ --build-arg GIT_REF=$CIRCLE_SHA1 \ --build-arg GIT_BRANCH=$CIRCLE_BRANCH \ --tag "${IMAGE_NAME}:${APP_VERSION}" \ --label "maintainer=dps-hmpps@digital.justice.gov.uk" \ --label "app.version=${APP_VERSION}" \ --label "build.version=${APP_VERSION}" \ --label "build.number=${CIRCLE_BUILD_NUM}" \ --label "build.url=${CIRCLE_BUILD_URL}" \ --label "build.gitref=${CIRCLE_SHA1}" \ << parameters.additional_docker_build_args >> name: Build container image no_output_timeout: << parameters.no_output_timeout >> - when: condition: << parameters.persist_container_image >> steps: - run: command: | mkdir -p docker_cache docker save ${IMAGE_NAME}:${APP_VERSION} -o docker_cache/build_image.tar name: Persist container image to workspace - persist_to_workspace: paths: - docker_cache root: ~/app - when: condition: << parameters.snyk-scan >> steps: - snyk/scan: additional-arguments: << parameters.snyk-args >> docker-image-name: ${IMAGE_NAME}:${APP_VERSION} fail-on-issues: << parameters.snyk-fail-build >> monitor-on-build: << parameters.publish >> organization: << parameters.snyk-org >> project: ${CIRCLE_PROJECT_REPONAME}-docker severity-threshold: << parameters.snyk-threshold >> target-file: << parameters.dockerfile_dir >>/<< parameters.snyk-target-file >> - when: condition: <<parameters.publish>> steps: - run: command: | #push to quay.io docker login -u="${QUAYIO_USERNAME}" -p="${QUAYIO_PASSWORD}" quay.io docker tag "<< parameters.image_name >>:${APP_VERSION}" "<< parameters.image_name >>:latest" docker push "<< parameters.image_name >>:${APP_VERSION}" docker push "<< parameters.image_name >>:latest" TAG="<< parameters.additional_docker_tag >>" echo "export TAG=$TAG" >> $BASH_ENV NUM=$(echo -n $TAG | wc -c) echo "export NUM=$NUM" >> $BASH_ENV if [ $NUM -gt 0 ]; then docker tag "<< parameters.image_name >>:${APP_VERSION}" "<< parameters.image_name >>:<< parameters.additional_docker_tag >>" docker push "<< parameters.image_name >>:<< parameters.additional_docker_tag >>" fi name: Publish image to repository - when: condition: << parameters.jira_update >> steps: - jira/notify: pipeline_id: << parameters.pipeline_id >> pipeline_number: << parameters.pipeline_number >> build_multiplatform_docker: description: | Build docker image, also creates an app version string and pushes image to repo. executor: name: default tag: "3.10" parameters: additional_docker_build_args: default: "" type: string dockerfile_dir: default: . type: string git-lfs: default: false type: boolean image_name: default: quay.io/hmpps/${CIRCLE_PROJECT_REPONAME} type: string jira_update: default: false description: When true, updates any referenced Jira tickets with build status. Note that Jira integration must be enabled in your CircleCI project settings. type: boolean no_output_timeout: default: 30m description: Configure the no_output_timeout setting for the container build step type: string pipeline_id: default: "" description: Required if jira_update is set (otherwise the Notify Jira job will pass but do nothing), passed in as << pipeline.id >> type: string pipeline_number: default: 0 description: Required if jira_update is set, passed in as << pipeline.number >> type: integer snyk-args: default: "" type: string snyk-fail-build: default: true type: boolean snyk-org: default: digital-probation-services type: string snyk-scan: default: false type: boolean snyk-target-file: default: Dockerfile type: string snyk-threshold: default: high enum: - low - medium - high type: enum steps: - when: condition: << parameters.git-lfs >> steps: - install_git_lfs - checkout - setup_remote_docker: docker_layer_caching: true - create_app_version - run: command: | IMAGE_NAME="<< parameters.image_name >>" echo "export IMAGE_NAME=$IMAGE_NAME" >> $BASH_ENV name: Create IMAGE_NAME env var - mem/remember: env_var: IMAGE_NAME value: ${IMAGE_NAME} - run: command: | docker context create multi-arch-build docker run --rm --privileged multiarch/qemu-user-static --reset -p yes docker run --rm --privileged tonistiigi/binfmt --install all docker buildx create --use multi-arch-build --platform linux/arm64,linux/amd64 --name="${CIRCLE_PROJECT_REPONAME}" name: Setup buildx - run: command: docker login -u="${QUAYIO_USERNAME}" -p="${QUAYIO_PASSWORD}" quay.io name: quay.io login - run: command: | docker buildx build \ --platform linux/amd64,linux/arm64 --pull \ --progress plain \ --rm=false << parameters.dockerfile_dir >> \ --build-arg BUILD_NUMBER=$APP_VERSION \ --build-arg GIT_REF=$CIRCLE_SHA1 \ --build-arg GIT_BRANCH=$CIRCLE_BRANCH \ --tag "${IMAGE_NAME}:${APP_VERSION}" \ --tag "${IMAGE_NAME}:latest" \ --label "maintainer=dps-hmpps@digital.justice.gov.uk" \ --label "app.version=${APP_VERSION}" \ --label "build.version=${APP_VERSION}" \ --label "build.number=${CIRCLE_BUILD_NUM}" \ --label "build.url=${CIRCLE_BUILD_URL}" \ --label "build.gitref=${CIRCLE_SHA1}" \ --push \ << parameters.additional_docker_build_args >> name: Build and publish container image no_output_timeout: << parameters.no_output_timeout >> - when: condition: << parameters.snyk-scan >> steps: - snyk/scan: additional-arguments: << parameters.snyk-args >> docker-image-name: ${IMAGE_NAME}:${APP_VERSION} fail-on-issues: << parameters.snyk-fail-build >> monitor-on-build: true organization: << parameters.snyk-org >> project: ${CIRCLE_PROJECT_REPONAME}-docker severity-threshold: << parameters.snyk-threshold >> target-file: << parameters.dockerfile_dir >>/<< parameters.snyk-target-file >> - when: condition: << parameters.jira_update >> steps: - jira/notify: pipeline_id: << parameters.pipeline_id >> pipeline_number: << parameters.pipeline_number >> database_schema_report: description: | Job to generate a schema report for a postgres database using schemaspy. Runs against postgres in docker An HTML report is generated and is available on the artifacts tab of the circleci job executor: jdk_tag: << parameters.jdk_tag >> localstack_tag: << parameters.localstack_tag >> name: java_localstack_postgres_with_db_name postgres_db: << parameters.database_name >> postgres_password: << parameters.password >> postgres_port: << parameters.port >> postgres_tag: << parameters.postgres_tag >> postgres_username: << parameters.user >> parameters: database_name: default: postgres description: Name of the database type: string host: default: localhost description: Host name of the database type: string initialise_database: default: ./gradlew check description: A command which will initialise the database schema type: string jdk_tag: default: "21.0" type: string localstack_tag: default: "3.0" type: string password: default: dev description: Database password type: string port: default: 5432 description: Port number of the database type: integer postgres_driver_version: default: 42.7.3 description: Postgres driver version type: string postgres_tag: default: "16.1" type: string schema: default: public description: Schema name type: string schemaspy_version: default: 6.2.4 description: Schemaspy version type: string user: default: root description: Database user name type: string steps: - checkout - run: command: curl -L https://github.com/schemaspy/schemaspy/releases/download/v<< parameters.schemaspy_version >>/schemaspy-<< parameters.schemaspy_version >>.jar --output /tmp/schemaspy.jar name: Install schemaspy - run: command: curl -L https://jdbc.postgresql.org/download/postgresql-<< parameters.postgres_driver_version >>.jar --output /tmp/postgres-driver.jar name: Install postgres jdbc driver - run: command: << parameters.initialise_database >> name: Execute a command to initialise the database schema - run: command: | java -jar /tmp/schemaspy.jar \ -t pgsql \ -dp /tmp/postgres-driver.jar \ -db << parameters.database_name >> \ -host << parameters.host >> \ -port << parameters.port >> \ -s << parameters.schema >> \ -vizjs \ -u << parameters.user >> \ -p << parameters.password >> \ -o /tmp/schemaspy name: Generate database schema report - run: command: | echo '<html><head><meta http-equiv="refresh" content="0; url=report/index.html" /></head><body><a href="report/index.html">Open Schema Report</a></body></html>' > /tmp/index.html name: generate index file - store_artifacts: destination: schema/index.html path: /tmp/index.html - store_artifacts: destination: schema/report path: /tmp/schemaspy deploy_env: description: | Deploy via helm, using chart found in the helm_deploy dir of the repo. Optionally send a slack notification. executor: name: default_small tag: "3.10" parameters: changelog_git_paths: default: "" description: When set it will limit the file changes shown in the changelog to the specified paths only. This is useful for multi-project builds where otherwise it will show all changes from all projects. type: string chart_name: default: PROJECT_NAME type: string chart_version: default: latest type: string env: default: dev type: string helm_additional_args: default: "" type: string helm_dir: default: helm_deploy type: string helm_repo: default: local description: For using non local helm chart set to URL of helm repo type: string helm_timeout: default: 5m type: string jira_env_type: default: development description: Environment type to use when updating Jira enum: - production - staging - testing - development - unmapped type: enum jira_update: default: false description: When true, updates any referenced Jira tickets with deployment information. Note that Jira integration must be enabled in your CircleCI project settings. type: boolean k8s_deployment_name: default: PROJECT_NAME description: The Deployment resource's name in Kubernetes to interrogate for the previous deployment's version type: string pipeline_id: default: "" description: Required if jira_update is set (otherwise the Notify Jira job will pass but do nothing), passed in as << pipeline.id >> type: string pipeline_number: default: 0 description: Required if jira_update is set, passed in as << pipeline.number >> type: integer release_name: default: PROJECT_NAME type: string show_changelog: default: true description: When true, displays what is new since the previous deployment in the job, and in Slack, if applicable type: boolean slack_channel_name: default: dps-releases description: Slack channel to use for deployment notifications. type: string slack_notification: default: false description: When true, notifies a Slack channel after every deployment done with this job. type: boolean steps: - checkout - k8s_setup - install_helm - install_aws_cli - mem/recall: env_var: APP_VERSION - when: condition: <<parameters.show_changelog>> steps: - run: command: | #!/usr/bin/env bash # ensure consequences still work if this script blows up touch .deployment_changelog if [[ "${K8S_DEPLOYMENT_NAME}" == "PROJECT_NAME" ]]; then K8S_DEPLOYMENT_NAME="${CIRCLE_PROJECT_REPONAME}" fi current_commit="$(echo "${APP_VERSION}" | cut -d'.' -f3)" # Try and get the currently deployed version K8S_PREVIOUS_APP_VERSION="$(kubectl get "deployment/${K8S_DEPLOYMENT_NAME}" --namespace="${KUBE_ENV_NAMESPACE}" -o=jsonpath='{.metadata.labels.app\.kubernetes\.io/version}' || true)" if [[ "$K8S_PREVIOUS_APP_VERSION" == "" ]]; then # if no previous version was found, set to current commit minus 1 echo "Previous deployment not found, showing current commit only." >> .deployment_changelog previous_commit="${current_commit}^1" else previous_commit="$(echo "${K8S_PREVIOUS_APP_VERSION}" | cut -d'.' -f3)" fi # Some apps may not have set the correct k8s label with a valid app version containing a sha1 # Check $previous_commit sha1 is valid if git rev-parse --quiet --verify "${previous_commit}" &>/dev/null; then # shellcheck disable=SC2086 PAGER="cat" git log --oneline --no-decorate \ --pretty=format:'%h %s (%cr)' --committer='noreply@github.com' --grep='#' \ "${previous_commit}..${current_commit}" $CHANGELOG_GIT_PATHS \ | sed 's/Merge pull request /PR /g; s|from ministryofjustice/dependabot/|:dependabot:|g; s|from ministryofjustice/||g' \ | tr '"' "'" | tr "\`" "'" \ >> .deployment_changelog else echo "Changelog not available." > .deployment_changelog fi cat .deployment_changelog environment: CHANGELOG_GIT_PATHS: << parameters.changelog_git_paths >> K8S_DEPLOYMENT_NAME: << parameters.k8s_deployment_name >> name: Show changes about to be released on << parameters.env >> - run: command: | echo 'export DEPLOYMENT_CHANGELOG=$(<.deployment_changelog)' >> $BASH_ENV name: Store deployment changelog - mem/recall: env_var: APP_VERSION - run: command: | #!/usr/bin/env bash if [[ ${RELEASE_NAME} == "PROJECT_NAME_ENV_NAME" ]]; then RELEASE_NAME="${CIRCLE_PROJECT_REPONAME}-${ENV_NAME}" elif [[ ${RELEASE_NAME} == "PROJECT_NAME" ]]; then RELEASE_NAME="${CIRCLE_PROJECT_REPONAME}" fi if [[ ${CHART_NAME} == "PROJECT_NAME" ]]; then CHART_NAME="${CIRCLE_PROJECT_REPONAME}" fi if [[ ${HELM_REPO} != "local" ]]; then helm repo add remote "${HELM_REPO}" CHART_NAME="remote/${CHART_NAME}" else # this is a hack to allow seeing the actual app version in the helm release metadata sed -i "s/appVersion:.*/appVersion: \"${APP_VERSION}\"/g" "${CHART_NAME}/Chart.yaml" fi # Install/update any chart dependencies. helm dependency update "${CHART_NAME}" HELM_ARGS=(--wait \ --install \ --reset-values \ --timeout "${HELM_TIMEOUT}" \ --history-max 10 \ --values "values-${ENV_NAME}.yaml" \ --set "global.environment=${ENV_NAME}") # See https://github.com/ministryofjustice/hmpps-ip-allowlists if [[ -n ${IP_ALLOWLIST_GROUPS_YAML} ]]; then echo "${IP_ALLOWLIST_GROUPS_YAML}" | base64 --decode > ip-allowlist-groups.yaml HELM_ARGS+=("--values" "ip-allowlist-groups.yaml") fi if [[ -n ${IP_ALLOWLIST_GROUPS_VERSION} ]]; then HELM_ARGS+=("--set" "generic-service.allowlist_version=${IP_ALLOWLIST_GROUPS_VERSION}") fi # Set the image tag for this deployment # Add debugging output set -x if ! helm dependency list "${CHART_NAME}" | grep generic-service; then HELM_ARGS+=("--set" "image.tag=${APP_VERSION}") else HELM_ARGS+=("--set" "generic-service.image.tag=${APP_VERSION}") fi set +x read -r -a extra_args \<<< "${HELM_ADDITIONAL_ARGS}" HELM_ARGS+=("${extra_args[@]}") if [[ ${CHART_VERSION} != "latest" ]]; then HELM_ARGS+=("--version" "${CHART_VERSION}") fi helm upgrade "${RELEASE_NAME}" "${CHART_NAME}" "${HELM_ARGS[@]}" # store release name for use by slack notification echo "export RELEASE_NAME=$RELEASE_NAME" >> "$BASH_ENV" environment: CHART_NAME: << parameters.chart_name >> CHART_VERSION: << parameters.chart_version >> ENV_NAME: << parameters.env >> HELM_ADDITIONAL_ARGS: << parameters.helm_additional_args >> HELM_REPO: << parameters.helm_repo >> HELM_TIMEOUT: << parameters.helm_timeout >> RELEASE_NAME: << parameters.release_name >> name: Deploy to << parameters.env >> working_directory: << parameters.helm_dir >> - when: condition: <<parameters.slack_notification>> steps: - run: command: | # For prod releases only always notify central dps-releases channel in addition to custom team channels. if [[ "<< parameters.env >>" == "prod" || "<< parameters.env >>" == "production" ]]; then # By default send to channel ID CVA3MKDTR = #dps-releases if [[ "<< parameters.slack_channel_name >>" == "CVA3MKDTR" || "<< parameters.slack_channel_name >>" == "dps-releases" ]]; then NOTIFY_SLACK_CHANNELS="CVA3MKDTR" else # Also send to custom team channel NOTIFY_SLACK_CHANNELS="CVA3MKDTR,<< parameters.slack_channel_name >>" fi else # non prod envs, send to custom team channel. NOTIFY_SLACK_CHANNELS="<< parameters.slack_channel_name >>" fi echo "export NOTIFY_SLACK_CHANNELS=$NOTIFY_SLACK_CHANNELS" >> $BASH_ENV name: Slack channels to notify - slack/notify: channel: ${NOTIFY_SLACK_CHANNELS} custom: | { "blocks": [ { "type": "section", "text": { "type": "mrkdwn", "text": "*${RELEASE_NAME}* version `${APP_VERSION}` deploy to *<< parameters.env >>*" }, "accessory": { "type": "button", "text": { "type": "plain_text", "text": "View job" }, "url": "${CIRCLE_BUILD_URL}" } }, { "type": "context", "elements": [ { "type": "mrkdwn", "text": ":circleci-${CCI_STATUS}: Deploy ${CCI_STATUS}" }, { "type": "plain_text", "text": "\n${DEPLOYMENT_CHANGELOG}" } ] } ] } event: always - when: condition: << parameters.jira_update >> steps: - jira/notify: environment: << parameters.env >> environment_type: << parameters.jira_env_type >> job_type: deployment pipeline_id: << parameters.pipeline_id >> pipeline_number: << parameters.pipeline_number >> gradle_owasp_dependency_check: description: | Job for running OWASP Dependency Check, looking for package dependencies with security vulnerabilities executor: java_options: <<parameters.java_options>> name: java tag: <<parameters.jdk_tag>> parameters: cache_key: default: v2 description: Specify a custom cache key. type: string cve_data_directory: default: ~/.gradle/dependency-check-data description: The plugin database directory. type: string java_options: default: -Xmx1024m -XX:ParallelGCThreads=2 -XX:ConcGCThreads=2 -Djava.util.concurrent.ForkJoinPool.common.parallelism=2 -Dorg.gradle.daemon=false -Dkotlin.compiler.execution.strategy=in-process type: string jdk_tag: default: "17.0" type: string no_output_timeout: default: 15m description: Specify period of time has passed with no output. type: string persist_to_workspace: default: false description: Persist reports to workspace for further processing. type: boolean slack_channel: default: dps_alerts_security description: Slack channel to use for notifications. type: string task: default: dependencyCheckAnalyze description: Task name. type: string steps: - checkout - gradle/with_cache: steps: - owasp/generate_cache_keys: cache_key: gradle-<< parameters.cache_key >>-cache-key - owasp/restore_owasp_cache: cache_key: << parameters.cache_key >> - run: command: ./gradlew dependencyCheckUpdate --info name: Update OWASP Dependency-Check Database - owasp/store_owasp_cache: cache_key: << parameters.cache_key >> cve_data_directory: <<parameters.cve_data_directory>> - run: command: ./gradlew <<parameters.task>> --info name: Run OWASP Dependency-Check Analyzer no_output_timeout: << parameters.no_output_timeout >> - run: command: ./gradlew dependencyCheckPurge --info name: OWASP Dependency-Check cache cleanup - owasp/collect_reports: persist_to_workspace: <<parameters.persist_to_workspace>> - slack/notify: channel: << parameters.slack_channel >> 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}" } } ] } event: fail helm_lint: description: | Helm lint - Check for syntax and render issues within the helm Chart executor: name: default_small tag: "3.10" parameters: chart_name: default: ${CIRCLE_PROJECT_REPONAME} type: string env: default: dev type: string helm_additional_args: default: "" type: string helm_dir: default: helm_deploy type: string steps: - checkout - install_helm - run: command: | helm dependency update << parameters.chart_name >> helm lint << parameters.chart_name >> --values=values-<< parameters.env >>.yaml << parameters.helm_additional_args >> name: Run helm lint working_directory: << parameters.helm_dir >> npm_outdated: description: | Node.js projects using npm - check if package dependencies are outdated executor: name: node tag: <<parameters.node_tag>> parameters: dependencies_to_check: default: typescript govuk-frontend description: Dependencies to check if they are outdated. type: string node_tag: default: "20.16" type: string slack_channel: default: dps_alerts_security description: Slack channel to use for notifications. type: string steps: - checkout - restore_cache: key: dependency-cache-{{ checksum "package.json" }} - run: command: npm ci --no-audit name: install-npm - run: command: npm outdated << parameters.dependencies_to_check >> name: run-outdated - slack/notify: channel: << parameters.slack_channel >> 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}" } } ] } event: fail npm_security_audit: description: | Node.js projects using npm - auditing package dependencies for security vulnerabilities executor: name: node tag: <<parameters.node_tag>> parameters: node_tag: default: "20.16" type: string slack_channel: default: dps_alerts_security description: Slack channel to use for notifications. type: string steps: - checkout - restore_cache: key: dependency-cache-{{ checksum "package.json" }} - run: command: npm ci --no-audit name: install-npm - run: command: npm run security_audit name: run-security-audit - slack/notify: channel: << parameters.slack_channel >> 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}" } } ] } event: fail publish_docker: description: | Pushes the built container image to the repository. NOTE: You MUST have ran your `build_docker` job with the parameter `persist_container_image` set to `true`. executor: name: default_small tag: "3.10" parameters: publish_latest_tag: default: true type: boolean steps: - checkout - setup_remote_docker - recall_container_image - run: command: | docker login -u="${QUAYIO_USERNAME}" -p="${QUAYIO_PASSWORD}" quay.io docker push "${IMAGE_NAME}:${APP_VERSION}" name: Publish image to repository - when: condition: << parameters.publish_latest_tag >> steps: - run: command: | docker tag "${IMAGE_NAME}:${APP_VERSION}" "${IMAGE_NAME}:latest" docker push "${IMAGE_NAME}:latest" name: Publish `latest` tag to repository sentry_release_and_deploy: description: | Notify Sentry.io of a release and deployment within your codebase executor: name: default_small tag: "3.10" parameters: sentry_create_release: default: false description: Tell sentry-cli to work out the commits on this release - this should only be done ONCE, ideally when you push to DEV. type: boolean sentry_environment: type: string sentry_org: default: ministryofjustice type: string sentry_project: type: string steps: - checkout - mem/recall: env_var: APP_VERSION - run: command: | export SENTRY_ORG=<< parameters.sentry_org >> export SENTRY_PROJECT=<< parameters.sentry_project >> echo "export SENTRY_ORG=$SENTRY_ORG" >> $BASH_ENV echo "export SENTRY_PROJECT=$SENTRY_PROJECT" >> $BASH_ENV curl -sL https://sentry.io/get-cli/ | bash name: Sentry - Setup environment - when: condition: << parameters.sentry_create_release >> steps: - run: command: | sentry-cli releases new $APP_VERSION --project $SENTRY_PROJECT sentry-cli releases set-commits $APP_VERSION --auto sentry-cli releases finalize $APP_VERSION name: Sentry - Create release - run: command: | sentry-cli releases deploys $APP_VERSION new -e << parameters.sentry_environment >> name: Sentry - Record deployment smoke_test: circleci_ip_ranges: true description: | Runs the smoke test for this project executor: name: java tag: <<parameters.jdk_tag>> parameters: cachekey: default: gradle- type: string cachepath: default: ~/.gradle type: string command: default: ./gradlew testSmoke -Dtestlogger.showStandardStreams=true type: string gradlefile: default: build.gradle.kts type: string jdk_tag: default: "11.0" type: string steps: - checkout - restore_cache: keys: - gradle-{{ checksum "<< parameters.gradlefile >>" }} - << parameters.cachekey >> - run: command: << parameters.command >> - save_cache: key: gradle-{{ checksum "<< parameters.gradlefile >>" }} paths: - << parameters.cachepath >> - store_test_results: path: build/test-results - store_artifacts: path: build/reports/tests trigger_job: description: | Trigger and (optionally) follow a pipeline in another CircleCI project. executor: name: default_small tag: "3.10" parameters: branch: default: main description: Name of the branch to target type: string build_parameters: default: '{}' description: Parameters to pass to the triggered pipeline (in a JSON string) type: string fail_build: default: true description: Fail the build if the triggered pipeline fails type: boolean follow_pipeline: default: true description: Follow the triggered pipeline and capture the result type: boolean follow_timeout: default: 500 description: Number of seconds to wait for the triggered pipeline to complete type: integer organization: default: ministryofjustice description: Name of the CircleCI organization type: string repository: description: Name of the repository type: string token: description: CircleCI Auth token for API access, either the string value, or an environment variable (i.e. $AUTH_TOKEN) that can be read via a context. type: string vcs_type: default: github description: Chosen VCS (either github or bitbucket) type: string steps: - run: command: | echo "Triggering the pipeline..." BUILD_RESPONSE=$( curl \ --silent \ --header "Circle-Token: << parameters.token >>" \ --request POST \ --retry 5 \ --connect-timeout 10 \ --max-time 60 \ --header 'Content-Type: application/json' \ --data '{"branch":"<< parameters.branch >>", "parameters":<< parameters.build_parameters >>}' \ --url https://circleci.com/api/v2/project/<< parameters.vcs_type >>/<< parameters.organization >>/<< parameters.repository >>/pipeline ) echo "Trigger response:" echo $BUILD_RESPONSE BUILD_ID=$(echo $BUILD_RESPONSE | jq -r '.id') if [[ $BUILD_ID == null ]]; then echo "Unable to trigger pipeline" exit 1 fi echo "export BUILD_ID=$BUILD_ID" >> $BASH_ENV name: Trigger pipeline on '<< parameters.vcs_type >>/<< parameters.organization >>/<< parameters.repository >>' using branch '<< parameters.branch >>' - when: condition: << parameters.follow_pipeline >> steps: - run: command: | WAIT=<< parameters.follow_timeout >> TIMEOUT=$(expr $SECONDS + $WAIT) STOPPED_TIME=null BUILD_URL=https://circleci.com/api/v2/pipeline/$BUILD_ID/workflow echo "Waiting up to $WAIT seconds for the pipeline to complete..." echo " - API Endpoint: $BUILD_URL" sleep 10 while [ $STOPPED_TIME == "null" ] && [ $SECONDS -le $TIMEOUT ]; do STATUS_RESPONSE=$( curl \ --silent \ --header "Circle-Token: << parameters.token >>" \ --request GET \ --retry 5 \ --connect-timeout 10 \ --max-time 60 \ --url $BUILD_URL ) STOPPED_TIME=$(echo $STATUS_RESPONSE | jq -r '.items[0].stopped_at') STATUS=$(echo $STATUS_RESPONSE | jq -r '.items[0].status') if [ $STOPPED_TIME == "null" ]; then echo " ... status: $STATUS" sleep 15 fi done echo "Pipeline complete - status: $STATUS" if [ "<< parameters.fail_build >>" == "true" ]; then if [ $STATUS != "success" ]; then exit 1 fi fi name: Following pipeline on '<< parameters.vcs_type >>/<< parameters.organization >>/<< parameters.repository >>' trivy_latest_scan: description: | Scan the latest tag (docker container image) for CVEs using Trivy. This is intended to be a scheduled job that runs maybe daily and can alert teams to new found issues on running applications that might not be in active development. Uses the latest Docker Trivy image. executor: name: default tag: "3.10" parameters: additional_args: default: "" description: Additional CLI args to pass into the trivy command type: string cache_key: default: v1 description: Cache key for the vulnerability database - change to break the cache. type: string cve_severities_to_check: default: HIGH,CRITICAL description: What severity of CVE to look for? Options are UNKNOWN,LOW,MEDIUM,HIGH,CRITICAL. type: string db_repo_1: default: ghcr.io/aquasecurity/trivy-db:2 description: Database repository for vulnerability database - main type: string db_repo_2: default: public.ecr.aws/aquasecurity/trivy-db description: Database repository for vulnerability database - backup type: string image_name: default: quay.io/hmpps/${CIRCLE_PROJECT_REPONAME} type: string slack_channel: default: dps_alerts_security description: Slack channel to use for notifications. type: string trivy_template: default: | ------- {{- range . }} {{- $location := .Target }} {{- range .Vulnerabilities }} Severity: {{ .Severity }} CVE: {{ .VulnerabilityID }} Title: "{{ .Title }}" PkgName: {{ .PkgName }} InstalledVersion: {{ .InstalledVersion }} FixedVersion: {{ .FixedVersion }} Location: {{ $location }} ------- {{- end }} {{- end }} type: string steps: - checkout - setup_remote_docker - install_trivy - restore_cache: key: trivy_cache_<< parameters.cache_key >> - run: command: | docker pull "<< parameters.image_name >>:latest" name: Ensure we have latest image from the repo - run: command: | /tmp/trivy \ --cache-dir .trivy \ image \ --exit-code 100 \ --no-progress \ --severity << parameters.cve_severities_to_check >> \ --ignore-unfixed \ --skip-dirs /usr/local/lib/node_modules/npm \ --skip-files /app/agent.jar \ --db-repository "<< parameters.db_repo_1 >>","<< parameters.db_repo_2 >>" \ << parameters.additional_args >> "<< parameters.image_name >>:latest" name: Trivy scan for << parameters.cve_severities_to_check >> CVEs - save_cache: key: trivy_cache_<< parameters.cache_key >> paths: - .trivy - run: command: | /tmp/trivy \ --cache-dir .trivy \ image \ --exit-code 100 \ --no-progress \ --severity << parameters.cve_severities_to_check >> \ --ignore-unfixed \ --skip-dirs /usr/local/lib/node_modules/npm \ --skip-files /app/agent.jar \ --output results.json \ --format json \ --db-repository "<< parameters.db_repo_1 >>","<< parameters.db_repo_2 >>" \ << parameters.additional_args >> "<< parameters.image_name >>:latest" name: Get Trivy results in json format when: always - store_artifacts: path: results.json - run: command: | /tmp/trivy \ --cache-dir .trivy \ image \ --exit-code 100 \ --no-progress \ --severity << parameters.cve_severities_to_check >> \ --ignore-unfixed \ --skip-dirs /usr/local/lib/node_modules/npm \ --skip-files /app/agent.jar \ --output results.txt \ --format template \ --template '<< parameters.trivy_template >>' \ --db-repository "<< parameters.db_repo_1 >>","<< parameters.db_repo_2 >>" \ << parameters.additional_args >> "<< parameters.image_name >>:latest" name: Get Trivy results formatted for slack when: on_fail - slack_message_results: file: results.txt - slack/notify: channel: << parameters.slack_channel >> 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}" } }, { "type": "context", "elements": [ { "type": "mrkdwn", "text": "${SLACK_TXT+```}${SLACK_TXT:-No output, view job for details.}${SLACK_TXT+```}" } ] }, { "type": "divider" } ] } event: fail trivy_pipeline_scan: description: | Scan the built docker container for CVEs using Trivy. executor: name: default tag: "3.10" parameters: additional_args: default: "" description: Additional CLI args to pass into the trivy command type: string cache_key: default: v1 description: Cache key for the vulnerability database - change to break the cache. type: string cve_severities_to_check: default: HIGH,CRITICAL description: What severity of CVE to look for? Options are UNKNOWN,LOW,MEDIUM,HIGH,CRITICAL. type: string db_repo_1: default: ghcr.io/aquasecurity/trivy-db:2 description: Database repository for vulnerability database - main type: string db_repo_2: default: public.ecr.aws/aquasecurity/trivy-db description: Database repository for vulnerability database - backup type: string fail_build: default: true description: Fail the build if any CVEs are detected. type: boolean steps: - checkout - setup_remote_docker - recall_container_image - install_trivy - restore_cache: key: trivy_cache_<< parameters.cache_key >> - run: command: | EXIT_CODE=0 if [ "<< parameters.fail_build >>" == "true" ]; then EXIT_CODE=100 fi /tmp/trivy \ --cache-dir .trivy \ image \ --exit-code ${EXIT_CODE} \ --no-progress \ --severity << parameters.cve_severities_to_check >> \ --ignore-unfixed \ --skip-dirs /usr/local/lib/node_modules/npm \ --skip-files /app/agent.jar \ --db-repository "<< parameters.db_repo_1 >>","<< parameters.db_repo_2 >>" \ << parameters.additional_args >> "${IMAGE_NAME}:${APP_VERSION}" name: Trivy scan for << parameters.cve_severities_to_check >> CVEs - save_cache: key: trivy_cache_<< parameters.cache_key >> paths: - .trivy veracode_pipeline_scan: description: | Veracode SAST pipeline scan executor: java_options: <<parameters.java_options>> name: java tag: <<parameters.jdk_tag>> parameters: additional_docker_build_args: default: "" type: string docker_image_app_dir: default: /app description: Directory inside the docker image where the application artifacts are saved type: string java_options: default: -Xmx1024m -XX:ParallelGCThreads=2 -XX:ConcGCThreads=2 -Djava.util.concurrent.ForkJoinPool.common.parallelism=2 -Dorg.gradle.daemon=false -Dkotlin.compiler.execution.strategy=in-process type: string jdk_tag: default: "17.0" type: string slack_channel: default: dps_alerts_security description: Slack channel to use for notifications. type: string steps: - veracode_prepare_artifacts: additional_docker_build_args: << parameters.additional_docker_build_args >> docker_image_app_dir: << parameters.docker_image_app_dir >> - run: command: | wget https://downloads.veracode.com/securityscan/pipeline-scan-LATEST.zip -O pipeline-scan.zip unzip pipeline-scan.zip -x README.md name: Download/Extract-Veracode-Pipeline-Scanner - restore_cache: keys: - veracode-baseline-results-{{ .Branch }} - run: command: | echo "Randomly picking 1 of 5 api keys, to help avoid veracode API rate limits." X=$(( RANDOM % 4 )) VERACODE_API_ID_X="VERACODE_API_ID_$X" VERACODE_API_KEY_X="VERACODE_API_KEY_$X" echo "Using ${VERACODE_API_ID_X} from pool." java -jar pipeline-scan.jar \ --request_policy "Ministry of Justice" \ --veracode_api_id "${!VERACODE_API_ID_X}" \ --veracode_api_key "${!VERACODE_API_KEY_X}" name: Download Veracode Policy no_output_timeout: 1m - run: command: | echo "Randomly picking 1 of 5 api keys, to help avoid veracode API rate limits." X=$(( RANDOM % 4 )) VERACODE_API_ID_X="VERACODE_API_ID_$X" VERACODE_API_KEY_X="VERACODE_API_KEY_$X" echo "Using ${VERACODE_API_ID_X} from pool." java -jar pipeline-scan.jar \ $(test -f results.json && echo "--baseline_file results.json") \ --json_output true \ --file source.zip \ --policy_file Ministry_of_Justice.json \ --veracode_api_id "${!VERACODE_API_ID_X}" \ --veracode_api_key "${!VERACODE_API_KEY_X}" \ --timeout 60 \ --issue_details false \ --summary_output true name: Scan Project no_output_timeout: 30m - slack_message_results: file: results.txt - save_cache: key: veracode-baseline-results-{{ .Branch }} paths: - results.json when: always - slack/notify: channel: << parameters.slack_channel >> 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}" } }, { "type": "context", "elements": [ { "type": "mrkdwn", "text": "${SLACK_TXT+```}${SLACK_TXT:-No output, view job for details.}${SLACK_TXT+```}" } ] }, { "type": "divider" } ] } event: fail veracode_policy_scan: description: | Veracode SAST policy scan executor: java_options: <<parameters.java_options>> name: java tag: <<parameters.jdk_tag>> parameters: additional_docker_build_args: default: "" type: string docker_image_app_dir: default: /app description: Directory inside the docker image where the application artifacts are saved type: string java_options: default: -Xmx1024m -XX:ParallelGCThreads=2 -XX:ConcGCThreads=2 -Djava.util.concurrent.ForkJoinPool.common.parallelism=2 -Dorg.gradle.daemon=false -Dkotlin.compiler.execution.strategy=in-process type: string jdk_tag: default: "17.0" type: string slack_channel: default: dps_alerts_security description: Slack channel to use for notifications. type: string teams: default: hmpps-tech description: | Comma-separated list of team names associated with the specified application. Validates against the names of existing teams for this account. type: string steps: - veracode_prepare_artifacts: additional_docker_build_args: << parameters.additional_docker_build_args >> docker_image_app_dir: << parameters.docker_image_app_dir >> - run: command: | wget https://repo1.maven.org/maven2/com/veracode/vosp/api/wrappers/vosp-api-wrappers-java/22.9.10.3/vosp-api-wrappers-java-22.9.10.3.jar -O VeracodeJavaAPI.jar name: Download/Extract veracode agent - run: command: | echo "Randomly picking 1 of 5 api keys, to help avoid veracode API rate limits." X=$(( RANDOM % 4 )) VERACODE_API_ID_X="VERACODE_API_ID_$X" VERACODE_API_KEY_X="VERACODE_API_KEY_$X" echo "Using ${VERACODE_API_ID_X} from pool." java -jar VeracodeJavaAPI.jar \ -vid "${!VERACODE_API_ID_X}" \ -vkey "${!VERACODE_API_KEY_X}" \ -teams "<< parameters.teams >>" \ -action UploadAndScan \ -appname ${CIRCLE_PROJECT_REPONAME} \ -createprofile true \ -deleteincompletescan 2 \ -version "CircleCI-${CIRCLE_BUILD_NUM}" \ -filepath source.zip \ 2>&1 | tee output.txt name: Upload to Veracode - slack_message_results: file: output.txt - slack/notify: channel: << parameters.slack_channel >> 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}" } }, { "type": "context", "elements": [ { "type": "mrkdwn", "text": "${SLACK_TXT+```}${SLACK_TXT:-No output, view job for details.}${SLACK_TXT+```}" } ] }, { "type": "divider" } ] } event: fail examples: deployment_with_slack_and_changelog: description: | Deployment with Slack notifications and git changelog usage: version: "2.1" orbs: hmpps: ministryofjustice/hmpps@3.5 workflows: build-test-and-deploy: jobs: - hmpps/build_docker: image_name: example_image_name name: build_docker snyk-scan: true snyk-threshold: high - hmpps/deploy_env: context: - hmpps-common-vars env: dev name: deploy_dev requires: - build_docker show_changelog: true slack_channel_name: your-notification-channel slack_notification: true example: description: | CircleCI orb used to store common jobs/commands used by MoJ DPS team projects. usage: version: "2.1" orbs: hmpps: ministryofjustice/hmpps@2.2 workflows: build-test-and-deploy: jobs: - hmpps/npm_security_audit: context: - hmpps-common-vars slack_channel: your_channel_or_leave_out_for_default - hmpps/helm_lint - hmpps/build_docker: image_name: example_image_name name: build_docker snyk-fail-build: false snyk-scan: true snyk-threshold: high - hmpps/deploy_env: chart_name: example_app env: dev name: deploy_dev requires: - build_docker slack_notification: description: | Deployment with Slack notifications usage: version: "2.1" orbs: hmpps: ministryofjustice/hmpps@2.2 workflows: build-test-and-deploy: jobs: - hmpps/build_docker: image_name: example_image_name name: build_docker snyk-scan: true snyk-threshold: high - hmpps/deploy_env: context: - hmpps-common-vars env: dev name: deploy_dev requires: - build_docker slack_channel_name: your-notification-channel slack_notification: true
Developer Updates
Get tips to optimize your builds
Or join our research panel and give feedback
By submitting this form, you are agreeing to ourTerms of UseandPrivacy Policy.