Skip to content

Commit

Permalink
feat: support command override (#284)
Browse files Browse the repository at this point in the history
  • Loading branch information
bpyser authored Mar 28, 2024
1 parent 35d224b commit 9259793
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 0 deletions.
3 changes: 3 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ inputs:
docker-labels:
description: "Create/Override options inside dockerLabels. Each variable is key=value, you can specify multiple variables with multi-line YAML."
required: false
command:
description: 'The command used by ECS to start the container image'
required: false
outputs:
task-definition:
description: 'The path to the rendered task definition file'
Expand Down
5 changes: 5 additions & 0 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ async function run() {
const logConfigurationLogDriver = core.getInput("log-configuration-log-driver", { required: false });
const logConfigurationOptions = core.getInput("log-configuration-options", { required: false });
const dockerLabels = core.getInput('docker-labels', { required: false });
const command = core.getInput('command', { required: false });

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

if (command) {
containerDef.command = command.split(' ')
}

if (environmentVariables) {

// If environment array is missing, create it
Expand Down
5 changes: 5 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ async function run() {
const logConfigurationLogDriver = core.getInput("log-configuration-log-driver", { required: false });
const logConfigurationOptions = core.getInput("log-configuration-options", { required: false });
const dockerLabels = core.getInput('docker-labels', { required: false });
const command = core.getInput('command', { required: false });

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

if (command) {
containerDef.command = command.split(' ')
}

if (environmentVariables) {

// If environment array is missing, create it
Expand Down
71 changes: 71 additions & 0 deletions index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -375,4 +375,75 @@ describe('Render task definition', () => {

expect(core.setFailed).toBeCalledWith('Invalid task definition: Could not find container definition with matching name');
});

test('renders a task definition with docker command', async () => {
core.getInput = jest
.fn()
.mockReturnValueOnce('task-definition.json')
.mockReturnValueOnce('web')
.mockReturnValueOnce('nginx:latest')
.mockReturnValueOnce('EXAMPLE=here')
.mockReturnValueOnce('awslogs')
.mockReturnValueOnce('awslogs-create-group=true\nawslogs-group=/ecs/web\nawslogs-region=us-east-1\nawslogs-stream-prefix=ecs')
.mockReturnValueOnce('key1=value1\nkey2=value2')
.mockReturnValueOnce('npm start --nice --please');

await run();

expect(tmp.fileSync).toHaveBeenNthCalledWith(1, {
tmpdir: '/home/runner/work/_temp',
prefix: 'task-definition-',
postfix: '.json',
keep: true,
discardDescriptor: true
});

expect(fs.writeFileSync).toHaveBeenNthCalledWith(1, 'new-task-def-file-name',
JSON.stringify({
family: 'task-def-family',
containerDefinitions: [
{
name: "web",
image: "nginx:latest",
environment: [
{
name: "FOO",
value: "bar"
},
{
name: "DONT-TOUCH",
value: "me"
},
{
name: "HELLO",
value: "world"
},
{
name: "EXAMPLE",
value: "here"
}
],
logConfiguration: {
logDriver: "awslogs",
options: {
"awslogs-create-group": "true",
"awslogs-group": "/ecs/web",
"awslogs-region": "us-east-1",
"awslogs-stream-prefix": "ecs"
}
},
dockerLabels : {
"key1":"value1",
"key2":"value2"
},
command : ["npm", "start", "--nice", "--please"]
},
{
name: "sidecar",
image: "hello"
}
]
}, null, 2)
);
});
});

0 comments on commit 9259793

Please sign in to comment.