1
1
const path = require ( 'path' ) ;
2
2
const core = require ( '@actions/core' ) ;
3
3
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' ) ;
5
5
const yaml = require ( 'yaml' ) ;
6
6
const fs = require ( 'fs' ) ;
7
7
const crypto = require ( 'crypto' ) ;
@@ -32,6 +32,7 @@ async function runTask(ecs, capacityProviderStrategy, clusterName, taskDefArn, w
32
32
const subnetIds = core . getInput ( 'run-task-subnets' , { required : false } ) || '' ;
33
33
const securityGroupIds = core . getInput ( 'run-task-security-groups' , { required : false } ) || '' ;
34
34
const containerOverrides = JSON . parse ( core . getInput ( 'run-task-container-overrides' , { required : false } ) || '[]' ) ;
35
+
35
36
let awsvpcConfiguration = { }
36
37
37
38
@@ -46,26 +47,16 @@ async function runTask(ecs, capacityProviderStrategy, clusterName, taskDefArn, w
46
47
47
48
const runTaskResponse = await ecs . runTask ( {
48
49
startedBy : startedBy ,
49
- capacityProviderStrategy : capacityProviderStrategy ,
50
50
cluster : clusterName ,
51
51
taskDefinition : taskDefArn ,
52
52
overrides : {
53
53
containerOverrides : containerOverrides
54
54
} ,
55
55
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
68
58
59
+ } ) ;
69
60
70
61
71
62
core . debug ( `Run task response ${ JSON . stringify ( runTaskResponse ) } ` )
@@ -143,24 +134,16 @@ async function tasksExitCode(ecs, clusterName, taskArns) {
143
134
// Deploy to a service that uses the 'ECS' deployment controller
144
135
async function updateEcsService ( ecs , capacityProviderStrategy , clusterName , service , taskDefArn , waitForService , waitForMinutes , forceNewDeployment , desiredCount ) {
145
136
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}) || '{}';
148
138
149
139
let params = {
150
- capacityProviderStrategy : capacityProviderStrategy ,
151
140
cluster : clusterName ,
152
141
service : service ,
153
142
taskDefinition : taskDefArn ,
154
- forceNewDeployment : forceNewDeployment
143
+ forceNewDeployment : forceNewDeployment ,
144
+ capacityProviderStrategy : capacityProviderStrategy
155
145
} ;
156
146
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
- }
164
147
// Add the desiredCount property only if it is defined and a number.
165
148
if ( ! isNaN ( desiredCount ) && desiredCount !== undefined ) {
166
149
params . desiredCount = desiredCount ;
@@ -412,9 +395,17 @@ async function run() {
412
395
const forceNewDeployInput = core . getInput ( 'force-new-deployment' , { required : false } ) || 'false' ;
413
396
const forceNewDeployment = forceNewDeployInput . toLowerCase ( ) === 'true' ;
414
397
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
+
418
409
// Register the task definition
419
410
core . debug ( 'Registering the task definition' ) ;
420
411
const taskDefPath = path . isAbsolute ( taskDefinitionFile ) ?
0 commit comments