Skip to content

Commit

Permalink
fix(ecs): correct logic of healthcheck command (aws#2462)
Browse files Browse the repository at this point in the history
Adding a healthcheck command to an ECS container definition
results in an invalid command after synthesizing.

Before:

    Input: ['CMD', 'command']
    Output:
          HealthCheck:
            Command:
              - CMD
              - CMD
              - echo
              - z

    Input: ['CMD-SHELL', 'command']
    Output:
          HealthCheck:
            Command:
              - CMD
              - CMD-SHELL
              - echo
              - z

After:

    Input: ['CMD', 'command']
    Output:
          HealthCheck:
            Command:
              - CMD
              - echo
              - z

    Input: ['CMD-SHELL', 'command']
    Output:
          HealthCheck:
            Command:
              - CMD-SHELL
              - echo
              - z

fixes aws#2461

Signed-off-by: Chris Lahaye <dev@chrislahaye.com>
  • Loading branch information
Chris Lahaye authored and SanderKnape committed May 14, 2019
1 parent b10b98a commit a761745
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 2 deletions.
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') {
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

0 comments on commit a761745

Please sign in to comment.