Skip to content

Commit 1243595

Browse files
authored
Merge pull request #82 from NHSDigital/cd
[DTOSS-9339] Deployment
2 parents 9178d3b + 32b0783 commit 1243595

6 files changed

Lines changed: 107 additions & 2 deletions

File tree

.azuredevops/pipelines/deploy.yml

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
trigger: none
2+
pr: none
3+
4+
parameters:
5+
- name: commitSHA
6+
displayName: Commit SHA
7+
type: string
8+
- name: environments
9+
type: object
10+
default:
11+
- dev
12+
- int
13+
14+
stages:
15+
- ${{ each env in parameters.environments }}:
16+
- stage: ${{ env }}
17+
displayName: Deploy to ${{ env }} environment
18+
pool:
19+
name: private-pool-dev-uks
20+
lockBehavior: sequential
21+
isSkippable: false
22+
23+
jobs:
24+
- deployment: DeployApp
25+
displayName: Deploy application
26+
environment: ${{ env }}
27+
strategy:
28+
runOnce:
29+
deploy:
30+
steps:
31+
- checkout: self
32+
33+
- task: TerraformInstaller@1
34+
displayName: Install Terraform
35+
inputs:
36+
terraformVersion: 1.7.0
37+
38+
- task: AzureCLI@2
39+
name: RunTerraform
40+
inputs:
41+
azureSubscription: manbrs-${{ env }}
42+
scriptType: bash
43+
scriptLocation: inlineScript
44+
addSpnToEnvironment: true
45+
inlineScript: |
46+
export ARM_TENANT_ID="$tenantId"
47+
export ARM_CLIENT_ID="$servicePrincipalId"
48+
export ARM_OIDC_TOKEN="$idToken"
49+
export ARM_USE_OIDC=true
50+
make ci ${{ env }} terraform-apply DOCKER_IMAGE_TAG=git-sha-${{ parameters.commitSHA }}

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,3 +77,13 @@ jobs:
7777
terraform_version: "${{ needs.metadata.outputs.terraform_version }}"
7878
version: "${{ needs.metadata.outputs.version }}"
7979
secrets: inherit
80+
81+
deploy-stage:
82+
name: Deploy stage
83+
needs: [build-stage]
84+
permissions:
85+
id-token: write
86+
uses: ./.github/workflows/stage-4-deploy.yaml
87+
with:
88+
commit_sha: ${{ github.sha }}
89+
secrets: inherit
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
name: Deployment stage
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
commit_sha:
7+
description: Commit SHA used to fetch ADO pipeline and docker image
8+
required: true
9+
type: string
10+
11+
jobs:
12+
deploy:
13+
name: Deploy
14+
runs-on: ubuntu-latest
15+
environment: azure
16+
17+
steps:
18+
- name: Checkout code
19+
uses: actions/checkout@v4
20+
21+
- uses: azure/login@v2
22+
with:
23+
client-id: ${{ secrets.AZURE_CLIENT_ID }}
24+
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
25+
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
26+
27+
- name: Call deployment pipeline
28+
run: |
29+
az pipelines run --commit-id ${{inputs.commit_sha}} --name "Deploy to Azure" --org https://dev.azure.com/nhse-dtos --project dtos-manage-breast-screening \
30+
--parameters commitSHA=${{inputs.commit_sha}}

README.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ To generate a new app, run:
107107
poetry run ./manage.py startapp <app_name> manage_breast_screening/`
108108
```
109109

110-
## Deployment
110+
## Manual deployment
111111
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 app is deployed to an [Azure container app](https://azure.microsoft.com/en-us/products/container-apps) using terraform.
112112

113113
For each environment, e.g. 'dev':
@@ -127,6 +127,11 @@ For each environment, e.g. 'dev':
127127
```
128128
1. The web app URL will be displayed as output. Copy it into a browser on the AVD to access the app.
129129

130+
## Continuous deployment
131+
When a PR is merged, Github actions securely triggers the deployment pipeline on the Azure devops pool running on the internal network. It currently deploys the dev environment automatically.
132+
133+
Access [Azure devops](https://dev.azure.com/nhse-dtos/dtos-manage-breast-screening/_build?definitionId=86) to see the pipeline.
134+
130135
## Application secrets
131136
The app requires secrets provided as environment variables. Terraform creates an Azure key vault and all its secrets are mapped directly to the app as environment variables. Devs can access the key vault to create and update the secrets manually.
132137

infrastructure/terraform/resource_group_init/core.bicep

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,16 @@ resource contributorAssignment 'Microsoft.Authorization/roleAssignments@2022-04-
2222
}
2323
}
2424

25+
// Let the managed identity read key vault secrets during terraform plan
26+
resource kvSecretUserAssignment 'Microsoft.Authorization/roleAssignments@2022-04-01' = {
27+
name: guid(subscription().subscriptionId, miPrincipalId, 'kvSecretUser')
28+
properties: {
29+
roleDefinitionId: subscriptionResourceId('Microsoft.Authorization/roleDefinitions', roleID.kvSecretUser)
30+
principalId: miPrincipalId
31+
description: '${miName} kvSecretUser access to subscription'
32+
}
33+
}
34+
2535
// Let the managed identity assign the Key Vault Secrets User role to the container app managed identity
2636
resource rbacAdminAssignment 'Microsoft.Authorization/roleAssignments@2022-04-01' = {
2737
name: guid(subscription().subscriptionId, miPrincipalId, 'rbacAdmin')

scripts/terraform/terraform.mk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ ci: # Skip manual approvals when running in CI - make ci <env> <action>
1313
set-azure-account: # Set the Azure account for the environment - make <env> set-azure-account
1414
[ "${SKIP_AZURE_LOGIN}" != "true" ] && az account set -s ${AZURE_SUBSCRIPTION} || true
1515

16-
resource-group-init: get-subscription-ids # Initialise the resource group - make <env> resource-group-init
16+
resource-group-init: set-azure-account get-subscription-ids # Initialise the resource group - make <env> resource-group-init
1717
$(eval STORAGE_ACCOUNT_NAME=sa${APP_SHORT_NAME}${ENV_CONFIG}tfstate)
1818

1919
$(eval output='$(shell az deployment sub create --location "${REGION}" --template-file infrastructure/terraform/resource_group_init/main.bicep \

0 commit comments

Comments
 (0)