-
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: ability to configure log driver and log options #255
Changes from 1 commit
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 |
---|---|---|
|
@@ -12,6 +12,9 @@ async function run() { | |
|
||
const environmentVariables = core.getInput('environment-variables', { required: false }); | ||
|
||
const logConfigurationLogDriver = core.getInput("log-configuration-log-driver", { required: false }); | ||
const logConfigurationOptions = core.getInput("log-configuration-options", { required: false }); | ||
|
||
// Parse the task definition | ||
const taskDefPath = path.isAbsolute(taskDefinitionFile) ? | ||
taskDefinitionFile : | ||
|
@@ -25,7 +28,7 @@ async function run() { | |
if (!Array.isArray(taskDefContents.containerDefinitions)) { | ||
throw new Error('Invalid task definition format: containerDefinitions section is not present or is not an array'); | ||
} | ||
const containerDef = taskDefContents.containerDefinitions.find(function(element) { | ||
const containerDef = taskDefContents.containerDefinitions.find(function (element) { | ||
return element.name == containerName; | ||
}); | ||
if (!containerDef) { | ||
|
@@ -50,7 +53,7 @@ async function run() { | |
const separatorIdx = trimmedLine.indexOf("="); | ||
// If there's nowhere to split | ||
if (separatorIdx === -1) { | ||
throw new Error(`Cannot parse the environment variable '${trimmedLine}'. Environment variable pairs must be of the form NAME=value.`); | ||
throw new Error(`Cannot parse the environment variable '${trimmedLine}'. Environment variable pairs must be of the form NAME=value.`); | ||
} | ||
// Build object | ||
const variable = { | ||
|
@@ -70,6 +73,29 @@ async function run() { | |
}) | ||
} | ||
|
||
if (logConfigurationLogDriver) { | ||
if (!containerDef.logConfiguration) { containerDef.logConfiguration = {} } | ||
const validDrivers = ["json-file", "syslog", "journald", "gelf", "fluentd", "awslogs", "splunk", "awsfirelens"]; | ||
if (!validDrivers.find(driver => driver === logConfigurationLogDriver)) { | ||
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. can this be simplified?
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. i could remove the link to the documentation or the valid options list. what do you think? 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. what i mean by this comment is that instead of using array function in L79. 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. ahhh right away! |
||
throw new Error(`'${logConfigurationLogDriver}' is invalid logConfigurationLogDriver. valid options are ${validDrivers}. More details: https://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_LogConfiguration.html`) | ||
} | ||
containerDef.logConfiguration.logDriver = logConfigurationLogDriver | ||
} | ||
|
||
if (logConfigurationOptions) { | ||
if (!containerDef.logConfiguration) { containerDef.logConfiguration = {} } | ||
if (!containerDef.logConfiguration.options) { containerDef.logConfiguration.options = {} } | ||
logConfigurationOptions.split("\n").forEach(function (option) { | ||
option = option.trim(); | ||
if (option && option.length) { // not a blank line | ||
if (option.indexOf("=") == -1) { | ||
throw new Error(`Can't parse logConfiguration option ${option}. Must be in key=value format, one per line`); | ||
} | ||
const [key, value] = option.split("="); | ||
containerDef.logConfiguration.options[key] = value | ||
} | ||
}) | ||
} | ||
|
||
// Write out a new task definition file | ||
var updatedTaskDefFile = tmp.fileSync({ | ||
|
@@ -92,5 +118,5 @@ module.exports = run; | |
|
||
/* istanbul ignore next */ | ||
if (require.main === module) { | ||
run(); | ||
run(); | ||
} |
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.
Currently for the ECS task, these are the log configurations that are supported.
For tasks on AWS Fargate, the supported log drivers are
awslogs, splunk, and awsfirelens
For tasks hosted on Amazon EC2 instances, the supported log drivers are
awslogs, fluentd, gelf, json-file, journald, logentries, syslog, splunk, and awsfirelens
.Are we assuming these drivers for ECS Tasks based on Ec2 instance? if this is the case do we need to add
logentries
as well ?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.
my current scenario is for fargate but yes, let's add logentries!