23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
# File 'lib/shiprails/ship/scale.rb', line 23
def update_ecs_services
say "Setting ECS service #{service} scale=#{scale} in #{environment}..."
configuration[:services].each do |service_name, service|
next unless service_name.to_s == self.service
image_name = "#{project_name}_#{service_name}"
service[:regions].each do |region_name, region|
next unless options["region"].nil? or options["region"] == region_name.to_s
ecs = Aws::ECS::Client.new(region: region_name.to_s)
region[:environments].each do |environment_name|
next unless environment_name == self.environment
cluster_name = "#{project_name}_#{environment_name}"
task_name = "#{image_name}_#{environment_name}"
begin
task_definition_description = ecs.describe_task_definition({task_definition: task_name})
task_definition = task_definition_description.task_definition.to_hash
rescue Aws::ECS::Errors::ClientException => e
say "Missing ECS task for #{task_name}!", :red
say "Run `ship setup`", :red
exit
end
begin
service_response = ecs.update_service({
cluster: cluster_name,
service: service_name,
desired_count: scale
})
say "Set ECS service #{service_name} scale=#{scale} in #{environment} (#{region_name})...", :green
rescue Aws::ECS::Errors::ServiceNotFoundException, Aws::ECS::Errors::ServiceNotActiveException => e
say "Missing ECS service for #{task_name}!", :red
say "Run `ship setup`", :red
exit
end
end
end
end
say "ECS service updated.", :green
end
|