Skip to content

fix: set networkConfiguration to null when using bridge network mode #617

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

Merged
merged 2 commits into from
Aug 19, 2024
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
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ Registers an Amazon ECS task definition and deploys it to an ECS service.

See [action.yml](action.yml) for the full documentation for this action's inputs and outputs.
In most cases when running a one-off task, subnet ID's, subnet groups, and assign public IP will be required.
Assign public IP will only be applied when a subnet or security group is defined.

### Task definition file

Expand Down Expand Up @@ -269,7 +270,8 @@ In the following example, the service would not be updated until the ad-hoc task
wait-for-task-stopped: true
```

Overrides and VPC networking options are available as well. See [action.yml](action.yml) for more details.
Overrides and VPC networking options are available as well. See [action.yml](action.yml) for more details. The `FARGATE`
launch type requires `awsvpc` network mode in your task definition and you must specify a network configuration.

## Troubleshooting

Expand Down
2 changes: 1 addition & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ inputs:
description: 'A comma-separated list of subnet IDs to assign to a task when run outside of a service. Will default to none.'
required: false
run-task-assign-public-IP:
description: "Whether the task's elastic network interface receives a public IP address. The default value is DISABLED."
description: "Whether the task's elastic network interface receives a public IP address. The default value is DISABLED but will only be applied if run-task-subnets or run-task-security-groups are also set."
required: false
run-task-launch-type:
description: "ECS launch type for tasks run outside of a service. Valid values are 'FARGATE' or 'EC2'. Will default to 'FARGATE'."
Expand Down
6 changes: 3 additions & 3 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@ async function runTask(ecs, clusterName, taskDefArn, waitForMinutes) {
awsvpcConfiguration["securityGroups"] = securityGroupIds.split(',')
}

if(assignPublicIP != ""){
if(assignPublicIP != "" && (subnetIds != "" || securityGroupIds != "")){
Copy link
Contributor

Choose a reason for hiding this comment

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

I think, we should call this out in the action.yml file. in the description of assignPublicIP field.

It would also be great if we could add a line describing the difference in networkconfiguration for different launch types.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok great, I made a few readme + actions.yml description changes. let me know what you think!

awsvpcConfiguration["assignPublicIp"] = assignPublicIP
}

const runTaskResponse = await ecs.runTask({
startedBy: startedBy,
cluster: clusterName,
Expand All @@ -60,7 +60,7 @@ async function runTask(ecs, clusterName, taskDefArn, waitForMinutes) {
containerOverrides: containerOverrides
},
launchType: launchType,
networkConfiguration: Object.keys(awsvpcConfiguration).length === 0 ? {} : { awsvpcConfiguration: awsvpcConfiguration }
networkConfiguration: Object.keys(awsvpcConfiguration).length === 0 ? null : { awsvpcConfiguration: awsvpcConfiguration }
});

core.debug(`Run task response ${JSON.stringify(runTaskResponse)}`)
Expand Down
6 changes: 3 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ async function runTask(ecs, clusterName, taskDefArn, waitForMinutes) {
awsvpcConfiguration["securityGroups"] = securityGroupIds.split(',')
}

if(assignPublicIP != ""){
if(assignPublicIP != "" && (subnetIds != "" || securityGroupIds != "")){
awsvpcConfiguration["assignPublicIp"] = assignPublicIP
}

const runTaskResponse = await ecs.runTask({
startedBy: startedBy,
cluster: clusterName,
Expand All @@ -54,7 +54,7 @@ async function runTask(ecs, clusterName, taskDefArn, waitForMinutes) {
containerOverrides: containerOverrides
},
launchType: launchType,
networkConfiguration: Object.keys(awsvpcConfiguration).length === 0 ? {} : { awsvpcConfiguration: awsvpcConfiguration }
networkConfiguration: Object.keys(awsvpcConfiguration).length === 0 ? null : { awsvpcConfiguration: awsvpcConfiguration }
});

core.debug(`Run task response ${JSON.stringify(runTaskResponse)}`)
Expand Down
32 changes: 31 additions & 1 deletion index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1129,7 +1129,7 @@ describe('Deploy to ECS', () => {
launchType: 'FARGATE',
taskDefinition: 'task:def:arn',
overrides: {"containerOverrides": []},
networkConfiguration: {awsvpcConfiguration: {assignPublicIp: "DISABLED" }}
networkConfiguration: null
});

expect(core.setOutput).toHaveBeenNthCalledWith(2, 'run-task-arn', ["arn:aws:ecs:fake-region:account_id:task/arn"]);
Expand Down Expand Up @@ -1236,6 +1236,36 @@ describe('Deploy to ECS', () => {
expect(waitUntilTasksStopped).toHaveBeenCalledTimes(1);
});

test('run task in bridge network mode', async () => {
core.getInput = jest
.fn()
.mockReturnValueOnce('task-definition.json') // task-definition
.mockReturnValueOnce('service-456') // service
.mockReturnValueOnce('somecluster') // cluster
.mockReturnValueOnce('true') // wait-for-service-stability
.mockReturnValueOnce('') // wait-for-minutes
.mockReturnValueOnce('') // force-new-deployment
.mockReturnValueOnce('') // desired-count
.mockReturnValueOnce('true') // run-task
.mockReturnValueOnce('true') // wait-for-task-stopped
.mockReturnValueOnce('someJoe') // run-task-started-by
.mockReturnValueOnce('EC2') // run-task-launch-type
.mockReturnValueOnce('') // run-task-subnet-ids
.mockReturnValueOnce('') // run-task-security-group-ids
.mockReturnValueOnce('') // run-task-container-overrides
.mockReturnValueOnce('') // run-task-assign-public-IP

await run();
expect(mockRunTask).toHaveBeenCalledWith({
startedBy: 'someJoe',
cluster: 'somecluster',
taskDefinition: 'task:def:arn',
launchType: 'EC2',
overrides: { containerOverrides: [] },
networkConfiguration: null
});
});

test('error is caught if run task fails with (wait-for-task-stopped: true)', async () => {
core.getInput = jest
.fn()
Expand Down
Loading