class DPL::Provider::OpsWorks

Public Instance Methods

access_key_id() click to toggle source
# File lib/dpl/provider/ops_works.rb, line 32
def access_key_id
  options[:access_key_id] || context.env['AWS_ACCESS_KEY_ID'] || raise(Error, "missing access_key_id")
end
check_app() click to toggle source
# File lib/dpl/provider/ops_works.rb, line 24
def check_app

end
check_auth() click to toggle source
# File lib/dpl/provider/ops_works.rb, line 40
def check_auth
  log "Logging in with Access Key: #{access_key_id[-4..-1].rjust(20, '*')}"
end
create_deployment() click to toggle source
# File lib/dpl/provider/ops_works.rb, line 81
def create_deployment
  deployment_config = {
    stack_id: ops_works_app[:stack_id],
    app_id: option(:app_id),
    command: {name: 'deploy'},
    comment: travis_deploy_comment,
    custom_json: custom_json
  }
  if !options[:instance_ids].nil?
    deployment_config[:instance_ids] = Array(option(:instance_ids))
  end
  if !options[:layer_ids].nil?
    deployment_config[:layer_ids] = Array(option(:layer_ids))
  end
  log "creating deployment #{deployment_config.to_json}"
  data = opsworks.create_deployment(deployment_config)
  log "Deployment created: #{data[:deployment_id]}"
  return unless options[:wait_until_deployed]
  print "Deploying "
  deployment = wait_until_deployed(data[:deployment_id])
  print "\n"
  if deployment[:status] == 'successful'
    log "Deployment successful."
    update = options[:update_app_on_success] || options[:update_on_success]
    return unless update.to_s.squeeze.downcase == 'true'
    update_app
  else
    error "Deployment failed."
  end
end
current_sha() click to toggle source
# File lib/dpl/provider/ops_works.rb, line 57
def current_sha
  @current_sha ||= `git rev-parse HEAD`.chomp
end
custom_json() click to toggle source
# File lib/dpl/provider/ops_works.rb, line 44
def custom_json
  options[:custom_json] || {
    deploy: {
      ops_works_app[:shortname] => {
        migrate: !!options[:migrate],
        scm: {
          revision: current_sha
        }
      }
    }
  }.to_json
end
deploy() click to toggle source
Calls superclass method
# File lib/dpl/provider/ops_works.rb, line 139
def deploy
  super
rescue Aws::Errors::ServiceError => error
  raise Error, "Stopping Deploy, OpsWorks service error: #{error.message}", error.backtrace
end
fetch_ops_works_app() click to toggle source
# File lib/dpl/provider/ops_works.rb, line 65
def fetch_ops_works_app
  data = opsworks.describe_apps(app_ids: [option(:app_id)])
  unless data[:apps] && data[:apps].count == 1
    raise Error, "App #{option(:app_id)} not found.", error.backtrace
  end
  data[:apps].first
end
needs_key?() click to toggle source
# File lib/dpl/provider/ops_works.rb, line 20
def needs_key?
  false
end
ops_works_app() click to toggle source
# File lib/dpl/provider/ops_works.rb, line 61
def ops_works_app
  @ops_works_app ||= fetch_ops_works_app
end
opsworks() click to toggle source
# File lib/dpl/provider/ops_works.rb, line 9
def opsworks
  @opsworks ||= Aws::OpsWorks::Client.new(opsworks_options)
end
opsworks_options() click to toggle source
# File lib/dpl/provider/ops_works.rb, line 13
def opsworks_options
  {
    region:      region || 'us-east-1',
    credentials: ::Aws::Credentials.new(access_key_id, secret_access_key)
  }
end
push_app() click to toggle source
# File lib/dpl/provider/ops_works.rb, line 73
def push_app
  Timeout::timeout(600) do
    create_deployment
  end
rescue Timeout::Error
  error 'Timeout: Could not finish deployment in 10 minutes.'
end
region() click to toggle source
# File lib/dpl/provider/ops_works.rb, line 28
def region
  options[:region] || context.env['AWS_DEFAULT_REGION']
end
secret_access_key() click to toggle source
# File lib/dpl/provider/ops_works.rb, line 36
def secret_access_key
  options[:secret_access_key] || context.env['AWS_SECRET_ACCESS_KEY'] || raise(Error, "missing secret_access_key")
end
travis_deploy_comment() click to toggle source
# File lib/dpl/provider/ops_works.rb, line 135
def travis_deploy_comment
  "Deploy build #{context.env['TRAVIS_BUILD_NUMBER'] || current_sha} via Travis CI"
end
update_app() click to toggle source
# File lib/dpl/provider/ops_works.rb, line 112
def update_app
  update_config = {
    app_id: option(:app_id),
    app_source: {
      revision: current_sha,
    }
  }
  opsworks.update_app(update_config)
  log "Application Source branch/revision setting updated."
end
wait_until_deployed(deployment_id) click to toggle source
# File lib/dpl/provider/ops_works.rb, line 123
def wait_until_deployed(deployment_id)
  deployment = nil
  loop do
    result = opsworks.describe_deployments(deployment_ids: [deployment_id])
    deployment = result[:deployments].first
    break unless deployment[:status] == "running"
    print "."
    sleep 5
  end
  deployment
end