class Opsworks::Deploy::Deployment
Attributes
client[R]
deployment[R]
options[R]
Public Class Methods
new(options, client = AWS.ops_works.client)
click to toggle source
# File lib/opsworks/deploy/deploy.rb, line 35 def initialize(options, client = AWS.ops_works.client) @options = { migrate: true, wait: false, env: nil }.merge(options) @client = client end
Public Instance Methods
deploy()
click to toggle source
# File lib/opsworks/deploy/deploy.rb, line 44 def deploy @deployment = client.create_deployment(arguments) puts @deployment.inspect wait_on_deployment if options[:wait] end
Private Instance Methods
arguments()
click to toggle source
# File lib/opsworks/deploy/deploy.rb, line 52 def arguments { stack_id: configuration['stack_id'], app_id: configuration['app_id'], command: command }.tap do |args| args[:custom_json] = custom_json if custom_json? end end
command()
click to toggle source
# File lib/opsworks/deploy/deploy.rb, line 62 def command {name: 'deploy', args: {'migrate' => [options[:migrate] ? 'true' : 'false']}} end
configuration()
click to toggle source
# File lib/opsworks/deploy/deploy.rb, line 74 def configuration @configuration ||= if !ENV['STACK_ID'].nil? && !ENV['APP_ID'].nil? {'stack_id' => ENV['STACK_ID'], 'app_id' => ENV['APP_ID']} elsif stacks = configured_environments stacks.fetch(environment) do raise "Missing stacks configuration for #{environment} in stacks.json" end else raise "Must set STACK_ID and APP_ID or have config/stacks.json for env `#{environment}`" end end
configured_environments()
click to toggle source
Look for config/stacks.json or stacks.json
# File lib/opsworks/deploy/deploy.rb, line 91 def configured_environments files = Dir['config/stacks.json','stacks.json'] file = files.first and JSON.parse(File.read(file)) end
custom_json()
click to toggle source
# File lib/opsworks/deploy/deploy.rb, line 66 def custom_json configuration['custom_json'].to_json end
custom_json?()
click to toggle source
# File lib/opsworks/deploy/deploy.rb, line 70 def custom_json? configuration.has_key?('custom_json') end
environment()
click to toggle source
# File lib/opsworks/deploy/deploy.rb, line 86 def environment options.fetch(:env) end
wait_on_deployment()
click to toggle source
# File lib/opsworks/deploy/deploy.rb, line 96 def wait_on_deployment deployment_id = deployment.data[:deployment_id] loop do deployment_description = client.describe_deployments( deployment_ids: [deployment_id] ) status = deployment_description.data[:deployments].first[:status] case status when 'running' then sleep DEPLOYMENT_POLL_INTERVAL when 'successful' then break else raise "Failed to run deployment: #{deployment_id} - #{status}" end end end