Skip to content
This repository was archived by the owner on Oct 2, 2024. It is now read-only.

Commit 86ce243

Browse files
authored
Merge pull request #16 from nhsuk/feature/remove-review-app
Feature/remove review app
2 parents 1130da6 + 22c5d43 commit 86ce243

File tree

3 files changed

+76
-3
lines changed

3 files changed

+76
-3
lines changed

README.md

+37-2
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,9 @@ in the editor will not be saved back to the repository._
1818

1919
## Installation
2020

21-
* Install the appropriate version for your development platform of
21+
* Install the appropriate version of
2222
[Azure Functions Core Tools version 2.x](https://docs.microsoft.com/en-us/azure/azure-functions/functions-run-local#install-the-azure-functions-core-tools)
23+
for your development platform of choice
2324
* Clone the repository - `git clone https://github.com/nhsuk/cache-flush.git`
2425
* Install npm dependencies - `npm install`
2526
* Rename [example.local.settings.json](example.local.settings.json) to
@@ -28,11 +29,45 @@ in the editor will not be saved back to the repository._
2829
[Akamai's documentation](https://developer.akamai.com/legacy/introduction/Prov_Creds.html)
2930
provides details on how to setup API credentials.
3031

31-
3232
## Run Azure Function App locally
3333

3434
* Start the Function app - `func start`
3535

36+
## Deployments and environments
37+
38+
Deployments to all environments are fully automated and are tested to confirm
39+
the deployment has been successful as part of the deployment process.
40+
Therefore, if the deployment job succeeds you can be confident the application
41+
is working.
42+
43+
Deployments are configured via [azure-pipelines.yml](./azure-pipelines.yml) and
44+
run within the
45+
[nhsuk.utilities](https://dev.azure.com/nhsuk/nhsuk.utilities/_build?definitionId=323)
46+
project. The pipeline is not public. In order to view it a login is required.
47+
The deployed applications are protected using the standard function app
48+
authorisation mechanism i.e.
49+
[authorization keys](https://docs.microsoft.com/en-us/azure/azure-functions/functions-bindings-http-webhook#authorization-keys).
50+
The keys are maintained as secrets to prevent abuse and unwanted use.
51+
52+
### Review environments
53+
Review environments are deployed for every PR and are available at
54+
[https://nhsuk-cache-flush-func-dev-uks-pr-<PR_NUMBER>.azurewebsites.net/](https://nhsuk-cache-flush-func-dev-uks-pr-XXX.azurewebsites.net/).
55+
When a PR is merged into `master` the review environment will be deleted.
56+
57+
### [Integration](https://nhsuk-cache-flush-func-int-uks.azurewebsites.net/)
58+
Merges to `master` generate a deployment to the integration environment.
59+
60+
### [Staging](https://nhsuk-cache-flush-func-stag-uks.azurewebsites.net/)
61+
The creation of a [release](https://github.com/nhsuk/cache-flush/releases)
62+
generates a deployment to the staging environment.
63+
64+
### [Production](https://nhsuk-cache-flush-func-prod-uks.azurewebsites.net/)
65+
Deployments to production are only possible if the change has been deployed to
66+
the staging environment. The deployment to production must be
67+
[approved](https://docs.microsoft.com/en-us/azure/devops/pipelines/process/approvals?view=azure-devops#approvals).
68+
Using approvals enables a pause between the deployment to staging and the
69+
deployment to production. It is often necessary to seek a sign-off prior to
70+
deploying to production and this setup allows that to happen.
3671

3772
## Environment variables
3873

azure-pipelines.yml

+27-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ pr:
1717

1818
variables:
1919
ARTIFACT_NAME: drop
20+
REVIEW_APP_NAME_ROOT: 'nhsuk-cache-flush-func-dev-uks-PR-'
2021

2122
stages:
2223
- stage: build
@@ -68,7 +69,7 @@ stages:
6869
jobs:
6970
- template: ./templates/deployment-job.yml
7071
parameters:
71-
appName: 'nhsuk-cache-flush-func-dev-uks-PR-$(system.pullRequest.pullRequestNumber)'
72+
appName: '$(REVIEW_APP_NAME_ROOT)$(system.pullRequest.pullRequestNumber)'
7273
appTest: deployed
7374
azureSubscription: Development
7475
environment: cacheflush-review
@@ -86,6 +87,31 @@ stages:
8687
azureSubscription: 'www.nhs.uk'
8788
environment: cacheflush-int
8889
releaseEnvironment: int
90+
- job: getNumberForMergedPR
91+
displayName: Get the number of the merged PR
92+
steps:
93+
- bash: $(System.DefaultWorkingDirectory)/scripts/get-pr-number.sh "$BUILD_SOURCEVERSIONMESSAGE"
94+
displayName: 'Set PR number, if available'
95+
name: PR_NUMBER
96+
- job: deleteReviewEnvironment
97+
condition: gt(dependencies.getNumberForMergedPR.outputs['PR_NUMBER.PR_NUMBER'], 0)
98+
dependsOn: getNumberForMergedPR
99+
displayName: Delete review environment for merged PR
100+
variables:
101+
PR_NUMBER: $[dependencies.getNumberForMergedPR.outputs['PR_NUMBER.PR_NUMBER']]
102+
RESOURCE_GROUP: nhsuk-utils-rg-dev-uks
103+
REVIEW_APP_NAME: $(REVIEW_APP_NAME_ROOT)$(PR_NUMBER)
104+
steps:
105+
- task: AzureCLI@2
106+
displayName: 'Delete review environment func app and app insights for merged PR'
107+
inputs:
108+
azureSubscription: Development
109+
inlineScript: |
110+
az extension add --name application-insights
111+
az monitor app-insights component delete --resource-group $(RESOURCE_GROUP) --app $(REVIEW_APP_NAME) --debug
112+
az functionapp delete --resource-group $(RESOURCE_GROUP) --name $(REVIEW_APP_NAME) --debug
113+
scriptLocation: inlineScript
114+
scriptType: bash
89115

90116
- stage: deployStagingEnvironment
91117
displayName: 'Deploy to Staging Environment'

scripts/get-pr-number.sh

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/bin/bash
2+
3+
regex="#([0-9]+)"
4+
echo "Testing commit msg: '$1' against regex: '$regex'."
5+
6+
if [[ "$1" =~ $regex ]]; then
7+
echo "PR number found. Value is: ${BASH_REMATCH[1]}"
8+
echo "##vso[task.setvariable variable=PR_NUMBER;isOutput=true]${BASH_REMATCH[1]}"
9+
else
10+
echo "No PR number found. Setting to 0."
11+
echo "##vso[task.setvariable variable=PR_NUMBER;isOutput=true]0"
12+
fi;

0 commit comments

Comments
 (0)