You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This repository contains a docker image used to deploy CDK to our environments and a CDK constructs library for common EPS project patterns.
5
+
This repository contains a docker image used to deploy CDK to our environments and a CDK constructs library for common EPS project patterns, plus shared deployment utilities.
6
6
7
7
-`docker/` Contains Dockerfile used to build image used fo for CDK deployments
8
-
-`packages/cdkConstructs/` Contains common CDK constructs used in EPS projects
9
-
-`packages/depoymentUtils/` Contains shared code for standardizing OAS files and performing proxygen deployments
8
+
-`packages/cdkConstructs/` Contains common CDK constructs and CDK helpers used in EPS projects
9
+
-`packages/deploymentUtils/` Contains shared code for standardising OpenAPI specifications and performing Proxygen-based deployments
10
10
-`scripts/` Utilities helpful to developers of this specification
11
11
-`.github/` Contains GitHub workflows that are used for building and deploying from pull requests and releases
12
12
@@ -17,13 +17,89 @@ The release workflow does the following
17
17
- creates a new version of the cdk construct library and publishes it to github
18
18
- pushes the cdk-utils docker image to dev and all other environments (subject to manual release approval in github actions)
19
19
20
-
## CDK Constructs
20
+
## CDK Constructs (`packages/cdkConstructs`)
21
21
22
-
This contains common CDK constructs used in EPS projects.
22
+
This contains common CDK constructs and helpers used in EPS projects.
23
23
24
-
Available constructs are:
24
+
Available constructs and helpers include:
25
25
26
-
-`TypescriptLambdaFunction` - A reusable construct for TypeScript Lambda functions
26
+
-`TypescriptLambdaFunction` – A reusable construct for TypeScript Lambda functions
27
+
-`createApp` – Helper for creating a CDK `App` pre-configured with standard EPS tags and stack props
28
+
-`deleteUnusedStacks` – Helper functions for cleaning up superseded or PR-based CloudFormation stacks and their Route 53 records
29
+
30
+
### CDK app bootstrap (`createApp`)
31
+
32
+
The helper in [packages/cdkConstructs/src/apps/createApp.ts](packages/cdkConstructs/src/apps/createApp.ts) creates a CDK `App` and applies the standard NHS EPS tagging and configuration.
`createApp` reads deployment metadata from environment variables such as `versionNumber`, `commitId`, `environment` and `isPullRequest`, and exposes them via the returned `props` for use when defining stacks.
50
+
51
+
### Stack cleanup helpers (`deleteUnusedStacks`)
52
+
53
+
The helpers in [packages/cdkConstructs/src/stacks/deleteUnusedStacks.ts](packages/cdkConstructs/src/stacks/deleteUnusedStacks.ts) are used to clean up old CloudFormation stacks and their DNS records:
54
+
55
+
-`deleteUnusedMainStacks(baseStackName, getActiveVersions, hostedZoneName?)` – deletes superseded main and sandbox stacks once the active version has been deployed for at least 24 hours, and removes matching CNAME records from Route 53.
56
+
-`deleteUnusedPrStacks(baseStackName, repoName, hostedZoneName?)` – deletes stacks created for pull requests whose GitHub PRs have been closed, and cleans up their CNAME records.
57
+
58
+
These functions are designed to be invoked from scheduled jobs (for example, a nightly cleanup workflow) after deployment. They rely on:
59
+
60
+
- APIM status endpoints to determine the active API versions (via `getActiveApiVersions`).
61
+
- GitHub’s API to determine whether PRs are closed.
62
+
- Route 53 APIs to enumerate and delete CNAME records associated with the stacks.
63
+
64
+
Refer to [packages/cdkConstructs/tests/stacks/deleteUnusedStacks.test.ts](packages/cdkConstructs/tests/stacks/deleteUnusedStacks.test.ts) for example scenarios.
The [packages/deploymentUtils](packages/deploymentUtils) package contains utilities for working with OpenAPI specifications and Proxygen-based API deployments.
69
+
70
+
It exposes the following main entry points via [packages/deploymentUtils/src/index.ts](packages/deploymentUtils/src/index.ts):
71
+
72
+
-`deployApi` – Normalises an OpenAPI specification and deploys it via Proxygen Lambda functions, optionally performing blue/green deployments and publishing documentation to the appropriate catalogue.
73
+
-`writeSchemas` – Writes JSON Schemas to disk, collapsing `examples` arrays into a single `example` value to be compatible with OAS.
74
+
-`deleteProxygenDeployments` – Removes Proxygen PTL instances that correspond to closed GitHub pull requests for a given API.
75
+
- Config helpers from `config/index` – used to resolve configuration and CloudFormation export values.
See the source files under [packages/deploymentUtils/src/specifications](packages/deploymentUtils/src/specifications) and their tests in [packages/deploymentUtils/tests](packages/deploymentUtils/tests) for fuller examples and expected behaviours.
27
103
28
104
## Contributing
29
105
@@ -49,25 +125,35 @@ See [https://code.visualstudio.com/docs/devcontainers/containers](https://code.v
49
125
All commits must be made using [signed commits](https://docs.github.com/en/authentication/managing-commit-signature-verification/signing-commits).
50
126
51
127
52
-
### Testing changes to construct library
53
-
To test changes to the construct library, you need to package the library and install it on the project you want to test it on.
128
+
### Testing changes to construct or deploymentUtils libraries
129
+
To test changes to the construct library or the deploymentUtils package, you need to package the relevant library and install it into the project you want to test it in.
54
130
55
131
Either
56
-
- run `make package` from this project and copy the .tgz file from lib folder to the project you want to test in
57
-
- create a pull request and from the pull request workflow run, download nhsdigital-eps-cdk-constructs-1.0.0.tgz to the project you want to test in
132
+
- run `make package` from this project and copy the generated `.tgz` file(s) from the lib folder to the project you want to test in
133
+
- create a pull request and from the pull request workflow run, download the generated `.tgz` artifact(s) (for example `nhsdigital-eps-cdk-constructs-1.0.0.tgz` and/or `nhsdigital-eps-deployment-utils-1.0.0.tgz`) to the project you want to test in
58
134
59
-
In the project you want to test in, run the following
135
+
In the project you want to test in, run the following as appropriate:
0 commit comments