Skip to content

Commit 6ebedf4

Browse files
authored
feat: add run-task-capacity-provider-strategy input (#661)
When you use cluster auto scaling, you must specify `capacityProviderStrategy` and not `launchType`. Unfortunately this is not possible to configure when running a one-off task with this action. This adds a new input `run-task-capacity-provider-strategy` which takes a JSON array of capacity provider strategy items. When this is specified, `run-task-launch-type` will not be applied.
1 parent 96cda52 commit 6ebedf4

File tree

4 files changed

+56
-3
lines changed

4 files changed

+56
-3
lines changed

action.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,11 @@ inputs:
5555
run-task-assign-public-IP:
5656
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
58+
run-task-capacity-provider-strategy:
59+
description: 'A JSON array of capacity provider strategy items which should applied when running a task outside of a service. Will default to none.'
60+
required: false
5861
run-task-launch-type:
59-
description: "ECS launch type for tasks run outside of a service. Valid values are 'FARGATE' or 'EC2'. Will default to 'FARGATE'."
62+
description: "ECS launch type for tasks run outside of a service. Valid values are 'FARGATE' or 'EC2'. Will default to 'FARGATE'. Will only be applied if run-task-capacity-provider-strategy is not set."
6063
required: false
6164
run-task-started-by:
6265
description: "A name to use for the startedBy tag when running a task outside of a service. Will default to 'GitHub-Actions'."

dist/index.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ async function runTask(ecs, clusterName, taskDefArn, waitForMinutes, enableECSMa
3838
const containerOverrides = JSON.parse(core.getInput('run-task-container-overrides', { required: false }) || '[]');
3939
const assignPublicIP = core.getInput('run-task-assign-public-IP', { required: false }) || 'DISABLED';
4040
const tags = JSON.parse(core.getInput('run-task-tags', { required: false }) || '[]');
41+
const capacityProviderStrategy = JSON.parse(core.getInput('run-task-capacity-provider-strategy', { required: false }) || '[]');
4142

4243
let awsvpcConfiguration = {}
4344

@@ -60,7 +61,8 @@ async function runTask(ecs, clusterName, taskDefArn, waitForMinutes, enableECSMa
6061
overrides: {
6162
containerOverrides: containerOverrides
6263
},
63-
launchType: launchType,
64+
capacityProviderStrategy: capacityProviderStrategy.length === 0 ? null : capacityProviderStrategy,
65+
launchType: capacityProviderStrategy.length === 0 ? launchType : null,
6466
networkConfiguration: Object.keys(awsvpcConfiguration).length === 0 ? null : { awsvpcConfiguration: awsvpcConfiguration },
6567
enableECSManagedTags: enableECSManagedTags,
6668
tags: tags

index.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ async function runTask(ecs, clusterName, taskDefArn, waitForMinutes, enableECSMa
3232
const containerOverrides = JSON.parse(core.getInput('run-task-container-overrides', { required: false }) || '[]');
3333
const assignPublicIP = core.getInput('run-task-assign-public-IP', { required: false }) || 'DISABLED';
3434
const tags = JSON.parse(core.getInput('run-task-tags', { required: false }) || '[]');
35+
const capacityProviderStrategy = JSON.parse(core.getInput('run-task-capacity-provider-strategy', { required: false }) || '[]');
3536

3637
let awsvpcConfiguration = {}
3738

@@ -54,7 +55,8 @@ async function runTask(ecs, clusterName, taskDefArn, waitForMinutes, enableECSMa
5455
overrides: {
5556
containerOverrides: containerOverrides
5657
},
57-
launchType: launchType,
58+
capacityProviderStrategy: capacityProviderStrategy.length === 0 ? null : capacityProviderStrategy,
59+
launchType: capacityProviderStrategy.length === 0 ? launchType : null,
5860
networkConfiguration: Object.keys(awsvpcConfiguration).length === 0 ? null : { awsvpcConfiguration: awsvpcConfiguration },
5961
enableECSManagedTags: enableECSManagedTags,
6062
tags: tags

index.test.js

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1144,6 +1144,7 @@ describe('Deploy to ECS', () => {
11441144
expect(mockRunTask).toHaveBeenNthCalledWith(1,{
11451145
startedBy: 'GitHub-Actions',
11461146
cluster: 'default',
1147+
capacityProviderStrategy: null,
11471148
launchType: 'FARGATE',
11481149
taskDefinition: 'task:def:arn',
11491150
overrides: {"containerOverrides": []},
@@ -1185,6 +1186,7 @@ describe('Deploy to ECS', () => {
11851186
expect(mockRunTask).toHaveBeenCalledWith({
11861187
startedBy: 'someJoe',
11871188
cluster: 'somecluster',
1189+
capacityProviderStrategy: null,
11881190
launchType: 'EC2',
11891191
taskDefinition: 'task:def:arn',
11901192
overrides: { containerOverrides: [{ name: 'someapp', command: 'somecmd' }] },
@@ -1195,6 +1197,48 @@ describe('Deploy to ECS', () => {
11951197
expect(core.setOutput).toHaveBeenNthCalledWith(2, 'run-task-arn', ["arn:aws:ecs:fake-region:account_id:task/arn"]);
11961198
});
11971199

1200+
test('run task with capacity provider strategy', async () => {
1201+
core.getInput = jest
1202+
.fn()
1203+
.mockReturnValueOnce('task-definition.json') // task-definition
1204+
.mockReturnValueOnce('') // service
1205+
.mockReturnValueOnce('somecluster') // cluster
1206+
.mockReturnValueOnce('') // wait-for-service-stability
1207+
.mockReturnValueOnce('') // wait-for-minutes
1208+
.mockReturnValueOnce('') // force-new-deployment
1209+
.mockReturnValueOnce('') // desired-count
1210+
.mockReturnValueOnce('false') // enable-ecs-managed-tags
1211+
.mockReturnValueOnce('') // propagate-tags
1212+
.mockReturnValueOnce('true') // run-task
1213+
.mockReturnValueOnce('false') // wait-for-task-stopped
1214+
.mockReturnValueOnce('someJoe') // run-task-started-by
1215+
.mockReturnValueOnce('') // run-task-launch-type
1216+
.mockReturnValueOnce('a,b') // run-task-subnet-ids
1217+
.mockReturnValueOnce('c,d') // run-task-security-group-ids
1218+
.mockReturnValueOnce(JSON.stringify([{ name: 'someapp', command: 'somecmd' }])) // run-task-container-overrides
1219+
.mockReturnValueOnce('') // run-task-assign-public-IP
1220+
.mockReturnValueOnce('[{"key": "project", "value": "myproject"}]') // run-task-tags
1221+
.mockReturnValueOnce('[{"capacityProvider":"FARGATE_SPOT","weight":1}]'); // run-task-capacity-provider-strategy
1222+
1223+
await run();
1224+
expect(core.setFailed).toHaveBeenCalledTimes(0);
1225+
1226+
expect(mockEcsRegisterTaskDef).toHaveBeenNthCalledWith(1, { family: 'task-def-family' });
1227+
expect(core.setOutput).toHaveBeenNthCalledWith(1, 'task-definition-arn', 'task:def:arn');
1228+
expect(mockRunTask).toHaveBeenCalledWith({
1229+
startedBy: 'someJoe',
1230+
cluster: 'somecluster',
1231+
capacityProviderStrategy: [{"capacityProvider":"FARGATE_SPOT","weight":1}],
1232+
launchType: null,
1233+
taskDefinition: 'task:def:arn',
1234+
overrides: { containerOverrides: [{ name: 'someapp', command: 'somecmd' }] },
1235+
networkConfiguration: { awsvpcConfiguration: { subnets: ['a', 'b'], securityGroups: ['c', 'd'], assignPublicIp: "DISABLED" } },
1236+
enableECSManagedTags: false,
1237+
tags: [{"key": "project", "value": "myproject"}],
1238+
});
1239+
expect(core.setOutput).toHaveBeenNthCalledWith(2, 'run-task-arn', ["arn:aws:ecs:fake-region:account_id:task/arn"]);
1240+
});
1241+
11981242
test('run task and service ', async () => {
11991243
core.getInput = jest
12001244
.fn()
@@ -1236,6 +1280,7 @@ describe('Deploy to ECS', () => {
12361280
startedBy: 'someJoe',
12371281
cluster: 'somecluster',
12381282
taskDefinition: 'task:def:arn',
1283+
capacityProviderStrategy: null,
12391284
launchType: 'EC2',
12401285
overrides: { containerOverrides: [{ name: 'someapp', command: 'somecmd' }] },
12411286
networkConfiguration: { awsvpcConfiguration: { subnets: ['a', 'b'], securityGroups: ['c', 'd'], assignPublicIp: "DISABLED" } },
@@ -1296,6 +1341,7 @@ describe('Deploy to ECS', () => {
12961341
startedBy: 'someJoe',
12971342
cluster: 'somecluster',
12981343
taskDefinition: 'task:def:arn',
1344+
capacityProviderStrategy: null,
12991345
launchType: 'EC2',
13001346
overrides: { containerOverrides: [] },
13011347
networkConfiguration: null,

0 commit comments

Comments
 (0)