Class: CfDeployer::DeploymentStrategy::AutoScalingGroupSwap

Inherits:
BlueGreen
  • Object
show all
Defined in:
lib/cf_deployer/deployment_strategy/auto_scaling_group_swap.rb

Defined Under Namespace

Classes: BothStacksActiveError

Constant Summary

Constants inherited from Base

Base::BLUE_GREEN_STRATEGY

Instance Attribute Summary

Attributes inherited from Base

#application_name, #component_name, #context, #environment_name

Instance Method Summary collapse

Methods inherited from BlueGreen

#destroy, #destroy_post, #exists?, #output_value, #status

Methods inherited from Base

#active_template, #blue_green_strategy?, #initialize, #run_hook

Constructor Details

This class inherits a constructor from CfDeployer::DeploymentStrategy::Base

Instance Method Details

#cool_inactive_on_failureObject



5
6
7
8
9
10
11
12
13
14
# 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

#deployObject



16
17
18
19
20
21
22
23
24
25
26
27
28
# 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_inactiveObject

Raises:



30
31
32
33
34
# 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

#switchObject

Raises:



36
37
38
39
40
# 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