diff --git a/action.yml b/action.yml index 462ad136..b9e8a3a0 100644 --- a/action.yml +++ b/action.yml @@ -28,6 +28,9 @@ inputs: command: description: 'The command used by ECS to start the container image' required: false + env-files: + description: 'S3 object arns to set env variables onto the container. You can specify multiple files with multi-line YAML strings.' + required: false outputs: task-definition: description: 'The path to the rendered task definition file' diff --git a/dist/index.js b/dist/index.js index a68c0987..00e4a4b3 100644 --- a/dist/index.js +++ b/dist/index.js @@ -16,6 +16,8 @@ async function run() { const containerName = core.getInput('container-name', { required: true }); const imageURI = core.getInput('image', { required: true }); const environmentVariables = core.getInput('environment-variables', { required: false }); + const envFiles = core.getInput('env-files', { required: false }); + 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 }); @@ -46,13 +48,27 @@ async function run() { containerDef.command = command.split(' ') } - if (environmentVariables) { + if (envFiles) { + containerDef.environmentFiles = []; + envFiles.split('\n').forEach(function (line) { + // Trim whitespace + const trimmedLine = line.trim(); + // Skip if empty + if (trimmedLine.length === 0) { return; } + // Build object + const variable = { + value: trimmedLine, + type: "s3", + }; + containerDef.environmentFiles.push(variable); + }) + } + if (environmentVariables) { // If environment array is missing, create it if (!Array.isArray(containerDef.environment)) { containerDef.environment = []; } - // Get pairs by splitting on newlines environmentVariables.split('\n').forEach(function (line) { // Trim whitespace diff --git a/index.js b/index.js index 283336d7..9bb3227b 100644 --- a/index.js +++ b/index.js @@ -10,6 +10,8 @@ async function run() { const containerName = core.getInput('container-name', { required: true }); const imageURI = core.getInput('image', { required: true }); const environmentVariables = core.getInput('environment-variables', { required: false }); + const envFiles = core.getInput('env-files', { required: false }); + 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 }); @@ -40,13 +42,27 @@ async function run() { containerDef.command = command.split(' ') } - if (environmentVariables) { + if (envFiles) { + containerDef.environmentFiles = []; + envFiles.split('\n').forEach(function (line) { + // Trim whitespace + const trimmedLine = line.trim(); + // Skip if empty + if (trimmedLine.length === 0) { return; } + // Build object + const variable = { + value: trimmedLine, + type: "s3", + }; + containerDef.environmentFiles.push(variable); + }) + } + if (environmentVariables) { // If environment array is missing, create it if (!Array.isArray(containerDef.environment)) { containerDef.environment = []; } - // Get pairs by splitting on newlines environmentVariables.split('\n').forEach(function (line) { // Trim whitespace diff --git a/index.test.js b/index.test.js index 0e019dc4..90a55943 100644 --- a/index.test.js +++ b/index.test.js @@ -27,7 +27,8 @@ describe('Render task definition', () => { .mockReturnValueOnce('task-definition.json') // task-definition .mockReturnValueOnce('web') // container-name .mockReturnValueOnce('nginx:latest') // image - .mockReturnValueOnce('FOO=bar\nHELLO=world'); // environment-variables + .mockReturnValueOnce('FOO=bar\nHELLO=world') // environment-variables + .mockReturnValueOnce('arn:aws:s3:::s3_bucket_name/envfile_object_name.env'); // env-files process.env = Object.assign(process.env, { GITHUB_WORKSPACE: __dirname }); process.env = Object.assign(process.env, { RUNNER_TEMP: '/home/runner/work/_temp' }); @@ -53,6 +54,12 @@ describe('Render task definition', () => { name: "DONT-TOUCH", value: "me" } + ], + environmentFiles: [ + { + value: "arn:aws:s3:::s3_bucket_name/envfile_object_name.env", + type: "s3" + } ] }, { @@ -92,6 +99,12 @@ describe('Render task definition', () => { name: "HELLO", value: "world" } + ], + environmentFiles: [ + { + value: "arn:aws:s3:::s3_bucket_name/envfile_object_name.env", + type: "s3" + } ] }, { @@ -110,7 +123,9 @@ describe('Render task definition', () => { .mockReturnValueOnce('/hello/task-definition.json') // task-definition .mockReturnValueOnce('web') // container-name .mockReturnValueOnce('nginx:latest') // image - .mockReturnValueOnce('EXAMPLE=here'); // environment-variables + .mockReturnValueOnce('EXAMPLE=here') // environment-variables + .mockReturnValueOnce('arn:aws:s3:::s3_bucket_name/envfile_object_name.env'); // env-files + jest.mock('/hello/task-definition.json', () => ({ family: 'task-def-family', containerDefinitions: [ @@ -137,6 +152,12 @@ describe('Render task definition', () => { { name: "web", image: "nginx:latest", + environmentFiles: [ + { + value: "arn:aws:s3:::s3_bucket_name/envfile_object_name.env", + type: "s3" + } + ], environment: [ { name: "EXAMPLE", @@ -157,6 +178,7 @@ describe('Render task definition', () => { .mockReturnValueOnce('web') .mockReturnValueOnce('nginx:latest') .mockReturnValueOnce('FOO=bar\nHELLO=world') + .mockReturnValueOnce('arn:aws:s3:::s3_bucket_name/envfile_object_name.env') .mockReturnValueOnce('awslogs') .mockReturnValueOnce(`awslogs-create-group=true\nawslogs-group=/ecs/web\nawslogs-region=us-east-1\nawslogs-stream-prefix=ecs`); @@ -192,6 +214,12 @@ describe('Render task definition', () => { value: "world" } ], + environmentFiles: [ + { + value: "arn:aws:s3:::s3_bucket_name/envfile_object_name.env", + type: "s3" + } + ], logConfiguration: { logDriver: "awslogs", options: { @@ -231,6 +259,7 @@ describe('Render task definition', () => { .mockReturnValueOnce('web') .mockReturnValueOnce('nginx:latest') .mockReturnValueOnce('EXAMPLE=here') + .mockReturnValueOnce('arn:aws:s3:::s3_bucket_name/envfile_object_name.env') .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'); @@ -270,6 +299,12 @@ describe('Render task definition', () => { value: "here" } ], + environmentFiles: [ + { + value: "arn:aws:s3:::s3_bucket_name/envfile_object_name.env", + type: "s3" + } + ], logConfiguration: { logDriver: "awslogs", options: { @@ -300,6 +335,7 @@ describe('Render task definition', () => { .mockReturnValueOnce('web') .mockReturnValueOnce('nginx:latest') .mockReturnValueOnce('EXAMPLE=here') + .mockReturnValueOnce('arn:aws:s3:::s3_bucket_name/envfile_object_name.env') .mockReturnValueOnce('awslogs') .mockReturnValueOnce('awslogs-create-group=true\nawslogs-group=/ecs/web\nawslogs-region=us-east-1\nawslogs-stream-prefix=ecs') .mockReturnValueOnce('key1=update_value1\nkey2\nkey3=value3'); @@ -383,6 +419,7 @@ describe('Render task definition', () => { .mockReturnValueOnce('web') .mockReturnValueOnce('nginx:latest') .mockReturnValueOnce('EXAMPLE=here') + .mockReturnValueOnce('arn:aws:s3:::s3_bucket_name/envfile_object_name.env') .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') @@ -423,6 +460,12 @@ describe('Render task definition', () => { value: "here" } ], + environmentFiles: [ + { + value: "arn:aws:s3:::s3_bucket_name/envfile_object_name.env", + type: "s3" + } + ], logConfiguration: { logDriver: "awslogs", options: {