8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
# File 'lib/capistrano/autoscale/dsl.rb', line 8
def autoscale(groupname, properties = {})
group_names = fetch(:aws_autoscale_group_names)
group_names << groupname
asg = Capistrano::Autoscale::AWS::AutoscaleGroup.new groupname
instances = asg.instances.running
info "Auto Scaling Group: #{groupname}"
instances.each.with_index do |instance, index|
info "Adding server #{instance.private_ip}"
if index.zero? && properties.key?(:primary_roles)
server_properties = properties.dup
server_properties[:roles] = server_properties.delete(:primary_roles)
else
server_properties = properties
end
server(instance.private_ip, server_properties)
end
instances = asg.instances_in_service.running
if instances.any?
after 'deploy', 'autoscale:update'
if fetch(:aws_autoscale_suspend_processes)
before 'deploy', 'autoscale:suspend'
after 'deploy', 'autoscale:resume'
after 'deploy:failed', 'autoscale:resume'
end
else
error <<~MESSAGE
Will not create AMI because no instances with state in service were found in the specified Auto Scaling group. Ensure that the Auto Scaling group name is correct and that there is at least one in service instance attached to it.
MESSAGE
end
end
|