Skip to content

Commit 73cf6ad

Browse files
committed
Run lint:prettier:fix
1 parent b455aac commit 73cf6ad

9 files changed

Lines changed: 133 additions & 77 deletions

File tree

.github/workflows/cicd-1-pull-request.yaml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ jobs:
8080
id-token: write
8181
uses: ./.github/workflows/stage-4-deploy.yaml
8282
with:
83-
environments: "[\"review\"]"
83+
environments: '["review"]'
8484
commit_sha: ${{ github.event.pull_request.head.sha }}
8585
pr_number: ${{ github.event.pull_request.number }}
8686
secrets: inherit
@@ -92,10 +92,10 @@ jobs:
9292
permissions:
9393
pull-requests: write
9494
steps:
95-
- name: Post URL to PR comments
96-
uses: marocchino/sticky-pull-request-comment@8ac02941f254c53fbda0cf44288785e1367e13bf
97-
with:
98-
message: |
99-
The review app is available at this URL:
100-
https://pr-${{ github.event.pull_request.number }}.manage-breast-screening.non-live.screening.nhs.uk
101-
You must authenticate with Entra ID
95+
- name: Post URL to PR comments
96+
uses: marocchino/sticky-pull-request-comment@8ac02941f254c53fbda0cf44288785e1367e13bf
97+
with:
98+
message: |
99+
The review app is available at this URL:
100+
https://pr-${{ github.event.pull_request.number }}.manage-breast-screening.non-live.screening.nhs.uk
101+
You must authenticate with Entra ID

.github/workflows/cicd-2-main-branch.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,6 @@ jobs:
8585
id-token: write
8686
uses: ./.github/workflows/stage-4-deploy.yaml
8787
with:
88-
environments: "[\"review\",\"dev\"]"
88+
environments: '["review","dev"]'
8989
commit_sha: ${{ github.sha }}
9090
secrets: inherit

.vscode/settings.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@
44
"MD024": { "siblings_only": true },
55
"MD033": false
66
},
7-
"python.testing.pytestArgs": [
8-
"."
9-
],
7+
"python.testing.pytestArgs": ["."],
108
"python.testing.unittestEnabled": false,
119
"python.testing.pytestEnabled": true
1210
}

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ For more information, see the following developer guides:
138138
- [Scripting Docker](https://github.com/NHSDigital/repository-template/blob/main/docs/developer-guides/Scripting_Docker.md)
139139

140140
### More documentation
141+
141142
Explore [the docs directory](docs).
142143

143144
## Licence

docs/adr/ADR-003-Subclass_Django_Form_fields.md

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,21 @@ This was very error prone and verbose, because we had to map between Django's fo
1818

1919
We decided to introduce a set of `Field` subclasses that customise the internal templates, so that they are rendered using the design system components.
2020

21-
| Field class | Widget class | Rendered component |
22-
| -- | -- | -- |
23-
| core.form_fields.CharField | TextInput, EmailInput, etc | input |
24-
| core.form_fields.CharField | TextArea | textarea |
25-
| core.form_fields.ChoiceField | RadioSelect | radios |
26-
| core.form_fields.ChoiceField | Select | select |
27-
| core.form_fields.MultipleChoiceField | CheckboxSelectMultiple | checkboxes |
28-
| core.form_fields.SplitDateField | SplitDateWidget | date-input |
21+
| Field class | Widget class | Rendered component |
22+
| ------------------------------------ | -------------------------- | ------------------ |
23+
| core.form_fields.CharField | TextInput, EmailInput, etc | input |
24+
| core.form_fields.CharField | TextArea | textarea |
25+
| core.form_fields.ChoiceField | RadioSelect | radios |
26+
| core.form_fields.ChoiceField | Select | select |
27+
| core.form_fields.MultipleChoiceField | CheckboxSelectMultiple | checkboxes |
28+
| core.form_fields.SplitDateField | SplitDateWidget | date-input |
2929

3030
In a template, they are rendered with `{{ form.field.as_field_group() }}` this encpauslates all the complexity of mapping parameters between Django's form API and the [Jinja2 component macros](./ADR-002-Use_Jinja2.md).
3131

3232
## Consequences
3333

3434
the custom form field subclasses:
35+
3536
- make it possible to add new forms without writing a lot of HTML or Jinja in the template
3637
- should be intuitive to developers already familiar with Django
3738
- may need extending to support additional params for the underlying component

docs/infrastructure/create-environment.md

Lines changed: 49 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -3,81 +3,87 @@
33
This is the initial manual process to create a new environment like review, dev, production...
44

55
## Code
6+
67
- Create the configuration files in `infrastructure/environments/[environment]`
78
- Add the `[environment]:` target in `scripts/terraform/terraform.mk`
89
- Add [environment] to the list of environments in `deploy-stage` step of `cicd-2-main-branch.yaml`. For the review enviornment, there is a single item in `cicd-1-pull-request.yaml`.
910
- Set the `fetch_secrets_from_app_key_vault` terraform variable to `false`. This is to let terraform create the key vault and prevent reading before it is ready.
1011

1112
## Entra ID
13+
1214
- Create postgres Entra ID group in `DTOS Administrative Unit (AU)`: `postgres_manbrs_[environment]_uks_admin`
1315
- Ask CCOE to assign role:
14-
- [Form for PIM](https://nhsdigitallive.service-now.com/nhs_digital?id=sc_cat_item&sys_id=28f3ab4f1bf3ca1078ac4337b04bcb78&sysparm_category=114fced51bdae1502eee65b9bd4bcbdc)
15-
- Approver: Add someone from the infrastructure team
16-
- Role Name: `Group.Read.All`
17-
- Application Name: `mi-manbrs-[environment]-adotoaz-uks`
18-
- Application ID: [client.id]
19-
- Managed identity: `mi-manbrs-[environment]-adotoaz-uks`
20-
- Description:
21-
- Managed identity: `mi-manbrs-[environment]-adotoaz-uks`
22-
- Role: permanent on Directory
16+
- [Form for PIM](https://nhsdigitallive.service-now.com/nhs_digital?id=sc_cat_item&sys_id=28f3ab4f1bf3ca1078ac4337b04bcb78&sysparm_category=114fced51bdae1502eee65b9bd4bcbdc)
17+
- Approver: Add someone from the infrastructure team
18+
- Role Name: `Group.Read.All`
19+
- Application Name: `mi-manbrs-[environment]-adotoaz-uks`
20+
- Application ID: [client.id]
21+
- Managed identity: `mi-manbrs-[environment]-adotoaz-uks`
22+
- Description: - Managed identity: `mi-manbrs-[environment]-adotoaz-uks` - Role: permanent on Directory
2323

2424
## Bicep
25+
2526
- Run bicep from AVD: `make [environment] resource-group-init`
2627

2728
## Infra secrets
28-
- Add the infrastructure secrets to the *inf* key vault `kv-manbrs-[review]-inf`
29+
30+
- Add the infrastructure secrets to the _inf_ key vault `kv-manbrs-[review]-inf`
2931

3032
## Azure devops
33+
3134
- Create ADO group
32-
- Name: `Run pipeline - [environment]`
33-
- Members: `mi-manbrs-[environment]-ghtoado-uks`. There may be more than 1 in the list. Check client id printed below the name.
34-
- Permissions:
35-
- View project-level information
35+
- Name: `Run pipeline - [environment]`
36+
- Members: `mi-manbrs-[environment]-ghtoado-uks`. There may be more than 1 in the list. Check client id printed below the name.
37+
- Permissions:
38+
- View project-level information
3639
- Create new pipeline:
37-
- Name: `Deploy to Azure - [environment]`
38-
- Pipeline yaml: `.azuredevops/pipelines/deploy.yml`
40+
- Name: `Deploy to Azure - [environment]`
41+
- Pipeline yaml: `.azuredevops/pipelines/deploy.yml`
3942
- Manage pipeline security:
40-
- Add group: `Run pipeline - [environment]`
41-
- Permissions:
42-
- Edit queue build configuration
43-
- Queue builds
44-
- View build pipeline
45-
- View builds
43+
- Add group: `Run pipeline - [environment]`
44+
- Permissions:
45+
- Edit queue build configuration
46+
- Queue builds
47+
- View build pipeline
48+
- View builds
4649
- Create service connection (ADO)
47-
- Connection type: `Azure Resource Manager`
48-
- Identity type: `Managed identity`
49-
- Subscription for managed identity: `Digital Screening DToS - Devops`
50-
- Resource group for managed identity: `rg-mi-[environment]-uks`
51-
- Managed identity: `mi-manbrs-[environment]-adotoaz-uks`
52-
- Scope level: `Subscription`
53-
- Subscription: `Digital Screening DToS - Core Services Dev`
54-
- Resource group for Service connection: leave blank
55-
- Service Connection Name: `manbrs-[environment]`
56-
- Do NOT tick: Grant access permission to all pipelines
57-
- Security: allow `Deploy to Azure - [environment]` pipeline
50+
- Connection type: `Azure Resource Manager`
51+
- Identity type: `Managed identity`
52+
- Subscription for managed identity: `Digital Screening DToS - Devops`
53+
- Resource group for managed identity: `rg-mi-[environment]-uks`
54+
- Managed identity: `mi-manbrs-[environment]-adotoaz-uks`
55+
- Scope level: `Subscription`
56+
- Subscription: `Digital Screening DToS - Core Services Dev`
57+
- Resource group for Service connection: leave blank
58+
- Service Connection Name: `manbrs-[environment]`
59+
- Do NOT tick: Grant access permission to all pipelines
60+
- Security: allow `Deploy to Azure - [environment]` pipeline
5861
- Create ADO environment: [environment]
59-
- Set: exclusive lock (except for review)
60-
- Add pipeline permission for `Deploy to Azure - [environment]` pipeline
62+
- Set: exclusive lock (except for review)
63+
- Add pipeline permission for `Deploy to Azure - [environment]` pipeline
6164

6265
## Github
66+
6367
- Create Github environment [environment]
6468
- Add the protection rule (except in review):
65-
- Deselect `Allow administrators to bypass configured protection rules`
66-
- In `Deployment branches and tags` choose `Selected branches and tags` from the drop-down menu
67-
- Click `Add deployment branch or tag rule` and enter "main"
69+
- Deselect `Allow administrators to bypass configured protection rules`
70+
- In `Deployment branches and tags` choose `Selected branches and tags` from the drop-down menu
71+
- Click `Add deployment branch or tag rule` and enter "main"
6872
- Add environment secrets, from `mi-manbrs-[environment]-ghtoado-uks` in github
69-
- *AZURE_CLIENT_ID*
70-
- *AZURE_SUBSCRIPTION_ID*
73+
- _AZURE_CLIENT_ID_
74+
- _AZURE_SUBSCRIPTION_ID_
7175

7276
## First run
77+
7378
- Test running terraform manually from the AVD (Optional)
7479
- Raise a pull request, review and merge to trigger the pipeline
7580
- Check ADO pipeline. You may be prompted to authorise:
76-
- Pipeline: service connection
77-
- Environment: service connection and agent pool
81+
- Pipeline: service connection
82+
- Environment: service connection and agent pool
7883

7984
## App secrets
80-
- Add the application secrets to the *app* key vault `kv-manbrs-[review]-app`
85+
86+
- Add the application secrets to the _app_ key vault `kv-manbrs-[review]-app`
8187
- Set `fetch_secrets_from_app_key_vault` terraform variable to `true`
8288
- Test running terraform manually from the AVD (Optional)
8389
- Raise a pull request, review and merge to trigger the pipeline

docs/infrastructure/deployment.md

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,67 @@
11
# Deployment
22

33
## Infrastructure
4+
45
The code is packaged into a docker image which is deployed to [Azure container apps](https://learn.microsoft.com/en-us/azure/container-apps/). The main app is a web application, with an HTTP ingress. And the second one is an [Azure container app job](https://learn.microsoft.com/en-us/azure/container-apps/jobs?tabs=azure-cli), triggered on demand to run the database migration.
56

67
The web application does not have a public endpoint. It is only accessible via [Azure front door](https://learn.microsoft.com/en-us/azure/frontdoor/) which is a CDN providing TLS certificates, firewall, scaling and caching. The internal endpoint is accessible via [Azure Virtual Desktop](https://learn.microsoft.com/en-us/azure/virtual-desktop/).
78

89
The data is hosted on [Azure postgres flexible server](https://learn.microsoft.com/en-us/azure/postgresql/flexible-server/overview).
910

1011
## Docker build
12+
1113
The build pipeline builds and pushes a docker image to [Github container registry](https://docs.github.com/en/packages/working-with-a-github-packages-registry/working-with-the-container-registry). The image is tagged with:
14+
1215
- branch name: for docker build caching
1316
- commit SHA: to uniquely identify the image during deployment, prefixed by "git-sha-".
1417
- image digest sha: immutable tag
1518

1619
## Automated deployment
20+
1721
The deployment is split between:
22+
1823
- [Github actions](https://github.com/features/actions) for Continuous Integration (CI)
1924
- [Azure devops](https://azure.microsoft.com/en-us/products/devops) pipelines for Continuous Deployment (CD)
2025

2126
### Github actions
27+
2228
Runs on Github hosted runners on the internet. They run all our tests (unit, functional, security, linting...). They don't have access to our internal network nor any sensitive data.
2329

2430
To deploy an environment, they authenticate to Azure and delegate the work to [Azure devops piplines](#azure-devops-pipelines).
2531

2632
See [all Github actions](https://github.com/NHSDigital/dtos-manage-breast-screening/actions).
2733

2834
### Azure devops pipelines
35+
2936
We use a public repository as required by the [NHS Service standard](https://service-manual.nhs.uk/standards-and-technology/service-standard-points/12-make-new-source-code-open). For security reasons, deployments cannot run from Github actions and run instead on Azure devops private runners inside our internal network. They have access to the network and any Azure resource deployed onto it.
3037

3138
See [all Azure devops pipelines](https://dev.azure.com/nhse-dtos/dtos-manage-breast-screening/_build).
3239

3340
### Review apps
34-
When a pull request is raised, add a "deploy" label to deploy a *review app* (concept borrowed from [Heroku](https://devcenter.heroku.com/articles/github-integration-review-apps)). It triggers the [CI/CD pull request](https://github.com/NHSDigital/dtos-manage-breast-screening/actions/workflows/cicd-1-pull-request.yaml) Github action workflow, which runs tests then authenticates to Azure and triggers the [Deploy review app](https://dev.azure.com/nhse-dtos/dtos-manage-breast-screening/_build?definitionId=102) Azure devops pipeline. It runs terraform to deploy the application, database and front door configuration.
41+
42+
When a pull request is raised, add a "deploy" label to deploy a _review app_ (concept borrowed from [Heroku](https://devcenter.heroku.com/articles/github-integration-review-apps)). It triggers the [CI/CD pull request](https://github.com/NHSDigital/dtos-manage-breast-screening/actions/workflows/cicd-1-pull-request.yaml) Github action workflow, which runs tests then authenticates to Azure and triggers the [Deploy review app](https://dev.azure.com/nhse-dtos/dtos-manage-breast-screening/_build?definitionId=102) Azure devops pipeline. It runs terraform to deploy the application, database and front door configuration.
3543

3644
To make this process faster and less costly, most of the infrastructure is reused for all review apps: networking, key vaults, container app environments... The base infrastructure is only updated by the pipeline on the main branch.
3745

38-
When the pull request is closed or merged, and if it has the "deploy" label, the [Delete review app](https://github.com/NHSDigital/dtos-manage-breast-screening/actions/workflows/cicd-1-pull-request-closed.yaml) workflow is triggered, followed by the [Delete review app](https://dev.azure.com/nhse-dtos/dtos-manage-breast-screening/_build?definitionId=103) Azure devops pipeline. It runs *terraform destroy* to delete the resources.
46+
When the pull request is closed or merged, and if it has the "deploy" label, the [Delete review app](https://github.com/NHSDigital/dtos-manage-breast-screening/actions/workflows/cicd-1-pull-request-closed.yaml) workflow is triggered, followed by the [Delete review app](https://dev.azure.com/nhse-dtos/dtos-manage-breast-screening/_build?definitionId=103) Azure devops pipeline. It runs _terraform destroy_ to delete the resources.
3947

4048
Note: terraform currently deploys a postgres server with a locked database. It must be deleted manually from the Azure portal before the pipeline runs.
4149

4250
### Main branch
51+
4352
When a pull request is merged to the main branch, the [CI/CD main branch](https://github.com/NHSDigital/dtos-manage-breast-screening/actions/workflows/cicd-2-main-branch.yaml) is triggered. It runs tests then authenticates to Azure and triggers the [Deploy to Azure](https://dev.azure.com/nhse-dtos/dtos-manage-breast-screening/_build?definitionId=93) Azure devops pipeline. It runs terraform to deploy the entire environment, including both infrastructure and applications. Any manual change is overwritten by terraform.
4453

4554
## Application secrets
46-
The application requires secrets provided as environment variables. Terraform creates an *app* Azure key vault and all its secrets are mapped directly to the app as environment variables. Developers can access the key vault to create and update the secrets manually.
55+
56+
The application requires secrets provided as environment variables. Terraform creates an _app_ Azure key vault and all its secrets are mapped directly to the app as environment variables. Developers can access the key vault to create and update the secrets manually.
4757

4858
Notes:
59+
4960
- [the process requires multiple steps](https://github.com/NHSDigital/dtos-devops-templates/tree/main/infrastructure/modules/container-app#key-vault-secrets) to set up an environment initially. The process is documented in [create-environment](create-environment.md).
5061
- The secrets names in key vault are uppercase with hyphen separators. They are mapped to environment variables as uppercase with underscore separator. e.g. `SECRET-KEY` is mapped to `SECRET_KEY`.
5162

5263
## Manual deployment
64+
5365
For each environment, e.g. 'dev':
5466

5567
1. Connect to [Azure virtual desktop](https://azure.microsoft.com/en-us/products/virtual-desktop). Ask the platform team for access with Administrator role.
@@ -73,7 +85,8 @@ For each environment, e.g. 'dev':
7385
[Review app environments](#review-apps) differ slightly from other environments. They are lightweight versions of the application and are designed to share much of the core Azure infrastructure. As a result, there is a one-to-many relationship between the container apps and the container app environment.
7486

7587
### Step 1
76-
If you run the following command *without* the `PR_NUMBER` parameter, it will apply only the infrastructure module:
88+
89+
If you run the following command _without_ the `PR_NUMBER` parameter, it will apply only the infrastructure module:
7790

7891
```shell
7992
make review terraform-apply
@@ -90,7 +103,9 @@ make review terraform-apply DOCKER_IMAGE_TAG=git-sha-01ecb79d561f55be60072a093dd
90103
```
91104

92105
### Delete review app
106+
93107
Run terraform-destroy:
108+
94109
```shell
95110
make review terraform-destroy DOCKER_IMAGE_TAG=git-sha-01ecb79d561f55be60072a093dd167fe8eb5b42e PR_NUMBER=123
96111
```

0 commit comments

Comments
 (0)