Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Expose components of ecs-task, enforce read only root filesystem #2545

Merged
merged 3 commits into from
Dec 20, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/wet-pillows-judge.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@guardian/cdk": minor
---

Expose taskDefinition, containerDefinition and task in ecsruntask
philmcmahon marked this conversation as resolved.
Show resolved Hide resolved
4 changes: 2 additions & 2 deletions src/constructs/ecs/__snapshots__/ecs-task.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,7 @@ exports[`The GuEcsTask pattern should create the correct resources with lots of
},
"Memory": 1024,
"Name": "test-ecs-task-ecs-test-TaskContainer",
"ReadonlyRootFilesystem": false,
"ReadonlyRootFilesystem": true,
},
],
"Cpu": "1024",
Expand Down Expand Up @@ -1192,7 +1192,7 @@ exports[`The GuEcsTask pattern should support overriding the subnets used by the
},
"Memory": 1024,
"Name": "test-ecs-task-ecs-test-TaskContainer",
"ReadonlyRootFilesystem": false,
"ReadonlyRootFilesystem": true,
},
],
"Cpu": "1024",
Expand Down
18 changes: 9 additions & 9 deletions src/constructs/ecs/ecs-task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Alarm, TreatMissingData } from "aws-cdk-lib/aws-cloudwatch";
import { SnsAction } from "aws-cdk-lib/aws-cloudwatch-actions";
import type { ISecurityGroup, ISubnet, IVpc } from "aws-cdk-lib/aws-ec2";
import type { IRepository } from "aws-cdk-lib/aws-ecr";
import type { RepositoryImageProps } from "aws-cdk-lib/aws-ecs";
import type { ContainerDefinition, RepositoryImageProps } from "aws-cdk-lib/aws-ecs";
import {
Cluster,
Compatibility,
Expand Down Expand Up @@ -128,11 +128,6 @@ export interface GuEcsTaskProps extends AppIdentity {
* shoud set this value to `false`.
*/
enableDistributablePolicy?: boolean;
/**
* When this parameter is true, the container is given read-only access to its root file system.
* @default false
*/
readonlyRootFilesystem?: boolean;
/**
* If `true`, CloudWatch Container Insights will be enabled for the cluster
* @default false
Expand Down Expand Up @@ -164,7 +159,10 @@ const getContainer = (config: ContainerConfiguration) => {
*
*/
export class GuEcsTask extends Construct {
stateMachine: StateMachine;
public readonly stateMachine: StateMachine;
public readonly taskDefinition: TaskDefinition;
public readonly containerDefinition: ContainerDefinition;
public readonly task: EcsRunTask;

constructor(scope: GuStack, id: string, props: GuEcsTaskProps) {
super(scope, id);
Expand All @@ -186,7 +184,6 @@ export class GuEcsTask extends Construct {
securityGroups = [],
environmentOverrides,
enableDistributablePolicy = true,
readonlyRootFilesystem = false,
containerInsights = false,
} = props;

Expand Down Expand Up @@ -216,6 +213,7 @@ export class GuEcsTask extends Construct {
operatingSystemFamily: OperatingSystemFamily.of("LINUX"),
},
});
this.taskDefinition = taskDefinition;

const containerDefinition = taskDefinition.addContainer(`${id}-TaskContainer`, {
image: getContainer(containerConfiguration),
Expand All @@ -227,8 +225,9 @@ export class GuEcsTask extends Construct {
streamPrefix: app,
logRetention: 14,
}),
readonlyRootFilesystem,
readonlyRootFilesystem: true,
});
this.containerDefinition = containerDefinition;

if (enableDistributablePolicy) {
const distPolicy = new GuGetDistributablePolicyStatement(scope, { app });
Expand Down Expand Up @@ -256,6 +255,7 @@ export class GuEcsTask extends Construct {
},
],
});
this.task = task;

this.stateMachine = new StateMachine(scope, `${id}-StateMachine`, {
definitionBody: DefinitionBody.fromChainable(task),
Expand Down
Loading