Skip to content
This repository has been archived by the owner on Dec 16, 2024. It is now read-only.

Pass hostPort explicitly in container definitions #464

Merged
merged 2 commits into from
Apr 25, 2018
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 aws/aws_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -548,7 +548,7 @@ func containersRuntimeValidator(region string) func(t *testing.T, stackInfo inte
if !assert.True(t, exists) {
return
}
if !assert.True(t, len(hellowWorldLogs) > 16) {
if !assert.True(t, len(hellowWorldLogs) > 3) {
return
}
assert.Contains(t, getAllMessageText(hellowWorldLogs), "Hello from Docker!")
Expand Down
10 changes: 10 additions & 0 deletions aws/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,16 @@ function computeContainerDefinitions(
const imageOptions = computeImage(imageName, container, ports, repository);
const portMappings = (container.ports || []).map(p => ({
containerPort: p.targetPort || p.port,
// From https://docs.aws.amazon.com/AmazonECS/latest/developerguide/task_definition_parameters.html:
// > For task definitions that use the awsvpc network mode, you should only specify the containerPort.
// > The hostPort can be left blank or it must be the same value as the containerPort.
//
// However, if left blank, it will be automatically populated by AWS, potentially leading to dirty
// diffs even when no changes have been made. Since we are currently always using `awsvpc` mode, we
// go ahead and populate it with the same value as `containerPort`.
//
// See https://github.com/terraform-providers/terraform-provider-aws/issues/3401.
hostPort: p.targetPort || p.port,
}));

// tslint:disable-next-line:max-line-length
Expand Down
7 changes: 1 addition & 6 deletions examples/containers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,12 +164,7 @@ api.get("/", async (req, res) => {
});
api.get("/run", async (req, res) => {
try {
// Launch 4 instances of the Task.
let tasks: Promise<void>[] = [];
for (let i = 0; i < 4; i++) {
tasks.push(helloTask.run());
}
await Promise.all(tasks);
await helloTask.run();
res.json({ success: true });
} catch (err) {
console.error(errorJSON(err));
Expand Down