Skip to content

Commit 9259793

Browse files
authored
feat: support command override (#284)
1 parent 35d224b commit 9259793

File tree

4 files changed

+84
-0
lines changed

4 files changed

+84
-0
lines changed

action.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ inputs:
2525
docker-labels:
2626
description: "Create/Override options inside dockerLabels. Each variable is key=value, you can specify multiple variables with multi-line YAML."
2727
required: false
28+
command:
29+
description: 'The command used by ECS to start the container image'
30+
required: false
2831
outputs:
2932
task-definition:
3033
description: 'The path to the rendered task definition file'

dist/index.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ async function run() {
2121
const logConfigurationLogDriver = core.getInput("log-configuration-log-driver", { required: false });
2222
const logConfigurationOptions = core.getInput("log-configuration-options", { required: false });
2323
const dockerLabels = core.getInput('docker-labels', { required: false });
24+
const command = core.getInput('command', { required: false });
2425

2526
// Parse the task definition
2627
const taskDefPath = path.isAbsolute(taskDefinitionFile) ?
@@ -43,6 +44,10 @@ async function run() {
4344
}
4445
containerDef.image = imageURI;
4546

47+
if (command) {
48+
containerDef.command = command.split(' ')
49+
}
50+
4651
if (environmentVariables) {
4752

4853
// If environment array is missing, create it

index.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ async function run() {
1515
const logConfigurationLogDriver = core.getInput("log-configuration-log-driver", { required: false });
1616
const logConfigurationOptions = core.getInput("log-configuration-options", { required: false });
1717
const dockerLabels = core.getInput('docker-labels', { required: false });
18+
const command = core.getInput('command', { required: false });
1819

1920
// Parse the task definition
2021
const taskDefPath = path.isAbsolute(taskDefinitionFile) ?
@@ -37,6 +38,10 @@ async function run() {
3738
}
3839
containerDef.image = imageURI;
3940

41+
if (command) {
42+
containerDef.command = command.split(' ')
43+
}
44+
4045
if (environmentVariables) {
4146

4247
// If environment array is missing, create it

index.test.js

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -375,4 +375,75 @@ describe('Render task definition', () => {
375375

376376
expect(core.setFailed).toBeCalledWith('Invalid task definition: Could not find container definition with matching name');
377377
});
378+
379+
test('renders a task definition with docker command', async () => {
380+
core.getInput = jest
381+
.fn()
382+
.mockReturnValueOnce('task-definition.json')
383+
.mockReturnValueOnce('web')
384+
.mockReturnValueOnce('nginx:latest')
385+
.mockReturnValueOnce('EXAMPLE=here')
386+
.mockReturnValueOnce('awslogs')
387+
.mockReturnValueOnce('awslogs-create-group=true\nawslogs-group=/ecs/web\nawslogs-region=us-east-1\nawslogs-stream-prefix=ecs')
388+
.mockReturnValueOnce('key1=value1\nkey2=value2')
389+
.mockReturnValueOnce('npm start --nice --please');
390+
391+
await run();
392+
393+
expect(tmp.fileSync).toHaveBeenNthCalledWith(1, {
394+
tmpdir: '/home/runner/work/_temp',
395+
prefix: 'task-definition-',
396+
postfix: '.json',
397+
keep: true,
398+
discardDescriptor: true
399+
});
400+
401+
expect(fs.writeFileSync).toHaveBeenNthCalledWith(1, 'new-task-def-file-name',
402+
JSON.stringify({
403+
family: 'task-def-family',
404+
containerDefinitions: [
405+
{
406+
name: "web",
407+
image: "nginx:latest",
408+
environment: [
409+
{
410+
name: "FOO",
411+
value: "bar"
412+
},
413+
{
414+
name: "DONT-TOUCH",
415+
value: "me"
416+
},
417+
{
418+
name: "HELLO",
419+
value: "world"
420+
},
421+
{
422+
name: "EXAMPLE",
423+
value: "here"
424+
}
425+
],
426+
logConfiguration: {
427+
logDriver: "awslogs",
428+
options: {
429+
"awslogs-create-group": "true",
430+
"awslogs-group": "/ecs/web",
431+
"awslogs-region": "us-east-1",
432+
"awslogs-stream-prefix": "ecs"
433+
}
434+
},
435+
dockerLabels : {
436+
"key1":"value1",
437+
"key2":"value2"
438+
},
439+
command : ["npm", "start", "--nice", "--please"]
440+
},
441+
{
442+
name: "sidecar",
443+
image: "hello"
444+
}
445+
]
446+
}, null, 2)
447+
);
448+
});
378449
});

0 commit comments

Comments
 (0)