Skip to content

Commit 89b23e0

Browse files
committed
Use managed tags for runTask and document README
1 parent fc02009 commit 89b23e0

File tree

3 files changed

+30
-10
lines changed

3 files changed

+30
-10
lines changed

README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,21 @@ The task definition file can be updated prior to deployment with the new contain
104104
wait-for-service-stability: true
105105
```
106106

107+
### Tags
108+
109+
To turn on [Amazon ECS-managed tags](https://docs.aws.amazon.com/AmazonECS/latest/developerguide/ecs-using-tags.html#managed-tags) `aws:ecs:serviceName` and `aws:ecs:clusterName` for the tasks in the service or the task set `enable-ecs-managed-tags`:
110+
111+
```yaml
112+
- name: Deploy Amazon ECS task definition
113+
uses: aws-actions/amazon-ecs-deploy-task-definition@v2
114+
with:
115+
task-definition: task-definition.json
116+
service: my-service
117+
cluster: my-cluster
118+
wait-for-service-stability: true
119+
enable-ecs-managed-tags: true
120+
```
121+
107122
## Credentials and Region
108123

109124
This action relies on the [default behavior of the AWS SDK for Javascript](https://docs.aws.amazon.com/sdk-for-javascript/v2/developer-guide/setting-credentials-node.html) to determine AWS credentials and region.

index.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ const IGNORED_TASK_DEFINITION_ATTRIBUTES = [
2121
];
2222

2323
// Method to run a stand-alone task with desired inputs
24-
async function runTask(ecs, clusterName, taskDefArn, waitForMinutes) {
24+
async function runTask(ecs, clusterName, taskDefArn, waitForMinutes, enableECSManagedTags) {
2525
core.info('Running task')
2626

2727
const waitForTask = core.getInput('wait-for-task-stopped', { required: false }) || 'false';
@@ -54,7 +54,8 @@ async function runTask(ecs, clusterName, taskDefArn, waitForMinutes) {
5454
containerOverrides: containerOverrides
5555
},
5656
launchType: launchType,
57-
networkConfiguration: Object.keys(awsvpcConfiguration).length === 0 ? null : { awsvpcConfiguration: awsvpcConfiguration }
57+
networkConfiguration: Object.keys(awsvpcConfiguration).length === 0 ? null : { awsvpcConfiguration: awsvpcConfiguration },
58+
enableECSManagedTags: enableECSManagedTags
5859
});
5960

6061
core.debug(`Run task response ${JSON.stringify(runTaskResponse)}`)
@@ -421,7 +422,7 @@ async function run() {
421422
core.debug(`shouldRunTask: ${shouldRunTask}`);
422423
if (shouldRunTask) {
423424
core.debug("Running ad-hoc task...");
424-
await runTask(ecs, clusterName, taskDefArn, waitForMinutes);
425+
await runTask(ecs, clusterName, taskDefArn, waitForMinutes, enableECSManagedTags);
425426
}
426427

427428
// Update the service with the new task definition

index.test.js

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1121,9 +1121,9 @@ describe('Deploy to ECS', () => {
11211121
.mockReturnValueOnce('') // cluster
11221122
.mockReturnValueOnce('') // wait-for-service-stability
11231123
.mockReturnValueOnce('') // wait-for-minutes
1124+
.mockReturnValueOnce('') // enable-ecs-managed-tags
11241125
.mockReturnValueOnce('') // force-new-deployment
11251126
.mockReturnValueOnce('') // desired-count
1126-
.mockReturnValueOnce('') // enable-ecs-managed-tags
11271127
.mockReturnValueOnce('true'); // run-task
11281128

11291129
await run();
@@ -1138,7 +1138,8 @@ describe('Deploy to ECS', () => {
11381138
launchType: 'FARGATE',
11391139
taskDefinition: 'task:def:arn',
11401140
overrides: {"containerOverrides": []},
1141-
networkConfiguration: null
1141+
networkConfiguration: null,
1142+
enableECSManagedTags: false
11421143
});
11431144

11441145
expect(core.setOutput).toHaveBeenNthCalledWith(2, 'run-task-arn', ["arn:aws:ecs:fake-region:account_id:task/arn"]);
@@ -1174,7 +1175,8 @@ describe('Deploy to ECS', () => {
11741175
launchType: 'EC2',
11751176
taskDefinition: 'task:def:arn',
11761177
overrides: { containerOverrides: [{ name: 'someapp', command: 'somecmd' }] },
1177-
networkConfiguration: { awsvpcConfiguration: { subnets: ['a', 'b'], securityGroups: ['c', 'd'], assignPublicIp: "DISABLED" } }
1178+
networkConfiguration: { awsvpcConfiguration: { subnets: ['a', 'b'], securityGroups: ['c', 'd'], assignPublicIp: "DISABLED" } },
1179+
enableECSManagedTags: false
11781180
});
11791181
expect(core.setOutput).toHaveBeenNthCalledWith(2, 'run-task-arn', ["arn:aws:ecs:fake-region:account_id:task/arn"]);
11801182
});
@@ -1220,7 +1222,8 @@ describe('Deploy to ECS', () => {
12201222
taskDefinition: 'task:def:arn',
12211223
launchType: 'EC2',
12221224
overrides: { containerOverrides: [{ name: 'someapp', command: 'somecmd' }] },
1223-
networkConfiguration: { awsvpcConfiguration: { subnets: ['a', 'b'], securityGroups: ['c', 'd'], assignPublicIp: "DISABLED" } }
1225+
networkConfiguration: { awsvpcConfiguration: { subnets: ['a', 'b'], securityGroups: ['c', 'd'], assignPublicIp: "DISABLED" } },
1226+
enableECSManagedTags: false
12241227
});
12251228
expect(core.setOutput).toHaveBeenNthCalledWith(2, 'run-task-arn', ["arn:aws:ecs:fake-region:account_id:task/arn"]);
12261229
});
@@ -1257,9 +1260,9 @@ describe('Deploy to ECS', () => {
12571260
.mockReturnValueOnce('somecluster') // cluster
12581261
.mockReturnValueOnce('true') // wait-for-service-stability
12591262
.mockReturnValueOnce('') // wait-for-minutes
1263+
.mockReturnValueOnce('') // enable-ecs-managed-tags
12601264
.mockReturnValueOnce('') // force-new-deployment
12611265
.mockReturnValueOnce('') // desired-count
1262-
.mockReturnValueOnce('') // enable-ecs-managed-tags
12631266
.mockReturnValueOnce('true') // run-task
12641267
.mockReturnValueOnce('true') // wait-for-task-stopped
12651268
.mockReturnValueOnce('someJoe') // run-task-started-by
@@ -1276,7 +1279,8 @@ describe('Deploy to ECS', () => {
12761279
taskDefinition: 'task:def:arn',
12771280
launchType: 'EC2',
12781281
overrides: { containerOverrides: [] },
1279-
networkConfiguration: null
1282+
networkConfiguration: null,
1283+
enableECSManagedTags: false
12801284
});
12811285
});
12821286

@@ -1453,7 +1457,7 @@ describe('Deploy to ECS', () => {
14531457
.mockReturnValueOnce('') // wait-for-minutes
14541458
.mockReturnValueOnce('') // force-new-deployment
14551459
.mockReturnValueOnce('1') // desired count is number
1456-
.mockReturnValueOnce('true'); // enable-ecs-managed-tags
1460+
.mockReturnValueOnce('true'); // enable-
14571461

14581462
await run();
14591463
expect(core.setFailed).toHaveBeenCalledTimes(0);

0 commit comments

Comments
 (0)