Class: DPL::Provider::OpsWorks
- Inherits:
-
DPL::Provider
- Object
- DPL::Provider
- DPL::Provider::OpsWorks
- Defined in:
- lib/dpl/provider/ops_works.rb
Instance Method Summary collapse
- #access_key_id ⇒ Object
- #check_app ⇒ Object
- #check_auth ⇒ Object
- #create_deployment ⇒ Object
- #current_sha ⇒ Object
- #custom_json ⇒ Object
- #deploy ⇒ Object
- #fetch_ops_works_app ⇒ Object
- #needs_key? ⇒ Boolean
- #ops_works_app ⇒ Object
- #opsworks ⇒ Object
- #opsworks_options ⇒ Object
- #push_app ⇒ Object
- #region ⇒ Object
- #secret_access_key ⇒ Object
- #travis_deploy_comment ⇒ Object
- #update_app ⇒ Object
- #wait_until_deployed(deployment_id) ⇒ Object
Instance Method Details
#access_key_id ⇒ Object
32 33 34 |
# File 'lib/dpl/provider/ops_works.rb', line 32 def access_key_id [:access_key_id] || context.env['AWS_ACCESS_KEY_ID'] || raise(Error, "missing access_key_id") end |
#check_app ⇒ Object
24 25 26 |
# File 'lib/dpl/provider/ops_works.rb', line 24 def check_app end |
#check_auth ⇒ Object
40 41 42 |
# 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 ⇒ Object
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# 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 ![:instance_ids].nil? deployment_config[:instance_ids] = Array(option(:instance_ids)) end if ![: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 [:wait_until_deployed] print "Deploying " deployment = wait_until_deployed(data[:deployment_id]) print "\n" if deployment[:status] == 'successful' log "Deployment successful." update = [:update_app_on_success] || [:update_on_success] return unless update.to_s.squeeze.downcase == 'true' update_app else error "Deployment failed." end end |
#current_sha ⇒ Object
57 58 59 |
# File 'lib/dpl/provider/ops_works.rb', line 57 def current_sha @current_sha ||= `git rev-parse HEAD`.chomp end |
#custom_json ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/dpl/provider/ops_works.rb', line 44 def custom_json [:custom_json] || { deploy: { ops_works_app[:shortname] => { migrate: !![:migrate], scm: { revision: current_sha } } } }.to_json end |
#deploy ⇒ Object
139 140 141 142 143 |
# 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.}", error.backtrace end |
#fetch_ops_works_app ⇒ Object
65 66 67 68 69 70 71 |
# 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? ⇒ Boolean
20 21 22 |
# File 'lib/dpl/provider/ops_works.rb', line 20 def needs_key? false end |
#ops_works_app ⇒ Object
61 62 63 |
# File 'lib/dpl/provider/ops_works.rb', line 61 def ops_works_app @ops_works_app ||= fetch_ops_works_app end |
#opsworks ⇒ Object
9 10 11 |
# File 'lib/dpl/provider/ops_works.rb', line 9 def opsworks @opsworks ||= Aws::OpsWorks::Client.new() end |
#opsworks_options ⇒ Object
13 14 15 16 17 18 |
# File 'lib/dpl/provider/ops_works.rb', line 13 def { region: region || 'us-east-1', credentials: ::Aws::Credentials.new(access_key_id, secret_access_key) } end |
#push_app ⇒ Object
73 74 75 76 77 78 79 |
# 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 ⇒ Object
28 29 30 |
# File 'lib/dpl/provider/ops_works.rb', line 28 def region [:region] || context.env['AWS_DEFAULT_REGION'] end |
#secret_access_key ⇒ Object
36 37 38 |
# File 'lib/dpl/provider/ops_works.rb', line 36 def secret_access_key [:secret_access_key] || context.env['AWS_SECRET_ACCESS_KEY'] || raise(Error, "missing secret_access_key") end |
#travis_deploy_comment ⇒ Object
135 136 137 |
# 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 ⇒ Object
112 113 114 115 116 117 118 119 120 121 |
# 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) ⇒ Object
123 124 125 126 127 128 129 130 131 132 133 |
# 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 |