feat(cdk): Provision ECS infrastructure for tag page rendering CODE - #16321
Conversation
| container: | ||
| permissions: | ||
| packages: write | ||
| needs: [production-container] | ||
| uses: ./.github/workflows/container.yml | ||
| with: | ||
| production-image-digest: ${{ needs.production-container.outputs.imageDigest }} |
There was a problem hiding this comment.
This container step is what runs cdk synth. This container is published to GitHub Packages and is used by the Commercial CI checks. I think there's an opportunity to simplify CI (as a separate task) by having the Commercial CI checks use the "production container". This would mean running cdk synth in a discrete step too, for improved readability.
d34b39d to
8a2aea9
Compare
48968fd to
c03f9b0
Compare
| "DefaultActions": [ | ||
| { | ||
| "ForwardConfig": { | ||
| "TargetGroups": [ | ||
| { | ||
| "TargetGroupArn": { | ||
| "Ref": "TargetGroupTagpagerendering42E428EE", | ||
| }, | ||
| "Weight": 1, | ||
| }, | ||
| { | ||
| "TargetGroupArn": { | ||
| "Ref": "EcsTargetGroupTagpagerendering06213654", | ||
| }, | ||
| "Weight": 0, | ||
| }, | ||
| ], | ||
| }, | ||
| "Type": "forward", | ||
| }, | ||
| ], |
There was a problem hiding this comment.
This part configures the weighted routing. 100% of traffic goes to the EC2 target group and 0% to the ECS target group.
| // Route all traffic to EC2 | ||
| targetGroupWeights: { | ||
| ec2: 1, | ||
| ecs: 0, | ||
| }, |
There was a problem hiding this comment.
This part configures the weighted routing. 100% of traffic goes to the EC2 target group and 0% to the ECS target group.
| artifactsBucket, | ||
| }), | ||
| }, | ||
| ...(!(imageIdentifier == null) && { |
There was a problem hiding this comment.
Currently, this condition evaluates to true for tag-page-rendering CODE as it sets imageIdentifier within bin/cdk.ts.
4721ad8 to
eb2eadb
Compare
There was a problem hiding this comment.
Pull request overview
Provisions ECS (Fargate) infrastructure for tag-page-rendering in CODE alongside the existing EC2 deployment, attaching both target groups to a single ALB with weighted routing (initially 100% to EC2). It also wires CI to inject a production image digest into cdk synth, and adds a local docker-compose flow for running the production build.
Changes:
- Add optional
imageIdentifiersupport to CDK stack props to enable EC2+ECS “hybrid” mode and set ALB target-group weights. - Update CI workflow ordering so a production image digest is built/published first, then passed into the container build that runs
make riffraff-bundle/cdk synth. - Add snapshot coverage for the ECS-enabled CODE stack and add a docker-compose file for local prod-build runs.
Reviewed changes
Copilot reviewed 6 out of 7 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| dotcom-rendering/cdk/lib/renderingStack.ts | Adds imageIdentifier and conditionally configures ECS + weighted target groups in the main stack. |
| dotcom-rendering/cdk/bin/cdk.ts | Exports CODE props and injects IMAGE_DIGEST into the stack config. |
| dotcom-rendering/cdk/lib/renderingStack.test.ts | Adds a snapshot test for the ECS-enabled Tag Page Rendering CODE stack. |
| dotcom-rendering/cdk/lib/snapshots/renderingStack.test.ts.snap | Updates snapshots to include the ECS-enabled CODE template output. |
| docker-compose.yaml | Adds local compose setup to run the production build and send a sample request after healthcheck. |
| .github/workflows/container.yml | Requires a production image digest input and passes it into the bundle generation step. |
| .github/workflows/cicd.yml | Reorders jobs so the production digest is produced first and then fed into the container workflow. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
eb2eadb to
cff3267
Compare
80d50c9 to
399de07
Compare
| scaling: { minimumInstances: 1, maximumInstances: 3 }, | ||
| instanceType: InstanceType.of(InstanceClass.T4G, InstanceSize.SMALL), | ||
| }); | ||
| imageIdentifier: process.env.IMAGE_DIGEST ?? 'DEV', |
There was a problem hiding this comment.
Note: In CI this environment variable is going to be passed in via the job output production-container.outputs.imageDigest.
There was a problem hiding this comment.
This is correct for CI in the "real-world" (bin/cdk.ts) 👍🏽 .
In the test context (renderingStack.test.ts), the string value is hard-coded to 'sha256:12345'. Doing so means the snapshot has a static value and so doesn't need updating each time an image is published.
|
I've rebased this with #16341. Whilst logs are appearing in Central ELK (see screenshot), deployment is now failing due to #16341 (comment). I think we could wait for guardian/cdk#2933 to land before merging this.
|
399de07 to
1e9dde8
Compare
This changes CI in a significant way - the production image is now built and published as the first step (~2 minutes). This is because we need to pass the image digest to CDK to inject into the CloudFormation template.
Update tag page rendering CODE to provision ECS infrastructure but route no traffic to it.
|
Seen on PROD (merged by @akash1810 15 minutes and 17 seconds ago) Please check your changes! |

Note
mainin "dangerous" mode after successfully testing this. Consequently, the screenshots won't be seen in the AWS console now.mainto avoid deleting the ECS infrastructure.What does this change?
This change provisions the infrastructure to run
tag page rendering CODEon ECS and EC2 as target groups for a single load balancer. The load balancer is configured with traffic weighting. Initially 100% of traffic is routed to EC2. Once we have a way to deterministically route requests to target groups, we'll tweak the weighting.Why?
This is the next step to running DCR on AWS ECS. It allows us to understand if we've got the ECS configuration correct. Once happy, we'll tweak the traffic weighting and make a plan to go to PROD. Such a plan could include running through the AWS ECS Workshop as an introduction to AWS ECS.
How has this change been tested?
I've successfully deployed to CODE. After this, we can see:
A new ECS cluster:
A new target group in the load balancer:
The new target is healthy:
Logs are also appearing in Central ELK:
Open questions