Skip to content

Commit

Permalink
feat: Add assignPublicIp Input
Browse files Browse the repository at this point in the history
  • Loading branch information
dchymko committed Jun 22, 2022
1 parent ab77eed commit b489eca
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
3 changes: 3 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ inputs:
run-task-started-by:
description: "A name to use for the startedBy tag when running a task outside of a service. Will default to 'GitHub-Actions'."
required: false
run-task-assign-public-ip:
description: "A boolean indicating whether to assign a public IP to the task."
required: false
wait-for-task-stopped:
description: 'Whether to wait for the task to stop when running it outside of a service. Will default to not wait.'
required: false
Expand Down
15 changes: 9 additions & 6 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ async function runTask(ecs, clusterName, taskDefArn, waitForMinutes) {
const launchType = core.getInput('run-task-launch-type', { required: false }) || 'FARGATE';
const subnetIds = core.getInput('run-task-subnets', { required: false }) || '';
const securityGroupIds = core.getInput('run-task-security-groups', { required: false }) || '';
const assignPublicIp = core.getInput('run-task-assign-public-ip', { required: false }) || '';
const containerOverrides = JSON.parse(core.getInput('run-task-container-overrides', { required: false }) || '[]');
let awsvpcConfiguration = {}

Expand All @@ -212,6 +213,10 @@ async function runTask(ecs, clusterName, taskDefArn, waitForMinutes) {
awsvpcConfiguration["securityGroups"] = securityGroupIds.split(',')
}

if (assignPublicIp != "") {
awsvpcConfiguration["assignPublicIp"] = assignPublicIp ? "ENABLED" : "DISABLED"
}

const runTaskResponse = await ecs.runTask({
startedBy: startedBy,
cluster: clusterName,
Expand All @@ -227,11 +232,7 @@ async function runTask(ecs, clusterName, taskDefArn, waitForMinutes) {

const taskArns = runTaskResponse.tasks.map(task => task.taskArn);
core.setOutput('run-task-arn', taskArns);

taskArns.map(taskArn => {
let taskId = taskArn.split('/').pop();
core.info(`Task running: https://console.aws.amazon.com/ecs/home?region=${aws.config.region}#/clusters/${clusterName}/tasks`)
});
core.info(`Task running: https://console.aws.amazon.com/ecs/home?region=${aws.config.region}#/clusters/${clusterName}/tasks`);

if (runTaskResponse.failures && runTaskResponse.failures.length > 0) {
const failure = runTaskResponse.failures[0];
Expand Down Expand Up @@ -485,9 +486,11 @@ async function createCodeDeployDeployment(codedeploy, clusterName, service, task
}
}
};

// If it hasn't been set then we don't even want to pass it to the api call to maintain previous behaviour.
if (codeDeployDescription) {
deploymentParams.description = codeDeployDescription
// CodeDeploy Deployment Descriptions have a max length of 512 characters, so truncate if necessary
deploymentParams.description = (codeDeployDescription.length <= 512) ? codeDeployDescription : `${codeDeployDescription.substring(0,511)}…`;
}
const createDeployResponse = await codedeploy.createDeployment(deploymentParams).promise();
core.setOutput('codedeploy-deployment-id', createDeployResponse.deploymentId);
Expand Down
5 changes: 5 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ async function runTask(ecs, clusterName, taskDefArn, waitForMinutes) {
const launchType = core.getInput('run-task-launch-type', { required: false }) || 'FARGATE';
const subnetIds = core.getInput('run-task-subnets', { required: false }) || '';
const securityGroupIds = core.getInput('run-task-security-groups', { required: false }) || '';
const assignPublicIp = core.getInput('run-task-assign-public-ip', { required: false }) || '';
const containerOverrides = JSON.parse(core.getInput('run-task-container-overrides', { required: false }) || '[]');
let awsvpcConfiguration = {}

Expand All @@ -40,6 +41,10 @@ async function runTask(ecs, clusterName, taskDefArn, waitForMinutes) {
awsvpcConfiguration["securityGroups"] = securityGroupIds.split(',')
}

if (assignPublicIp != "") {
awsvpcConfiguration["assignPublicIp"] = assignPublicIp ? "ENABLED" : "DISABLED"
}

const runTaskResponse = await ecs.runTask({
startedBy: startedBy,
cluster: clusterName,
Expand Down

0 comments on commit b489eca

Please sign in to comment.