class CfDeployer::DeploymentStrategy::AutoScalingGroupSwap
Public Instance Methods
cool_inactive_on_failure() { || ... }
click to toggle source
# File lib/cf_deployer/deployment_strategy/auto_scaling_group_swap.rb, line 5 def cool_inactive_on_failure yield rescue => e if both_stacks_active? Log.error "Deployment failed - #{e.message} - and both stacks are active. Cooling down failed stack. Look into the failure, and try your deployment again." cool_down(inactive_stack) end raise e end
deploy()
click to toggle source
# File lib/cf_deployer/deployment_strategy/auto_scaling_group_swap.rb, line 16 def deploy check_blue_green_not_both_active 'Deployment' Log.info "Found active stack #{active_stack.name}" if active_stack delete_stack inactive_stack cool_inactive_on_failure do create_inactive_stack swap_group end run_hook(:'after-swap') Log.info "Active stack has been set to #{inactive_stack.name}" delete_stack(active_stack) if active_stack && !keep_previous_stack Log.info "#{component_name} deployed successfully" end
kill_inactive()
click to toggle source
# File lib/cf_deployer/deployment_strategy/auto_scaling_group_swap.rb, line 30 def kill_inactive check_blue_green_not_both_active 'Kill Inactive' raise ApplicationError.new('Only one color stack exists, cannot kill a non-existant version!') unless both_stacks_exist? delete_stack inactive_stack end
switch()
click to toggle source
# File lib/cf_deployer/deployment_strategy/auto_scaling_group_swap.rb, line 36 def switch check_blue_green_not_both_active 'Switch' raise ApplicationError.new('Both stacks must exist to switch.') unless both_stacks_exist? cool_inactive_on_failure { swap_group true } end
Private Instance Methods
asg_driver(name)
click to toggle source
# File lib/cf_deployer/deployment_strategy/auto_scaling_group_swap.rb, line 90 def asg_driver name @auto_scaling_group_drivers[name] ||= CfDeployer::Driver::AutoScalingGroup.new name end
asg_name_outputs()
click to toggle source
# File lib/cf_deployer/deployment_strategy/auto_scaling_group_swap.rb, line 94 def asg_name_outputs @context[:settings][:'auto-scaling-group-name-output'] end
both_stacks_active?()
click to toggle source
# File lib/cf_deployer/deployment_strategy/auto_scaling_group_swap.rb, line 64 def both_stacks_active? active_stack && stack_active?(inactive_stack) end
check_blue_green_not_both_active(action)
click to toggle source
# File lib/cf_deployer/deployment_strategy/auto_scaling_group_swap.rb, line 44 def check_blue_green_not_both_active action active_stacks = get_active_asgs(active_stack) + get_active_asgs(inactive_stack) raise BothStacksActiveError.new("Found both auto-scaling-groups, #{active_stacks}, in green and blue stacks are active. #{action} aborted!") if both_stacks_active? end
cool_down(stack)
click to toggle source
# File lib/cf_deployer/deployment_strategy/auto_scaling_group_swap.rb, line 72 def cool_down stack get_active_asgs(stack).each do |id| asg_driver(id).cool_down end end
create_inactive_stack()
click to toggle source
# File lib/cf_deployer/deployment_strategy/auto_scaling_group_swap.rb, line 58 def create_inactive_stack inactive_stack.deploy get_parameters_outputs(inactive_stack) run_hook(:'after-create') end
get_active_asgs(stack)
click to toggle source
# File lib/cf_deployer/deployment_strategy/auto_scaling_group_swap.rb, line 82 def get_active_asgs stack return [] unless stack && stack.exists? && stack.resource_statuses[:asg_instances] stack.resource_statuses[:asg_instances].keys.select do |id| result = asg_driver(id).describe result[:min] > 0 && result[:max] > 0 && result[:desired] > 0 end end
keep_previous_stack()
click to toggle source
# File lib/cf_deployer/deployment_strategy/auto_scaling_group_swap.rb, line 54 def keep_previous_stack context[:settings][:'keep-previous-stack'] end
stack_active?(stack)
click to toggle source
# File lib/cf_deployer/deployment_strategy/auto_scaling_group_swap.rb, line 78 def stack_active?(stack) stack.exists? && get_active_asgs(stack).any? end
swap_group(is_switching_to_cooled = false)
click to toggle source
# File lib/cf_deployer/deployment_strategy/auto_scaling_group_swap.rb, line 49 def swap_group is_switching_to_cooled = false is_switching_to_cooled ? warm_up_cooled_stack : warm_up_inactive_stack cool_down(active_stack) if active_stack && (is_switching_to_cooled || keep_previous_stack) end
warm_up_cooled_stack()
click to toggle source
# File lib/cf_deployer/deployment_strategy/auto_scaling_group_swap.rb, line 68 def warm_up_cooled_stack warm_up_stack(inactive_stack, active_stack, true) end