lib/hako/schedulers/ecs.rb in hako-0.16.0 vs lib/hako/schedulers/ecs.rb in hako-0.17.0

- old
+ new

@@ -2,10 +2,11 @@ require 'aws-sdk' require 'hako' require 'hako/scheduler' require 'hako/schedulers/ecs_definition_comparator' require 'hako/schedulers/ecs_elb' +require 'hako/schedulers/ecs_autoscaling' module Hako module Schedulers class Ecs < Scheduler DEFAULT_CLUSTER = 'default' @@ -19,10 +20,13 @@ @desired_count = options.fetch('desired_count', nil) @region = options.fetch('region') { validation_error!('region must be set') } @role = options.fetch('role', nil) @task_role_arn = options.fetch('task_role_arn', nil) @ecs_elb_options = options.fetch('elb', nil) + if options.key?('autoscaling') + @autoscaling = EcsAutoscaling.new(options.fetch('autoscaling'), dry_run: @dry_run) + end @started_at = nil @container_instance_arn = nil end # @param [Hash<String, Container>] containers @@ -37,10 +41,13 @@ if @dry_run definitions.each do |d| Hako.logger.info "Add container #{d}" end + if @autoscaling + @autoscaling.apply(Aws::ECS::Types::Service.new(cluster_arn: @cluster, service_name: @app_id)) + end else task_definition = register_task_definition(definitions) if task_definition == :noop Hako.logger.info "Task definition isn't changed" task_definition = ecs_client.describe_task_definition(task_definition: @app_id).task_definition @@ -48,12 +55,18 @@ Hako.logger.info "Registered task definition: #{task_definition.task_definition_arn}" end service = create_or_update_service(task_definition.task_definition_arn, front_port) if service == :noop Hako.logger.info "Service isn't changed" + if @autoscaling + @autoscaling.apply(describe_service) + end else Hako.logger.info "Updated service: #{service.service_arn}" + if @autoscaling + @autoscaling.apply(service) + end wait_for_ready(service) end Hako.logger.info 'Deployment completed' end end @@ -530,9 +543,13 @@ cluster: @cluster, service: @app_id, desired_count: @desired_count, task_definition: task_definition_arn, } + if @autoscaling + # Keep current desired_count if autoscaling is enabled + params[:desired_count] = service.desired_count + end if service_changed?(service, params) ecs_client.update_service(params).service else :noop end