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: adds env-files input to the github action #235

Merged
merged 5 commits into from
May 10, 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 @@ -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'
Expand Down
20 changes: 18 additions & 2 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
Expand Down Expand Up @@ -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
Expand Down
20 changes: 18 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
Expand Down Expand Up @@ -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
Expand Down
47 changes: 45 additions & 2 deletions index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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' });
Expand All @@ -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"
}
]
},
{
Expand Down Expand Up @@ -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"
}
]
},
{
Expand All @@ -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: [
Expand All @@ -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",
Expand All @@ -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`);

Expand Down Expand Up @@ -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: {
Expand Down Expand Up @@ -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');
Expand Down Expand Up @@ -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: {
Expand Down Expand Up @@ -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');
Expand Down Expand Up @@ -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')
Expand Down Expand Up @@ -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: {
Expand Down
Loading