lib/hako/schedulers/ecs.rb in hako-2.6.2 vs lib/hako/schedulers/ecs.rb in hako-2.7.0

- old
+ new

@@ -12,10 +12,11 @@ require 'hako/schedulers/ecs_autoscaling' require 'hako/schedulers/ecs_definition_comparator' require 'hako/schedulers/ecs_elb' require 'hako/schedulers/ecs_elb_v2' require 'hako/schedulers/ecs_service_comparator' +require 'hako/schedulers/ecs_service_discovery' require 'hako/schedulers/ecs_volume_comparator' module Hako module Schedulers class Ecs < Scheduler @@ -85,10 +86,13 @@ assign_public_ip: awsvpc_configuration.fetch('assign_public_ip', nil), }, } end end + if options['service_discovery'] + @service_discovery = EcsServiceDiscovery.new(options.fetch('service_discovery'), @region, dry_run: @dry_run) + end @started_at = nil @container_instance_arn = nil end @@ -112,10 +116,13 @@ end if @autoscaling @autoscaling.apply(Aws::ECS::Types::Service.new(cluster_arn: @cluster, service_name: @app_id)) end ecs_elb_client.modify_attributes + if @service_discovery + @service_discovery.apply + end else current_service = describe_service task_definition_changed, task_definition = register_task_definition(definitions) if task_definition_changed Hako.logger.info "Registered task definition: #{task_definition.task_definition_arn}" @@ -128,16 +135,22 @@ Hako.logger.info "Service isn't changed" if @autoscaling @autoscaling.apply(current_service) end ecs_elb_client.modify_attributes + if @service_discovery + @service_discovery.apply + end else Hako.logger.info "Updated service: #{service.service_arn}" if @autoscaling @autoscaling.apply(service) end ecs_elb_client.modify_attributes + if @service_discovery + @service_discovery.apply + end unless wait_for_ready(service) if task_definition_changed Hako.logger.error("Rolling back to #{current_service.task_definition}") update_service(service, current_service.task_definition) ecs_client.deregister_task_definition(task_definition: service.task_definition) @@ -293,10 +306,17 @@ puts 'Autoscaling:' @autoscaling.status(service) else puts 'Autoscaling: No' end + + if service.service_registries.empty? + puts 'Service Discovery: No' + else + puts 'Service Discovery:' + @service_discovery.status(service.service_registries) + end end # @return [nil] def remove service = describe_service @@ -311,10 +331,13 @@ ecs_client.update_service(cluster: service.cluster_arn, service: service.service_arn, desired_count: 0) end ecs_client.delete_service(cluster: service.cluster_arn, service: service.service_arn) Hako.logger.info "#{service.service_arn} is deleted" end + unless service.service_registries.empty? + @service_discovery.remove(service.service_registries) + end else puts "Service #{@app_id} doesn't exist" end ecs_elb_client.destroy @@ -609,10 +632,11 @@ essential: container.essential, environment: environment, secrets: container.secrets, docker_labels: container.docker_labels, mount_points: container.mount_points, + entry_point: container.entry_point, command: container.command, privileged: container.privileged, linux_parameters: container.linux_parameters, volumes_from: container.volumes_from, user: container.user, @@ -829,10 +853,11 @@ if @autoscaling # Keep current desired_count if autoscaling is enabled params[:desired_count] = current_service.desired_count end warn_placement_policy_change(current_service) + warn_service_registries_change(current_service) if service_changed?(current_service, params) ecs_client.update_service(params).service else :noop end @@ -861,10 +886,14 @@ end if ecs_elb_client.find_or_create_load_balancer(front_port) ecs_elb_client.modify_attributes params[:load_balancers] = [ecs_elb_client.load_balancer_params_for_service] end + if @service_discovery + @service_discovery.apply + params[:service_registries] = @service_discovery.service_registries + end ecs_client.create_service(params).service end # @param [Aws::ECS::Types::Service] service # @param [Hash] params @@ -1201,10 +1230,13 @@ cmd << '--read-only' end (definition[:docker_security_options] || []).each do |docker_security_option| cmd << '--security-opt' << docker_security_option end + if definition[:entry_point] + cmd << '--entrypoint' << definition[:entry_point] + end cmd << "\\\n " definition.fetch(:environment).each do |env| name = env.fetch(:name) value = env.fetch(:value) @@ -1278,9 +1310,19 @@ end h end if @placement_strategy != placement_strategy Hako.logger.warn "Ignoring updated placement_strategy in the configuration, because AWS doesn't allow updating them for now." + end + end + + # @param [Aws::ECS::Types::Service] service + # @return [void] + def warn_service_registries_change(service) + actual_service_registries = service.service_registries.sort_by(&:registry_arn).map(&:to_h) + expected_service_registries = @service_discovery&.service_registries&.sort_by { |s| s[:registry_arn] } || [] + if actual_service_registries != expected_service_registries + Hako.logger.warn "Ignoring updated service_registries in the configuration, because AWS doesn't allow updating them for now." end end # @param [Aws::ECS::Types::TaskDefinition] task_definition # @param [String] target_definition