Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support command override #284

Merged
merged 1 commit into from
Mar 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
);
});
});