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(aws-ecs-patterns): entryPoint and command support within ApplicationLoadBalancedFargateService and ApplicationLoadBalancedEc2Service #22609

Merged
merged 5 commits into from
Oct 28, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 4 additions & 0 deletions packages/@aws-cdk/aws-ecs-patterns/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ const loadBalancedEcsService = new ecsPatterns.ApplicationLoadBalancedEc2Service
TEST_ENVIRONMENT_VARIABLE1: "test environment variable 1 value",
TEST_ENVIRONMENT_VARIABLE2: "test environment variable 2 value",
},
command: ['command'],
entryPoint: ['entry', 'point'],
},
desiredCount: 2,
});
Expand All @@ -49,6 +51,8 @@ const loadBalancedFargateService = new ecsPatterns.ApplicationLoadBalancedFargat
cpu: 512,
taskImageOptions: {
image: ecs.ContainerImage.fromRegistry("amazon/amazon-ecs-sample"),
command: ['command'],
entryPoint: ['entry', 'point'],
},
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,32 @@ export interface ApplicationLoadBalancedTaskImageOptions {
* @default - No labels.
*/
readonly dockerLabels?: { [key: string]: string };

/**
* The entry point that's passed to the container.
*
* This parameter maps to `Entrypoint` in the [Create a container](https://docs.docker.com/engine/api/v1.38/#operation/ContainerCreate) section
* of the [Docker Remote API](https://docs.docker.com/engine/api/v1.38/) and the `--entrypoint` option to
* [docker run](https://docs.docker.com/engine/reference/commandline/run/).
*
* For more information about the Docker `ENTRYPOINT` parameter, see https://docs.docker.com/engine/reference/builder/#entrypoint.
*
* @default none
*/
readonly entryPoint?: string[];

/**
* The command that's passed to the container. If there are multiple arguments, make sure that each argument is a separated string in the array.
*
* This parameter maps to `Cmd` in the [Create a container](https://docs.docker.com/engine/api/v1.38/#operation/ContainerCreate) section
* of the [Docker Remote API](https://docs.docker.com/engine/api/v1.38/) and the `COMMAND` parameter to
* [docker run](https://docs.docker.com/engine/reference/commandline/run/).
*
* For more information about the Docker `CMD` parameter, see https://docs.docker.com/engine/reference/builder/#cmd.
*
* @default none
*/
readonly command?: string[];
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,8 @@ export class ApplicationLoadBalancedEc2Service extends ApplicationLoadBalancedSe
secrets: taskImageOptions.secrets,
logging: logDriver,
dockerLabels: taskImageOptions.dockerLabels,
command: taskImageOptions.command,
entryPoint: taskImageOptions.entryPoint,
});
container.addPortMappings({
containerPort: taskImageOptions.containerPort || 80,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ export class ApplicationLoadBalancedFargateService extends ApplicationLoadBalanc
environment: taskImageOptions.environment,
secrets: taskImageOptions.secrets,
dockerLabels: taskImageOptions.dockerLabels,
command: taskImageOptions.command,
entryPoint: taskImageOptions.entryPoint,
});
container.addPortMappings({
containerPort: taskImageOptions.containerPort || 80,
Expand Down
8 changes: 8 additions & 0 deletions packages/@aws-cdk/aws-ecs-patterns/test/ec2/l3s.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ test('test ECS loadbalanced construct', () => {
TEST_ENVIRONMENT_VARIABLE2: 'test environment variable 2 value',
},
dockerLabels: { label1: 'labelValue1', label2: 'labelValue2' },
entryPoint: ['echo', 'ecs-is-awesome'],
command: ['/bin/bash'],
},
desiredCount: 2,
});
Expand Down Expand Up @@ -66,6 +68,8 @@ test('test ECS loadbalanced construct', () => {
label1: 'labelValue1',
label2: 'labelValue2',
},
EntryPoint: ['echo', 'ecs-is-awesome'],
Command: ['/bin/bash'],
}),
],
});
Expand Down Expand Up @@ -405,6 +409,8 @@ test('test Fargate loadbalanced construct', () => {
TEST_ENVIRONMENT_VARIABLE2: 'test environment variable 2 value',
},
dockerLabels: { label1: 'labelValue1', label2: 'labelValue2' },
entryPoint: ['echo', 'running-on-fargate'],
command: ['/bin/bash'],
},
desiredCount: 2,
});
Expand Down Expand Up @@ -436,6 +442,8 @@ test('test Fargate loadbalanced construct', () => {
label1: 'labelValue1',
label2: 'labelValue2',
},
EntryPoint: ['echo', 'running-on-fargate'],
Command: ['/bin/bash'],
}),
],
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,50 @@ test('setting ALB deployment controller', () => {
});
});

test('setting a command for taskImageOptions in an ApplicationLoadBalancedFargateService works', () => {
// GIVEN
const stack = new cdk.Stack();

// WHEN
new ecsPatterns.ApplicationLoadBalancedFargateService(stack, 'Service', {
taskImageOptions: {
image: ecs.ContainerImage.fromRegistry('/aws/aws-example-app'),
command: ['./app/bin/start.sh', '--foo'],
},
});
// THEN
Template.fromStack(stack).hasResourceProperties('AWS::ECS::TaskDefinition', {
ContainerDefinitions: [
Match.objectLike({
Image: '/aws/aws-example-app',
Command: ['./app/bin/start.sh', '--foo'],
}),
],
});
});

test('setting an entryPoint for taskImageOptions in an ApplicationLoadBalancedFargateService works', () => {
// GIVEN
const stack = new cdk.Stack();

// WHEN
new ecsPatterns.ApplicationLoadBalancedFargateService(stack, 'Service', {
taskImageOptions: {
image: ecs.ContainerImage.fromRegistry('/aws/aws-example-app'),
entryPoint: ['echo', 'foo'],
},
});
// THEN
Template.fromStack(stack).hasResourceProperties('AWS::ECS::TaskDefinition', {
ContainerDefinitions: [
Match.objectLike({
Image: '/aws/aws-example-app',
EntryPoint: ['echo', 'foo'],
}),
],
});
});

test('setting NLB deployment controller', () => {
// GIVEN
const stack = new cdk.Stack();
Expand Down Expand Up @@ -1165,4 +1209,4 @@ test('NetworkLoadBalancedFargateService multiple capacity provider strategies ar
},
]),
});
});
});