-
Notifications
You must be signed in to change notification settings - Fork 144
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 for setting environment secrets, and other task-def params #204
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,30 @@ inputs: | |
environment-variables: | ||
description: 'Variables to add to the container. Each variable is of the form KEY=value, you can specify multiple variables with multi-line YAML strings.' | ||
required: false | ||
environment-secrets: | ||
description: 'Secrets to add to the container. Each secret is of the form KEY=value, you can specify multiple variables with multi-line YAML strings.' | ||
required: false | ||
family: | ||
description: 'task-def family' | ||
required: false | ||
cpu: | ||
description: 'CPU' | ||
required: false | ||
memory: | ||
description: 'Memory' | ||
required: false | ||
executionRoleArn: | ||
description: 'executionRoleArn' | ||
required: false | ||
taskRoleArn: | ||
description: 'taskRoleArn' | ||
required: false | ||
awslogs-group: | ||
description: 'awslogs-group' | ||
required: false | ||
awslogs-region: | ||
description: 'awslogs-region' | ||
required: false | ||
Comment on lines
+23
to
+42
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Question; is the expectation here that some of this changes between github action execution? Until now, we haven't added these fields into the github action config because we supply a task def json and then we read the parameters that change and inline them into the task definition. But I'm wondering if there is a usecase that we've missed. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah some of these might not be needed like the logs, and task arns since you can just use the names. To be honest I think the biggest item needed is secret arns since they do contain the AWS Account Id and would prefer not to commit that in the repo. |
||
outputs: | ||
task-definition: | ||
description: 'The path to the rendered task definition file' | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,10 +7,20 @@ async function run() { | |
try { | ||
// Get inputs | ||
const taskDefinitionFile = core.getInput('task-definition', { required: true }); | ||
const containerName = core.getInput('container-name', { required: true }); | ||
|
||
const family = core.getInput('family', { required: false }); | ||
const cpu = core.getInput('cpu', { required: false }); | ||
const memory = core.getInput('memory', { required: false }); | ||
const executionRoleArn = core.getInput('executionRoleArn', { required: false }); | ||
const taskRoleArn = core.getInput('taskRoleArn', { required: false }); | ||
|
||
const containerName = core.getInput('container-name', { required: false }); | ||
const imageURI = core.getInput('image', { required: true }); | ||
const awslogsGroup = core.getInput('awslogs-group', { required: false }); | ||
const awslogsRegion = core.getInput('awslogs-region', { required: false }); | ||
|
||
const environmentVariables = core.getInput('environment-variables', { required: false }); | ||
const environmentSecrets = core.getInput('environment-secrets', { required: false }); | ||
|
||
// Parse the task definition | ||
const taskDefPath = path.isAbsolute(taskDefinitionFile) ? | ||
|
@@ -33,6 +43,26 @@ async function run() { | |
} | ||
containerDef.image = imageURI; | ||
|
||
if (family) { | ||
taskDefContents.family = family; | ||
} | ||
|
||
if (cpu) { | ||
taskDefContents.cpu = cpu; | ||
} | ||
|
||
if (memory) { | ||
taskDefContents.memory = memory; | ||
} | ||
|
||
if (executionRoleArn) { | ||
taskDefContents.executionRoleArn = executionRoleArn; | ||
} | ||
|
||
if (taskRoleArn) { | ||
taskDefContents.taskRoleArn = taskRoleArn; | ||
} | ||
|
||
if (environmentVariables) { | ||
|
||
// If environment array is missing, create it | ||
|
@@ -70,6 +100,47 @@ async function run() { | |
}) | ||
} | ||
|
||
if (environmentSecrets) { | ||
|
||
// If environment array is missing, create it | ||
if (!Array.isArray(containerDef.secrets)) { | ||
containerDef.secrets = []; | ||
} | ||
|
||
// Get pairs by splitting on newlines | ||
environmentSecrets.split('\n').forEach(function (line) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit; this could be turned into a |
||
// Trim whitespace | ||
const trimmedLine = line.trim(); | ||
// Skip if empty | ||
if (trimmedLine.length === 0) { return; } | ||
// Split on = | ||
const separatorIdx = trimmedLine.indexOf("="); | ||
// If there's nowhere to split | ||
if (separatorIdx === -1) { | ||
throw new Error(`Cannot parse the environment secret '${trimmedLine}'. Environment secret pairs must be of the form KEY=value.`); | ||
} | ||
// Build object | ||
const secret = { | ||
name: trimmedLine.substring(0, separatorIdx), | ||
valueFrom: trimmedLine.substring(separatorIdx + 1), | ||
}; | ||
|
||
// Search container definition environment for one matching name | ||
const variableDef = containerDef.secrets.find((e) => e.name == secret.name); | ||
if (variableDef) { | ||
// If found, update | ||
variableDef.valueFrom = secret.valueFrom; | ||
} else { | ||
// Else, create | ||
containerDef.secrets.push(secret); | ||
} | ||
}) | ||
} | ||
|
||
if (awslogsGroup && awslogsRegion && containerDef.logConfiguration && containerDef.logConfiguration.options) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These options look specific to |
||
containerDef.logConfiguration.options["awslogs-group"] = awslogsGroup; | ||
containerDef.logConfiguration.options["awslogs-region"] = awslogsRegion; | ||
Comment on lines
+141
to
+142
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit; It might also be worthwhile to also include the option to set |
||
} | ||
|
||
// Write out a new task definition file | ||
var updatedTaskDefFile = tmp.fileSync({ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@joshmello can you think about how to add option to get secrets from AWS AppConfig? For example. we can set arn of config. It's will be very useful. Or just read env from file.
(asking because have a lot of env to setup)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
by "environment-secrets" you mean both value from SSM and from Secret Manager right ?