diff --git a/provider/aws/formation/service.json.tmpl b/provider/aws/formation/service.json.tmpl index 0d207c257..d6f11b7ec 100644 --- a/provider/aws/formation/service.json.tmpl +++ b/provider/aws/formation/service.json.tmpl @@ -508,7 +508,7 @@ } }, {{ end }} - {{ if .Autoscale }} + {{ if $.Autoscale }} "AutoscalingTarget": { "Type": "AWS::ApplicationAutoScaling::ScalableTarget", "Properties": { @@ -568,15 +568,7 @@ {{ if .Agent.Enabled }} "SchedulingStrategy": "DAEMON", {{ else }} - {{ if .Autoscale }} - {{ with $.CurrentDesiredCount }} - "DesiredCount": "{{.}}", - {{ else }} - "DesiredCount": "{{$.Service.Scale.Count.Min}}", - {{ end }} - {{ else }} - "DesiredCount": { "Ref": "Count" }, - {{ end }} + "DesiredCount": { "Ref": "Count" }, "SchedulingStrategy": "REPLICA", "PlacementStrategies": { "Fn::If": [ "FargateEither", { "Ref": "AWS::NoValue" }, diff --git a/provider/aws/releases.go b/provider/aws/releases.go index 59a8046e7..357f64b50 100644 --- a/provider/aws/releases.go +++ b/provider/aws/releases.go @@ -340,7 +340,7 @@ func (p *Provider) ReleasePromote(app, id string, opts structs.ReleasePromoteOpt tp[fmt.Sprintf("ResourceTemplate%s", upperName(r.Name))] = ou.Url } - for _, s := range m.Services { + for i, s := range m.Services { min := s.Deployment.Minimum max := s.Deployment.Maximum @@ -352,8 +352,19 @@ func (p *Provider) ReleasePromote(app, id string, opts structs.ReleasePromoteOpt max = *opts.Max } + stackAutoscale, err := p.stackParameter(p.Rack, "Autoscale") + if err != nil { + return err + } + + autoscale := false + if stackAutoscale == "Yes" { + autoscale = true + } + stp := map[string]interface{}{ "App": r.App, + "Autoscale": autoscale, "Build": tp["Build"], "DeploymentMin": min, "DeploymentMax": max, @@ -364,6 +375,18 @@ func (p *Provider) ReleasePromote(app, id string, opts structs.ReleasePromoteOpt "WildcardDomain": tp["WildcardDomain"], } + data, err := formationTemplate("service", stp) + if err != nil { + return err + } + + ou, err := p.ObjectStore(app, "", bytes.NewReader(data), structs.ObjectStoreOptions{Presign: options.Bool(true)}) + if err != nil { + return err + } + + tp[fmt.Sprintf("ServiceTemplate%s", upperName(s.Name))] = ou.Url + sarn, err := p.serviceArn(r.App, s.Name) if err != nil { return err @@ -378,22 +401,12 @@ func (p *Provider) ReleasePromote(app, id string, opts structs.ReleasePromoteOpt return err } - if len(res.Services) == 1 && res.Services[0].DesiredCount != nil { - stp["CurrentDesiredCount"] = *res.Services[0].DesiredCount + // when autoscale is on set m.Services[i].Scale.Count.Min to desired count + // since this is used to service count param from app + if autoscale && len(res.Services) == 1 && res.Services[0].DesiredCount != nil { + m.Services[i].Scale.Count.Min = int(*res.Services[0].DesiredCount) } } - - data, err := formationTemplate("service", stp) - if err != nil { - return err - } - - ou, err := p.ObjectStore(app, "", bytes.NewReader(data), structs.ObjectStoreOptions{Presign: options.Bool(true)}) - if err != nil { - return err - } - - tp[fmt.Sprintf("ServiceTemplate%s", upperName(s.Name))] = ou.Url } for _, t := range m.Timers { @@ -427,6 +440,7 @@ func (p *Provider) ReleasePromote(app, id string, opts structs.ReleasePromoteOpt tp[fmt.Sprintf("TimerTemplate%s", upperName(t.Name))] = ou.Url } + // m.Services[i].Scale.Count.Min is mutated if service autoscaling is used data, err := formationTemplate("app", tp) if err != nil { return err diff --git a/provider/aws/service.go b/provider/aws/service.go index 3cdafd490..d1ca4510f 100644 --- a/provider/aws/service.go +++ b/provider/aws/service.go @@ -260,5 +260,23 @@ func (p *Provider) ServiceUpdate(app, name string, opts structs.ServiceUpdateOpt return err } + if opts.Count != nil { + sarn, err := p.serviceArn(app, name) + if err != nil { + return err + } + + if sarn != "" { + _, err := p.ecs().UpdateService(&ecs.UpdateServiceInput{ + Cluster: aws.String(p.Cluster), + Service: aws.String(sarn), + DesiredCount: aws.Int64(int64(*opts.Count)), + }) + if err != nil { + return err + } + } + } + return nil }