@@ -17,6 +17,7 @@ import (
1717 "github.com/aws/amazon-ecs-cli/ecs-cli/modules/cli/compose/context"
1818 "github.com/aws/amazon-ecs-cli/ecs-cli/modules/cli/compose/entity"
1919 "github.com/aws/amazon-ecs-cli/ecs-cli/modules/cli/compose/entity/types"
20+ "github.com/aws/amazon-ecs-cli/ecs-cli/modules/commands/flags"
2021 "github.com/aws/amazon-ecs-cli/ecs-cli/modules/utils"
2122 "github.com/aws/amazon-ecs-cli/ecs-cli/modules/utils/cache"
2223 composeutils "github.com/aws/amazon-ecs-cli/ecs-cli/modules/utils/compose"
@@ -99,7 +100,8 @@ func (t *Task) Start() error {
99100// if count of running tasks = 0, starts 1
100101// if count != 0, and the task definitions differed, then its stops the old ones and starts the new ones
101102func (t * Task ) Up () error {
102- return t .up (true )
103+ updateTasks := t .Context ().CLIContext .Bool (flags .ForceUpdateFlag )
104+ return t .up (updateTasks )
103105}
104106
105107// Info returns a formatted list of containers (running and stopped) in the current cluster
@@ -108,19 +110,20 @@ func (t *Task) Info(filterLocal bool) (project.InfoSet, error) {
108110 return entity .Info (t , filterLocal )
109111}
110112
111- // Scale finds out the current count of running tasks for this project and scales to the desired count
113+ // Scale finds out the current count of running tasks for this project and scales to the desired count.
114+ // Any run params specified will be taken into account.
112115// if desired = current, noop
113116// if desired > current, stops the extra ones
114117// if desired < current, start new ones (also if current was 0, create a new task definition)
115- func (t * Task ) Scale (expectedCount int ) error {
118+ func (t * Task ) Scale (desiredCount int ) error {
116119 ecsTasks , err := entity .CollectTasksWithStatus (t , ecs .DesiredStatusRunning , true )
117120 if err != nil {
118121 return err
119122 }
120123
121124 observedCount := len (ecsTasks )
122125
123- if expectedCount == observedCount {
126+ if desiredCount == observedCount {
124127 // NoOp
125128 log .WithFields (log.Fields {
126129 "countOfRunningTasks" : observedCount ,
@@ -129,18 +132,18 @@ func (t *Task) Scale(expectedCount int) error {
129132 return nil
130133 }
131134
132- // running more than expected , stop the tasks
133- if expectedCount < observedCount {
134- diff := observedCount - expectedCount
135+ // running more than desired , stop the extra tasks
136+ if desiredCount < observedCount {
137+ diff := observedCount - desiredCount
135138 ecsTasksToStop := []* ecs.Task {}
136139 for i := 0 ; i < diff ; i ++ {
137140 ecsTasksToStop = append (ecsTasksToStop , ecsTasks [i ])
138141 }
139142 return t .stopTasks (ecsTasksToStop )
140143 }
141144
142- // if expected > observed, then run the difference
143- diff := expectedCount - observedCount
145+ // if desired > observed, then run the difference
146+ diff := desiredCount - observedCount
144147
145148 var taskDef string
146149 // if nothing was running, create new task definition
@@ -250,6 +253,7 @@ func (t *Task) stopTasks(ecsTasks []*ecs.Task) error {
250253}
251254
252255// runTasks issues run task request to ECS Service in chunks of count=10
256+ // it always takes into account the latest ECS params
253257func (t * Task ) runTasks (taskDefinition string , totalCount int ) ([]* ecs.Task , error ) {
254258 result := []* ecs.Task {}
255259 chunkSize := 10 // can issue only up to 10 tasks in a RunTask Call
@@ -302,6 +306,7 @@ func convertToECSTaskOverride(overrides map[string][]string) (*ecs.TaskOverride,
302306 return ecsOverrides , nil
303307}
304308
309+ // buildRunTaskInput will account for what is currently specified in ECS Params
305310func (t * Task ) buildRunTaskInput (taskDefinition string , count int , overrides map [string ][]string ) (* ecs.RunTaskInput , error ) {
306311 cluster := t .Context ().CommandConfig .Cluster
307312 launchType := t .Context ().CommandConfig .LaunchType
@@ -356,7 +361,6 @@ func (t *Task) buildRunTaskInput(taskDefinition string, count int, overrides map
356361 runTaskInput .PlacementStrategy = placementStrategy
357362 }
358363
359-
360364 if launchType != "" {
361365 runTaskInput .LaunchType = aws .String (launchType )
362366 }
@@ -373,10 +377,11 @@ func (t *Task) createOne() error {
373377 return t .waitForRunTasks (ecsTask )
374378}
375379
376- // up gets a list of running tasks and if updateTasks is set to true, it updates it with the latest task definition
377- // if count of running tasks = 0, starts 1
378- // if count != 0, and the task definitions differed, then its stops the old ones and starts the new ones
379- func (t * Task ) up (updateTasks bool ) error {
380+ // up gets a list of running tasks. If there are no running tasks, it starts 1 task.
381+ // If there are no running tasks, and either the task definition has changed or
382+ // forceUpdate is specified, then the running tasks are stopped and relaunched
383+ // with the task definition and run parameters in the current call.
384+ func (t * Task ) up (forceUpdate bool ) error {
380385 ecsTasks , err := entity .CollectTasksWithStatus (t , ecs .DesiredStatusRunning , true )
381386 if err != nil {
382387 return err
@@ -407,7 +412,7 @@ func (t *Task) up(updateTasks bool) error {
407412
408413 ecsTaskArns := make (map [string ]bool )
409414
410- if oldTaskDef != newTaskDef {
415+ if oldTaskDef != newTaskDef || forceUpdate {
411416 log .WithFields (log.Fields {"taskDefinition" : newTaskDef }).Info ("Updating to new task definition" )
412417
413418 chunkSize := 10
0 commit comments