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

Adding network params #65

Open
wants to merge 19 commits into
base: master
Choose a base branch
from
Open
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
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ Runs an Amazon ECS task on ECS cluster.
cluster: my-cluster
count: 1
started-by: github-actions-${{ github.actor }}
subnets: ['subnet-asdfasdfadsfasasdfa','subnet-asdfasdfadsfasdfadf']
wait-for-finish: true
```

Expand Down Expand Up @@ -100,6 +101,7 @@ The task definition file can be updated prior to deployment with the new contain
cluster: my-cluster
count: 1
started-by: github-actions-${{ github.actor }}
subnets: ['subnet-asdfasdfadsfasasdfa','subnet-asdfasdfadsfasdfadf']
wait-for-finish: true
```

Expand Down
4 changes: 2 additions & 2 deletions action.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: 'Amazon ECS "Run Task" Action for GitHub Actions'
description: 'Runs an Amazon ECS task'
name: 'Amazon ECS Standalone Task deployment for GitHub Actions'
description: 'Runs a standalone Amazon ECS task'
branding:
icon: 'cloud'
color: 'orange'
Expand Down
36,378 changes: 20,517 additions & 15,861 deletions dist/index.js

Large diffs are not rendered by default.

38 changes: 32 additions & 6 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ const IGNORED_TASK_DEFINITION_ATTRIBUTES = [
'taskDefinitionArn',
'requiresAttributes',
'revision',
'status'
'status',
'registeredAt',
'deregisteredAt',
'registeredBy'
];

const WAIT_DEFAULT_DELAY_SEC = 5;
Expand Down Expand Up @@ -89,6 +92,7 @@ async function run() {
const cluster = core.getInput('cluster', { required: false });
const count = core.getInput('count', { required: true });
const startedBy = core.getInput('started-by', { required: false }) || agent;
const subnets = core.getInput('subnets', { required: true });
const waitForFinish = core.getInput('wait-for-finish', { required: false }) || false;
let waitForMinutes = parseInt(core.getInput('wait-for-minutes', { required: false })) || 30;
if (waitForMinutes > MAX_WAIT_MINUTES) {
Expand Down Expand Up @@ -121,14 +125,36 @@ async function run() {
cluster: clusterName,
taskDefinition: taskDefArn,
count: count,
startedBy: startedBy
startedBy: startedBy,
networkConfiguration: {
awsvpcConfiguration: {
subnets: subnets
},
},
})}`)

console.log(`Running task with ${JSON.stringify({
cluster: clusterName,
taskDefinition: taskDefArn,
count: count,
startedBy: startedBy,
networkConfiguration: {
awsvpcConfiguration: {
subnets: subnets
},
},
})}`)

const runTaskResponse = await ecs.runTask({
cluster: clusterName,
taskDefinition: taskDefArn,
count: count,
startedBy: startedBy
startedBy: startedBy,
networkConfiguration: {
awsvpcConfiguration: {
subnets: subnets
},
},
}).promise();

core.debug(`Run task response ${JSON.stringify(runTaskResponse)}`)
Expand Down Expand Up @@ -161,7 +187,7 @@ async function waitForTasksStopped(ecs, clusterName, taskArns, waitForMinutes) {
const maxAttempts = (waitForMinutes * 60) / WAIT_DEFAULT_DELAY_SEC;

core.debug('Waiting for tasks to stop');

const waitTaskResponse = await ecs.waitFor('tasksStopped', {
cluster: clusterName,
tasks: taskArns,
Expand All @@ -172,7 +198,7 @@ async function waitForTasksStopped(ecs, clusterName, taskArns, waitForMinutes) {
}).promise();

core.debug(`Run task response ${JSON.stringify(waitTaskResponse)}`)

core.info(`All tasks have stopped. Watch progress in the Amazon ECS console: https://console.aws.amazon.com/ecs/home?region=${aws.config.region}#/clusters/${clusterName}/tasks`);
}

Expand All @@ -187,7 +213,7 @@ async function tasksExitCode(ecs, clusterName, taskArns) {
const reasons = containers.map(container => container.reason)

const failuresIdx = [];

exitCodes.filter((exitCode, index) => {
if (exitCode !== 0) {
failuresIdx.push(index)
Expand Down
12 changes: 10 additions & 2 deletions index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ describe('Deploy to ECS', () => {
.mockReturnValueOnce('task-definition.json') // task-definition
.mockReturnValueOnce('cluster-789') // cluster
.mockReturnValueOnce('1') // count
.mockReturnValueOnce('amazon-ecs-run-task-for-github-actions'); // started-by
.mockReturnValueOnce('amazon-ecs-run-task-for-github-actions') // started-by
.mockReturnValueOnce(['subnet-asdfasdfa']); // subnets

process.env = Object.assign(process.env, { GITHUB_WORKSPACE: __dirname });

Expand Down Expand Up @@ -130,7 +131,12 @@ describe('Deploy to ECS', () => {
cluster: 'cluster-789',
taskDefinition: 'task:def:arn',
count: '1',
startedBy: 'amazon-ecs-run-task-for-github-actions'
startedBy: 'amazon-ecs-run-task-for-github-actions',
networkConfiguration: {
awsvpcConfiguration: {
subnets: ['subnet-asdfasdfa']
},
},
});
expect(mockEcsWaiter).toHaveBeenCalledTimes(0);
expect(core.setOutput).toBeCalledWith('task-arn', ['arn:aws:ecs:fake-region:account_id:task/arn']);
Expand All @@ -143,6 +149,7 @@ describe('Deploy to ECS', () => {
.mockReturnValueOnce('cluster-789') // cluster
.mockReturnValueOnce('1') // count
.mockReturnValueOnce('amazon-ecs-run-task-for-github-actions') // started-by
.mockReturnValueOnce(['subnet-123456']) // subnets
.mockReturnValueOnce('true'); // wait-for-finish

await run();
Expand Down Expand Up @@ -222,6 +229,7 @@ describe('Deploy to ECS', () => {
"essential": false
} ],
"requiresCompatibilities": [ "EC2" ],
"registeredAt": 1611690781,
"family": "task-def-family"
}
`;
Expand Down
Loading