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

fix(ecs): correct logic of healthcheck command #2462

Merged
merged 1 commit into from
May 6, 2019
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion packages/@aws-cdk/aws-ecs/lib/container-definition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,7 @@ function getHealthCheckCommand(hc: HealthCheck): string[] {
return hcCommand;
}

if (cmd[0] !== "CMD" || cmd[0] !== 'CMD-SHELL') {
if (cmd[0] !== "CMD" && cmd[0] !== 'CMD-SHELL') {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a unit test to ensure that this check is working as expected?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pkandasamy91 the existing test should be sufficient.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will add missing tests in a separate PR.

hcCommand.push('CMD');
}

Expand Down
74 changes: 73 additions & 1 deletion packages/@aws-cdk/aws-ecs/test/test.container-definition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ export = {
test.done();
},

'can specify Health Check values'(test: Test) {
'can specify Health Check values in shell form'(test: Test) {
// GIVEN
const stack = new cdk.Stack();
const taskDefinition = new ecs.Ec2TaskDefinition(stack, 'TaskDef');
Expand Down Expand Up @@ -396,6 +396,78 @@ export = {
test.done();
},

'can specify Health Check values in array form starting with CMD-SHELL'(test: Test) {
// GIVEN
const stack = new cdk.Stack();
const taskDefinition = new ecs.Ec2TaskDefinition(stack, 'TaskDef');
const hcCommand = "curl localhost:8000";

// WHEN
taskDefinition.addContainer('cont', {
image: ecs.ContainerImage.fromRegistry('test'),
memoryLimitMiB: 1024,
healthCheck: {
command: ["CMD-SHELL", hcCommand],
intervalSeconds: 20,
retries: 5,
startPeriod: 10
}
});

// THEN
expect(stack).to(haveResourceLike('AWS::ECS::TaskDefinition', {
ContainerDefinitions: [
{
HealthCheck: {
Command: ["CMD-SHELL", hcCommand],
Interval: 20,
Retries: 5,
Timeout: 5,
StartPeriod: 10
},
}
]
}));

test.done();
},

'can specify Health Check values in array form starting with CMD'(test: Test) {
// GIVEN
const stack = new cdk.Stack();
const taskDefinition = new ecs.Ec2TaskDefinition(stack, 'TaskDef');
const hcCommand = "curl localhost:8000";

// WHEN
taskDefinition.addContainer('cont', {
image: ecs.ContainerImage.fromRegistry('test'),
memoryLimitMiB: 1024,
healthCheck: {
command: ["CMD", hcCommand],
intervalSeconds: 20,
retries: 5,
startPeriod: 10
}
});

// THEN
expect(stack).to(haveResourceLike('AWS::ECS::TaskDefinition', {
ContainerDefinitions: [
{
HealthCheck: {
Command: ["CMD", hcCommand],
Interval: 20,
Retries: 5,
Timeout: 5,
StartPeriod: 10
},
}
]
}));

test.done();
},

'can specify private registry credentials'(test: Test) {
// GIVEN
const stack = new cdk.Stack();
Expand Down