Skip to content

Commit 6182e42

Browse files
committed
feat(cdk): Switch container source from ECR to GHCR
- Remove ECR repository lookup, use GHCR public image instead - Add SCP-compliant IAM role names (InnovationSandbox-ndx-* prefix) - Pass DB credentials as env vars via CloudFormation dynamic references instead of ECS secrets (workaround for sandbox SCP restrictions) - Update CDK context for new AWS account
1 parent 2da1079 commit 6182e42

2 files changed

Lines changed: 27 additions & 14 deletions

File tree

cloudformation/scenarios/localgov-drupal/cdk/cdk.context.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,5 +56,18 @@
5656
"us-east-1d",
5757
"us-east-1e",
5858
"us-east-1f"
59+
],
60+
"availability-zones:account=831494785845:region=eu-west-2": [
61+
"eu-west-2a",
62+
"eu-west-2b",
63+
"eu-west-2c"
64+
],
65+
"availability-zones:account=831494785845:region=us-east-1": [
66+
"us-east-1a",
67+
"us-east-1b",
68+
"us-east-1c",
69+
"us-east-1d",
70+
"us-east-1e",
71+
"us-east-1f"
5972
]
6073
}

cloudformation/scenarios/localgov-drupal/cdk/lib/constructs/compute.ts

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import * as cdk from 'aws-cdk-lib';
22
import * as ec2 from 'aws-cdk-lib/aws-ec2';
3-
import * as ecr from 'aws-cdk-lib/aws-ecr';
43
import * as ecs from 'aws-cdk-lib/aws-ecs';
54
import * as efs from 'aws-cdk-lib/aws-efs';
65
import * as elbv2 from 'aws-cdk-lib/aws-elasticloadbalancingv2';
@@ -133,8 +132,10 @@ export class ComputeConstruct extends Construct {
133132

134133
// ==========================================================================
135134
// Task Execution Role (for pulling images and logging)
135+
// Role name must match SCP pattern: InnovationSandbox-ndx*
136136
// ==========================================================================
137137
const executionRole = new iam.Role(this, 'ExecutionRole', {
138+
roleName: `InnovationSandbox-ndx-${deploymentMode}-exec`,
138139
assumedBy: new iam.ServicePrincipal('ecs-tasks.amazonaws.com'),
139140
managedPolicies: [
140141
iam.ManagedPolicy.fromAwsManagedPolicyName('service-role/AmazonECSTaskExecutionRolePolicy'),
@@ -146,8 +147,10 @@ export class ComputeConstruct extends Construct {
146147

147148
// ==========================================================================
148149
// Task Role (for AWS AI services)
150+
// Role name must match SCP pattern: InnovationSandbox-ndx*
149151
// ==========================================================================
150152
const taskRole = new iam.Role(this, 'TaskRole', {
153+
roleName: `InnovationSandbox-ndx-${deploymentMode}-task`,
151154
assumedBy: new iam.ServicePrincipal('ecs-tasks.amazonaws.com'),
152155
});
153156

@@ -264,23 +267,20 @@ export class ComputeConstruct extends Construct {
264267
containerEnvironment.ADMIN_PASSWORD = props.adminPassword;
265268
}
266269

267-
// Look up the ECR repository for the Drupal image
268-
const drupalRepository = ecr.Repository.fromRepositoryAttributes(this, 'DrupalRepo', {
269-
repositoryArn: `arn:aws:ecr:${cdk.Stack.of(this).region}:${cdk.Stack.of(this).account}:repository/localgov-drupal`,
270-
repositoryName: 'localgov-drupal',
271-
});
272-
273-
// Add container
270+
// Add container - pull from GitHub Container Registry
274271
const container = taskDefinition.addContainer('drupal', {
275-
image: ecs.ContainerImage.fromEcrRepository(drupalRepository, 'latest'),
272+
image: ecs.ContainerImage.fromRegistry('ghcr.io/co-cddo/ndx_try_aws_scenarios-localgov_drupal:fix-menu-links-search-index'),
276273
logging: ecs.LogDrivers.awsLogs({
277-
streamPrefix: 'drupal',
278274
logGroup: this.logGroup,
275+
streamPrefix: 'drupal',
279276
}),
280-
environment: containerEnvironment,
281-
secrets: {
282-
DB_USER: ecs.Secret.fromSecretsManager(props.databaseSecret, 'username'),
283-
DB_PASSWORD: ecs.Secret.fromSecretsManager(props.databaseSecret, 'password'),
277+
environment: {
278+
...containerEnvironment,
279+
// Use CloudFormation dynamic references for credentials
280+
// This resolves at deploy time, avoiding ECS secret fetch at runtime
281+
// (workaround for sandbox SCP restrictions on secretsmanager:GetSecretValue)
282+
DB_USER: props.databaseSecret.secretValueFromJson('username').unsafeUnwrap(),
283+
DB_PASSWORD: props.databaseSecret.secretValueFromJson('password').unsafeUnwrap(),
284284
},
285285
portMappings: [
286286
{

0 commit comments

Comments
 (0)