Skip to content

Commit d203445

Browse files
committed
Update dist/index.js
1 parent a7d144a commit d203445

File tree

1 file changed

+84
-8
lines changed

1 file changed

+84
-8
lines changed

dist/index.js

Lines changed: 84 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ async function runTask(ecs, clusterName, taskDefArn, waitForMinutes, enableECSMa
3939
const assignPublicIP = core.getInput('run-task-assign-public-IP', { required: false }) || 'DISABLED';
4040
const tags = JSON.parse(core.getInput('run-task-tags', { required: false }) || '[]');
4141
const capacityProviderStrategy = JSON.parse(core.getInput('run-task-capacity-provider-strategy', { required: false }) || '[]');
42+
const runTaskManagedEBSVolumeName = core.getInput('run-task-managed-ebs-volume-name', { required: false }) || '';
43+
const runTaskManagedEBSVolume = core.getInput('run-task-managed-ebs-volume', { required: false }) || '{}';
4244

4345
let awsvpcConfiguration = {}
4446

@@ -53,6 +55,20 @@ async function runTask(ecs, clusterName, taskDefArn, waitForMinutes, enableECSMa
5355
if(assignPublicIP != "" && (subnetIds != "" || securityGroupIds != "")){
5456
awsvpcConfiguration["assignPublicIp"] = assignPublicIP
5557
}
58+
let volumeConfigurations = [];
59+
let taskManagedEBSVolumeObject;
60+
61+
if (runTaskManagedEBSVolumeName != '') {
62+
if (runTaskManagedEBSVolume != '{}') {
63+
taskManagedEBSVolumeObject = convertToManagedEbsVolumeObject(runTaskManagedEBSVolume);
64+
volumeConfigurations = [{
65+
name: runTaskManagedEBSVolumeName,
66+
managedEBSVolume: taskManagedEBSVolumeObject
67+
}];
68+
} else {
69+
core.warning(`run-task-managed-ebs-volume-name provided without run-task-managed-ebs-volume value. VolumeConfigurations property will not be included in the RunTask API call`);
70+
}
71+
}
5672

5773
const runTaskResponse = await ecs.runTask({
5874
startedBy: startedBy,
@@ -65,7 +81,8 @@ async function runTask(ecs, clusterName, taskDefArn, waitForMinutes, enableECSMa
6581
launchType: capacityProviderStrategy.length === 0 ? launchType : null,
6682
networkConfiguration: Object.keys(awsvpcConfiguration).length === 0 ? null : { awsvpcConfiguration: awsvpcConfiguration },
6783
enableECSManagedTags: enableECSManagedTags,
68-
tags: tags
84+
tags: tags,
85+
volumeConfigurations: volumeConfigurations
6986
});
7087

7188
core.debug(`Run task response ${JSON.stringify(runTaskResponse)}`)
@@ -92,6 +109,47 @@ async function runTask(ecs, clusterName, taskDefArn, waitForMinutes, enableECSMa
92109
}
93110
}
94111

112+
function convertToManagedEbsVolumeObject(managedEbsVolume) {
113+
managedEbsVolumeObject = {}
114+
const ebsVolumeObject = JSON.parse(managedEbsVolume);
115+
if ('roleArn' in ebsVolumeObject){ // required property
116+
managedEbsVolumeObject.roleArn = ebsVolumeObject.roleArn;
117+
core.debug(`Found RoleArn ${ebsVolumeObject['roleArn']}`);
118+
} else {
119+
throw new Error('managed-ebs-volume must provide "role-arn" to associate with the EBS volume')
120+
}
121+
122+
if ('encrypted' in ebsVolumeObject) {
123+
managedEbsVolumeObject.encrypted = ebsVolumeObject.encrypted;
124+
}
125+
if ('filesystemType' in ebsVolumeObject) {
126+
managedEbsVolumeObject.filesystemType = ebsVolumeObject.filesystemType;
127+
}
128+
if ('iops' in ebsVolumeObject) {
129+
managedEbsVolumeObject.iops = ebsVolumeObject.iops;
130+
}
131+
if ('kmsKeyId' in ebsVolumeObject) {
132+
managedEbsVolumeObject.kmsKeyId = ebsVolumeObject.kmsKeyId;
133+
}
134+
if ('sizeInGiB' in ebsVolumeObject) {
135+
managedEbsVolumeObject.sizeInGiB = ebsVolumeObject.sizeInGiB;
136+
}
137+
if ('snapshotId' in ebsVolumeObject) {
138+
managedEbsVolumeObject.snapshotId = ebsVolumeObject.snapshotId;
139+
}
140+
if ('tagSpecifications' in ebsVolumeObject) {
141+
managedEbsVolumeObject.tagSpecifications = ebsVolumeObject.tagSpecifications;
142+
}
143+
if (('throughput' in ebsVolumeObject) && (('volumeType' in ebsVolumeObject) && (ebsVolumeObject.volumeType == 'gp3'))){
144+
managedEbsVolumeObject.throughput = ebsVolumeObject.throughput;
145+
}
146+
if ('volumeType' in ebsVolumeObject) {
147+
managedEbsVolumeObject.volumeType = ebsVolumeObject.volumeType;
148+
}
149+
core.debug(`Created managedEbsVolumeObject: ${JSON.stringify(managedEbsVolumeObject)}`);
150+
return managedEbsVolumeObject;
151+
}
152+
95153
// Poll tasks until they enter a stopped state
96154
async function waitForTasksStopped(ecs, clusterName, taskArns, waitForMinutes) {
97155
if (waitForMinutes > MAX_WAIT_MINUTES) {
@@ -142,13 +200,32 @@ async function tasksExitCode(ecs, clusterName, taskArns) {
142200
async function updateEcsService(ecs, clusterName, service, taskDefArn, waitForService, waitForMinutes, forceNewDeployment, desiredCount, enableECSManagedTags, propagateTags) {
143201
core.debug('Updating the service');
144202

203+
const serviceManagedEBSVolumeName = core.getInput('service-managed-ebs-volume-name', { required: false }) || '';
204+
const serviceManagedEBSVolume = core.getInput('service-managed-ebs-volume', { required: false }) || '{}';
205+
206+
let volumeConfigurations = [];
207+
let serviceManagedEbsVolumeObject;
208+
209+
if (serviceManagedEBSVolumeName != '') {
210+
if (serviceManagedEBSVolume != '{}') {
211+
serviceManagedEbsVolumeObject = convertToManagedEbsVolumeObject(serviceManagedEBSVolume);
212+
volumeConfigurations = [{
213+
name: serviceManagedEBSVolumeName,
214+
managedEBSVolume: serviceManagedEbsVolumeObject
215+
}];
216+
} else {
217+
core.warning('service-managed-ebs-volume-name provided without service-managed-ebs-volume value. VolumeConfigurations property will not be included in the UpdateService API call');
218+
}
219+
}
220+
145221
let params = {
146222
cluster: clusterName,
147223
service: service,
148224
taskDefinition: taskDefArn,
149225
forceNewDeployment: forceNewDeployment,
150226
enableECSManagedTags: enableECSManagedTags,
151-
propagateTags: propagateTags
227+
propagateTags: propagateTags,
228+
volumeConfigurations: volumeConfigurations
152229
};
153230

154231
// Add the desiredCount property only if it is defined and a number.
@@ -409,7 +486,11 @@ async function run() {
409486
if (enableECSManagedTagsInput !== '') {
410487
enableECSManagedTags = enableECSManagedTagsInput.toLowerCase() === 'true';
411488
}
412-
let propagateTags = core.getInput('propagate-tags', { required: false }) || '';
489+
const propagateTagsInput = core.getInput('propagate-tags', { required: false }) || '';
490+
let propagateTags = null;
491+
if (propagateTagsInput !== '') {
492+
propagateTags = propagateTagsInput;
493+
}
413494

414495
// Register the task definition
415496
core.debug('Registering the task definition');
@@ -457,11 +538,6 @@ async function run() {
457538
if (serviceResponse.status != 'ACTIVE') {
458539
throw new Error(`Service is ${serviceResponse.status}`);
459540
}
460-
// set propagateTags to the current value if no input provided
461-
if (describeResponse.services[0].propagateTags != null && propagateTags === '') {
462-
propagateTags = describeResponse.services[0].propagateTags;
463-
core.debug(`Current service 'propagateTags' value '${describeResponse.services[0].propagateTags}' will be set to service`);
464-
}
465541

466542
if (!serviceResponse.deploymentController || !serviceResponse.deploymentController.type || serviceResponse.deploymentController.type === 'ECS') {
467543
// Service uses the 'ECS' deployment controller, so we can call UpdateService

0 commit comments

Comments
 (0)