Skip to content

Commit 8981030

Browse files
committed
"Updated action.yml, index.js, and index.test.js files with changes to capacity provider strategy, task definition, and ECS service updates."
1 parent 3ee2cc6 commit 8981030

File tree

4 files changed

+126
-94
lines changed

4 files changed

+126
-94
lines changed

.idea/workspace.xml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

action.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ inputs:
6767
description: 'Whether to wait for the task to stop when running it outside of a service. Will default to not wait.'
6868
required: false
6969
capacity-provider-strategy:
70-
description: 'Users can use their capacity provider startegy in order to deploy to ECS'
71-
required: false
70+
description: 'Users can use their capacity provider startegy in order to deploy to ECS, Valid values are 'FARGATE', 'EC2' or 'FARGATE_SPOT'. Will default to 'FARGATE'. Launch type must be ommited (not used) in order to use this option. MUST PROVIDE A BASE AND WEIGHT'
71+
required: false
7272

7373
#back to normal inputs
7474
outputs:

index.js

Lines changed: 19 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
const path = require('path');
22
const core = require('@actions/core');
33
const { CodeDeploy, waitUntilDeploymentSuccessful } = require('@aws-sdk/client-codedeploy');
4-
const { ECS, waitUntilServicesStable, waitUntilTasksStopped} = require('@aws-sdk/client-ecs');
4+
const { ECS, waitUntilServicesStable, waitUntilTasksStopped } = require('@aws-sdk/client-ecs');
55
const yaml = require('yaml');
66
const fs = require('fs');
77
const crypto = require('crypto');
@@ -32,6 +32,7 @@ async function runTask(ecs, capacityProviderStrategy, clusterName, taskDefArn, w
3232
const subnetIds = core.getInput('run-task-subnets', { required: false }) || '';
3333
const securityGroupIds = core.getInput('run-task-security-groups', { required: false }) || '';
3434
const containerOverrides = JSON.parse(core.getInput('run-task-container-overrides', { required: false }) || '[]');
35+
3536
let awsvpcConfiguration = {}
3637

3738

@@ -46,26 +47,16 @@ async function runTask(ecs, capacityProviderStrategy, clusterName, taskDefArn, w
4647

4748
const runTaskResponse = await ecs.runTask({
4849
startedBy: startedBy,
49-
capacityProviderStrategy: capacityProviderStrategy,
5050
cluster: clusterName,
5151
taskDefinition: taskDefArn,
5252
overrides: {
5353
containerOverrides: containerOverrides
5454
},
5555
launchType: launchType,
56-
networkConfiguration: Object.keys(awsvpcConfiguration).length === 0 ? {} : { awsvpcConfiguration: awsvpcConfiguration }
57-
});
58-
59-
60-
61-
if (capacityProviderStrategy){
62-
//if the capacity provider is given then the launch type is ommited
63-
launchType = undefined;
64-
}
65-
else{
66-
launchType = 'FARGATE';
67-
}
56+
networkConfiguration: Object.keys(awsvpcConfiguration).length === 0 ? {} : { awsvpcConfiguration: awsvpcConfiguration },
57+
capacityProviderStrategy: capacityProviderStrategy
6858

59+
});
6960

7061

7162
core.debug(`Run task response ${JSON.stringify(runTaskResponse)}`)
@@ -143,24 +134,16 @@ async function tasksExitCode(ecs, clusterName, taskArns) {
143134
// Deploy to a service that uses the 'ECS' deployment controller
144135
async function updateEcsService(ecs, capacityProviderStrategy, clusterName, service, taskDefArn, waitForService, waitForMinutes, forceNewDeployment, desiredCount) {
145136
core.debug('Updating the service');
146-
//const capacityProviderStrategyInput = core.getInput('run-service-capacity-provider-strategy', {required: false}) || 'false';
147-
//const capacityProvider = capacityProviderStrategyInput.toLowerCase() === 'true';
137+
//const capacityProviderStrategy = core.getInput('capacity-provider-strategy',{required: false}) || '{}';
148138

149139
let params = {
150-
capacityProviderStrategy: capacityProviderStrategy,
151140
cluster: clusterName,
152141
service: service,
153142
taskDefinition: taskDefArn,
154-
forceNewDeployment: forceNewDeployment
143+
forceNewDeployment: forceNewDeployment,
144+
capacityProviderStrategy: capacityProviderStrategy
155145
};
156146

157-
if (capacityProvider){
158-
//if the capacity provider is given then the launch type is ommited
159-
launchType = undefined;
160-
}
161-
else{
162-
launchType = launchType || 'FARGATE';
163-
}
164147
// Add the desiredCount property only if it is defined and a number.
165148
if (!isNaN(desiredCount) && desiredCount !== undefined) {
166149
params.desiredCount = desiredCount;
@@ -412,9 +395,17 @@ async function run() {
412395
const forceNewDeployInput = core.getInput('force-new-deployment', { required: false }) || 'false';
413396
const forceNewDeployment = forceNewDeployInput.toLowerCase() === 'true';
414397
const desiredCount = parseInt((core.getInput('desired-count', {required: false})));
415-
const capacityProviderStrategy = core.getInput('capacity-provider-strategy',{required: false}) || '{}';
416-
417-
398+
const capacityProviderStrategy = core.getInput('capacity-provider-strategy',{required: false}) || [{base: 1, capacityProvider: 'FARGATE', weight: 1}];
399+
400+
if(capacityProviderStrategy){
401+
core.debug('Using capacity provider ommits the launchtype option')
402+
launchType = undefined;
403+
}
404+
else{
405+
core.debug('Using launch type ommits the capacity provider option')
406+
launchType = 'FARGATE' ;
407+
}
408+
418409
// Register the task definition
419410
core.debug('Registering the task definition');
420411
const taskDefPath = path.isAbsolute(taskDefinitionFile) ?

0 commit comments

Comments
 (0)