class Momentum::OpsWorks::Deployer

Constants

TIMEOUT

Public Class Methods

new(aws_id, aws_secret) click to toggle source
# File lib/momentum/opsworks.rb, line 64
def initialize(aws_id, aws_secret)
  @ow = Momentum::OpsWorks.client(aws_id, aws_secret)
end

Public Instance Methods

deploy!(stack_name, app_name = Momentum.config[:app_base_name]) click to toggle source
# File lib/momentum/opsworks.rb, line 89
def deploy!(stack_name, app_name = Momentum.config[:app_base_name])
  stack = Momentum::OpsWorks.get_stack(@ow, stack_name)
  app = Momentum::OpsWorks.get_app(@ow, stack, app_name)
  layers = Momentum::OpsWorks.get_layers(@ow, stack, Momentum.config[:app_layers])
  instance_ids = layers.inject([]) { |ids, l| ids + Momentum::OpsWorks.get_online_instance_ids(@ow, layer_id: l[:layer_id]) }
  raise 'No online instances found!' if instance_ids.empty?
  @ow.create_deployment(
    stack_id: stack[:stack_id],
    app_id: app[:app_id],
    command: {
      name: 'deploy'
    },
    instance_ids: instance_ids
  )
end
execute_recipe!(stack_name, layer, recipe, app_name = Momentum.config[:app_base_name]) click to toggle source
# File lib/momentum/opsworks.rb, line 68
def execute_recipe!(stack_name, layer, recipe, app_name = Momentum.config[:app_base_name])
  raise "No recipe provided" unless recipe
  stack = Momentum::OpsWorks.get_stack(@ow, stack_name)
  app = Momentum::OpsWorks.get_app(@ow, stack, app_name)
  layer_names = layer ? [layer] : Momentum.config[:app_layers]
  layers = Momentum::OpsWorks.get_layers(@ow, stack, layer_names)
  instance_ids = layers.inject([]) { |ids, l| ids + Momentum::OpsWorks.get_online_instance_ids(@ow, layer_id: l[:layer_id]) }
  raise 'No online instances found!' if instance_ids.empty?
  @ow.create_deployment(
    stack_id: stack[:stack_id],
    app_id: app[:app_id],
    command: {
      name: 'execute_recipes',
      args: {
        'recipes' => [recipe.to_s]
      }
    },
    instance_ids: instance_ids
  )
end
wait_for_success!(deployment, timeout = TIMEOUT) click to toggle source
# File lib/momentum/opsworks.rb, line 105
def wait_for_success!(deployment, timeout = TIMEOUT)
  Timeout.timeout(timeout) do
    status = @ow.describe_deployments(deployment_ids: [deployment[:deployment_id]])[:deployments].first[:status]
    $stderr.puts 'Polling deploy status...'
    while status == 'running'
      sleep 10
      status = @ow.describe_deployments(deployment_ids: [deployment[:deployment_id]])[:deployments].first[:status]
      $stderr.print '.'
    end
    raise "Deploy failed (status: #{status})!" unless status == 'successful'
  end
  $stderr.puts 'Success!'
rescue Timeout::Error
  raise "Timed out waiting for deploy to succeed after #{timeout} seconds."
end