Skip to content

Commit a40f6ea

Browse files
authored
Merge pull request #235 from bmbferreira/master
feat: adds env-files input to the github action
2 parents 5f07eab + 8247a1a commit a40f6ea

File tree

4 files changed

+84
-6
lines changed

4 files changed

+84
-6
lines changed

action.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ inputs:
2828
command:
2929
description: 'The command used by ECS to start the container image'
3030
required: false
31+
env-files:
32+
description: 'S3 object arns to set env variables onto the container. You can specify multiple files with multi-line YAML strings.'
33+
required: false
3134
outputs:
3235
task-definition:
3336
description: 'The path to the rendered task definition file'

dist/index.js

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ async function run() {
1616
const containerName = core.getInput('container-name', { required: true });
1717
const imageURI = core.getInput('image', { required: true });
1818
const environmentVariables = core.getInput('environment-variables', { required: false });
19+
const envFiles = core.getInput('env-files', { required: false });
20+
1921
const logConfigurationLogDriver = core.getInput("log-configuration-log-driver", { required: false });
2022
const logConfigurationOptions = core.getInput("log-configuration-options", { required: false });
2123
const dockerLabels = core.getInput('docker-labels', { required: false });
@@ -46,13 +48,27 @@ async function run() {
4648
containerDef.command = command.split(' ')
4749
}
4850

49-
if (environmentVariables) {
51+
if (envFiles) {
52+
containerDef.environmentFiles = [];
53+
envFiles.split('\n').forEach(function (line) {
54+
// Trim whitespace
55+
const trimmedLine = line.trim();
56+
// Skip if empty
57+
if (trimmedLine.length === 0) { return; }
58+
// Build object
59+
const variable = {
60+
value: trimmedLine,
61+
type: "s3",
62+
};
63+
containerDef.environmentFiles.push(variable);
64+
})
65+
}
5066

67+
if (environmentVariables) {
5168
// If environment array is missing, create it
5269
if (!Array.isArray(containerDef.environment)) {
5370
containerDef.environment = [];
5471
}
55-
5672
// Get pairs by splitting on newlines
5773
environmentVariables.split('\n').forEach(function (line) {
5874
// Trim whitespace

index.js

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ async function run() {
1010
const containerName = core.getInput('container-name', { required: true });
1111
const imageURI = core.getInput('image', { required: true });
1212
const environmentVariables = core.getInput('environment-variables', { required: false });
13+
const envFiles = core.getInput('env-files', { required: false });
14+
1315
const logConfigurationLogDriver = core.getInput("log-configuration-log-driver", { required: false });
1416
const logConfigurationOptions = core.getInput("log-configuration-options", { required: false });
1517
const dockerLabels = core.getInput('docker-labels', { required: false });
@@ -40,13 +42,27 @@ async function run() {
4042
containerDef.command = command.split(' ')
4143
}
4244

43-
if (environmentVariables) {
45+
if (envFiles) {
46+
containerDef.environmentFiles = [];
47+
envFiles.split('\n').forEach(function (line) {
48+
// Trim whitespace
49+
const trimmedLine = line.trim();
50+
// Skip if empty
51+
if (trimmedLine.length === 0) { return; }
52+
// Build object
53+
const variable = {
54+
value: trimmedLine,
55+
type: "s3",
56+
};
57+
containerDef.environmentFiles.push(variable);
58+
})
59+
}
4460

61+
if (environmentVariables) {
4562
// If environment array is missing, create it
4663
if (!Array.isArray(containerDef.environment)) {
4764
containerDef.environment = [];
4865
}
49-
5066
// Get pairs by splitting on newlines
5167
environmentVariables.split('\n').forEach(function (line) {
5268
// Trim whitespace

index.test.js

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ describe('Render task definition', () => {
2727
.mockReturnValueOnce('task-definition.json') // task-definition
2828
.mockReturnValueOnce('web') // container-name
2929
.mockReturnValueOnce('nginx:latest') // image
30-
.mockReturnValueOnce('FOO=bar\nHELLO=world'); // environment-variables
30+
.mockReturnValueOnce('FOO=bar\nHELLO=world') // environment-variables
31+
.mockReturnValueOnce('arn:aws:s3:::s3_bucket_name/envfile_object_name.env'); // env-files
3132

3233
process.env = Object.assign(process.env, { GITHUB_WORKSPACE: __dirname });
3334
process.env = Object.assign(process.env, { RUNNER_TEMP: '/home/runner/work/_temp' });
@@ -53,6 +54,12 @@ describe('Render task definition', () => {
5354
name: "DONT-TOUCH",
5455
value: "me"
5556
}
57+
],
58+
environmentFiles: [
59+
{
60+
value: "arn:aws:s3:::s3_bucket_name/envfile_object_name.env",
61+
type: "s3"
62+
}
5663
]
5764
},
5865
{
@@ -92,6 +99,12 @@ describe('Render task definition', () => {
9299
name: "HELLO",
93100
value: "world"
94101
}
102+
],
103+
environmentFiles: [
104+
{
105+
value: "arn:aws:s3:::s3_bucket_name/envfile_object_name.env",
106+
type: "s3"
107+
}
95108
]
96109
},
97110
{
@@ -110,7 +123,9 @@ describe('Render task definition', () => {
110123
.mockReturnValueOnce('/hello/task-definition.json') // task-definition
111124
.mockReturnValueOnce('web') // container-name
112125
.mockReturnValueOnce('nginx:latest') // image
113-
.mockReturnValueOnce('EXAMPLE=here'); // environment-variables
126+
.mockReturnValueOnce('EXAMPLE=here') // environment-variables
127+
.mockReturnValueOnce('arn:aws:s3:::s3_bucket_name/envfile_object_name.env'); // env-files
128+
114129
jest.mock('/hello/task-definition.json', () => ({
115130
family: 'task-def-family',
116131
containerDefinitions: [
@@ -137,6 +152,12 @@ describe('Render task definition', () => {
137152
{
138153
name: "web",
139154
image: "nginx:latest",
155+
environmentFiles: [
156+
{
157+
value: "arn:aws:s3:::s3_bucket_name/envfile_object_name.env",
158+
type: "s3"
159+
}
160+
],
140161
environment: [
141162
{
142163
name: "EXAMPLE",
@@ -157,6 +178,7 @@ describe('Render task definition', () => {
157178
.mockReturnValueOnce('web')
158179
.mockReturnValueOnce('nginx:latest')
159180
.mockReturnValueOnce('FOO=bar\nHELLO=world')
181+
.mockReturnValueOnce('arn:aws:s3:::s3_bucket_name/envfile_object_name.env')
160182
.mockReturnValueOnce('awslogs')
161183
.mockReturnValueOnce(`awslogs-create-group=true\nawslogs-group=/ecs/web\nawslogs-region=us-east-1\nawslogs-stream-prefix=ecs`);
162184

@@ -192,6 +214,12 @@ describe('Render task definition', () => {
192214
value: "world"
193215
}
194216
],
217+
environmentFiles: [
218+
{
219+
value: "arn:aws:s3:::s3_bucket_name/envfile_object_name.env",
220+
type: "s3"
221+
}
222+
],
195223
logConfiguration: {
196224
logDriver: "awslogs",
197225
options: {
@@ -231,6 +259,7 @@ describe('Render task definition', () => {
231259
.mockReturnValueOnce('web')
232260
.mockReturnValueOnce('nginx:latest')
233261
.mockReturnValueOnce('EXAMPLE=here')
262+
.mockReturnValueOnce('arn:aws:s3:::s3_bucket_name/envfile_object_name.env')
234263
.mockReturnValueOnce('awslogs')
235264
.mockReturnValueOnce('awslogs-create-group=true\nawslogs-group=/ecs/web\nawslogs-region=us-east-1\nawslogs-stream-prefix=ecs')
236265
.mockReturnValueOnce('key1=value1\nkey2=value2');
@@ -270,6 +299,12 @@ describe('Render task definition', () => {
270299
value: "here"
271300
}
272301
],
302+
environmentFiles: [
303+
{
304+
value: "arn:aws:s3:::s3_bucket_name/envfile_object_name.env",
305+
type: "s3"
306+
}
307+
],
273308
logConfiguration: {
274309
logDriver: "awslogs",
275310
options: {
@@ -300,6 +335,7 @@ describe('Render task definition', () => {
300335
.mockReturnValueOnce('web')
301336
.mockReturnValueOnce('nginx:latest')
302337
.mockReturnValueOnce('EXAMPLE=here')
338+
.mockReturnValueOnce('arn:aws:s3:::s3_bucket_name/envfile_object_name.env')
303339
.mockReturnValueOnce('awslogs')
304340
.mockReturnValueOnce('awslogs-create-group=true\nawslogs-group=/ecs/web\nawslogs-region=us-east-1\nawslogs-stream-prefix=ecs')
305341
.mockReturnValueOnce('key1=update_value1\nkey2\nkey3=value3');
@@ -383,6 +419,7 @@ describe('Render task definition', () => {
383419
.mockReturnValueOnce('web')
384420
.mockReturnValueOnce('nginx:latest')
385421
.mockReturnValueOnce('EXAMPLE=here')
422+
.mockReturnValueOnce('arn:aws:s3:::s3_bucket_name/envfile_object_name.env')
386423
.mockReturnValueOnce('awslogs')
387424
.mockReturnValueOnce('awslogs-create-group=true\nawslogs-group=/ecs/web\nawslogs-region=us-east-1\nawslogs-stream-prefix=ecs')
388425
.mockReturnValueOnce('key1=value1\nkey2=value2')
@@ -423,6 +460,12 @@ describe('Render task definition', () => {
423460
value: "here"
424461
}
425462
],
463+
environmentFiles: [
464+
{
465+
value: "arn:aws:s3:::s3_bucket_name/envfile_object_name.env",
466+
type: "s3"
467+
}
468+
],
426469
logConfiguration: {
427470
logDriver: "awslogs",
428471
options: {

0 commit comments

Comments
 (0)