Skip to content

Commit 0a1e247

Browse files
authored
fix: set networkConfiguration to null when using bridge network mode (#617)
* set networkConfiguration to null when using bridge network mode * update readme
1 parent fd6bd3e commit 0a1e247

File tree

5 files changed

+41
-9
lines changed

5 files changed

+41
-9
lines changed

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ Registers an Amazon ECS task definition and deploys it to an ECS service.
3232
3333
See [action.yml](action.yml) for the full documentation for this action's inputs and outputs.
3434
In most cases when running a one-off task, subnet ID's, subnet groups, and assign public IP will be required.
35+
Assign public IP will only be applied when a subnet or security group is defined.
3536
3637
### Task definition file
3738
@@ -269,7 +270,8 @@ In the following example, the service would not be updated until the ad-hoc task
269270
wait-for-task-stopped: true
270271
```
271272

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

274276
## Troubleshooting
275277

action.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ inputs:
5353
description: 'A comma-separated list of subnet IDs to assign to a task when run outside of a service. Will default to none.'
5454
required: false
5555
run-task-assign-public-IP:
56-
description: "Whether the task's elastic network interface receives a public IP address. The default value is DISABLED."
56+
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."
5757
required: false
5858
run-task-launch-type:
5959
description: "ECS launch type for tasks run outside of a service. Valid values are 'FARGATE' or 'EC2'. Will default to 'FARGATE'."

dist/index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,10 @@ async function runTask(ecs, clusterName, taskDefArn, waitForMinutes) {
4848
awsvpcConfiguration["securityGroups"] = securityGroupIds.split(',')
4949
}
5050

51-
if(assignPublicIP != ""){
51+
if(assignPublicIP != "" && (subnetIds != "" || securityGroupIds != "")){
5252
awsvpcConfiguration["assignPublicIp"] = assignPublicIP
5353
}
54-
54+
5555
const runTaskResponse = await ecs.runTask({
5656
startedBy: startedBy,
5757
cluster: clusterName,
@@ -60,7 +60,7 @@ async function runTask(ecs, clusterName, taskDefArn, waitForMinutes) {
6060
containerOverrides: containerOverrides
6161
},
6262
launchType: launchType,
63-
networkConfiguration: Object.keys(awsvpcConfiguration).length === 0 ? {} : { awsvpcConfiguration: awsvpcConfiguration }
63+
networkConfiguration: Object.keys(awsvpcConfiguration).length === 0 ? null : { awsvpcConfiguration: awsvpcConfiguration }
6464
});
6565

6666
core.debug(`Run task response ${JSON.stringify(runTaskResponse)}`)

index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,10 @@ async function runTask(ecs, clusterName, taskDefArn, waitForMinutes) {
4242
awsvpcConfiguration["securityGroups"] = securityGroupIds.split(',')
4343
}
4444

45-
if(assignPublicIP != ""){
45+
if(assignPublicIP != "" && (subnetIds != "" || securityGroupIds != "")){
4646
awsvpcConfiguration["assignPublicIp"] = assignPublicIP
4747
}
48-
48+
4949
const runTaskResponse = await ecs.runTask({
5050
startedBy: startedBy,
5151
cluster: clusterName,
@@ -54,7 +54,7 @@ async function runTask(ecs, clusterName, taskDefArn, waitForMinutes) {
5454
containerOverrides: containerOverrides
5555
},
5656
launchType: launchType,
57-
networkConfiguration: Object.keys(awsvpcConfiguration).length === 0 ? {} : { awsvpcConfiguration: awsvpcConfiguration }
57+
networkConfiguration: Object.keys(awsvpcConfiguration).length === 0 ? null : { awsvpcConfiguration: awsvpcConfiguration }
5858
});
5959

6060
core.debug(`Run task response ${JSON.stringify(runTaskResponse)}`)

index.test.js

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1129,7 +1129,7 @@ describe('Deploy to ECS', () => {
11291129
launchType: 'FARGATE',
11301130
taskDefinition: 'task:def:arn',
11311131
overrides: {"containerOverrides": []},
1132-
networkConfiguration: {awsvpcConfiguration: {assignPublicIp: "DISABLED" }}
1132+
networkConfiguration: null
11331133
});
11341134

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

1239+
test('run task in bridge network mode', async () => {
1240+
core.getInput = jest
1241+
.fn()
1242+
.mockReturnValueOnce('task-definition.json') // task-definition
1243+
.mockReturnValueOnce('service-456') // service
1244+
.mockReturnValueOnce('somecluster') // cluster
1245+
.mockReturnValueOnce('true') // wait-for-service-stability
1246+
.mockReturnValueOnce('') // wait-for-minutes
1247+
.mockReturnValueOnce('') // force-new-deployment
1248+
.mockReturnValueOnce('') // desired-count
1249+
.mockReturnValueOnce('true') // run-task
1250+
.mockReturnValueOnce('true') // wait-for-task-stopped
1251+
.mockReturnValueOnce('someJoe') // run-task-started-by
1252+
.mockReturnValueOnce('EC2') // run-task-launch-type
1253+
.mockReturnValueOnce('') // run-task-subnet-ids
1254+
.mockReturnValueOnce('') // run-task-security-group-ids
1255+
.mockReturnValueOnce('') // run-task-container-overrides
1256+
.mockReturnValueOnce('') // run-task-assign-public-IP
1257+
1258+
await run();
1259+
expect(mockRunTask).toHaveBeenCalledWith({
1260+
startedBy: 'someJoe',
1261+
cluster: 'somecluster',
1262+
taskDefinition: 'task:def:arn',
1263+
launchType: 'EC2',
1264+
overrides: { containerOverrides: [] },
1265+
networkConfiguration: null
1266+
});
1267+
});
1268+
12391269
test('error is caught if run task fails with (wait-for-task-stopped: true)', async () => {
12401270
core.getInput = jest
12411271
.fn()

0 commit comments

Comments
 (0)