Class: DPL::Provider::CodeDeploy
- Inherits:
-
DPL::Provider
- Object
- DPL::Provider
- DPL::Provider::CodeDeploy
- Defined in:
- lib/dpl/provider/code_deploy.rb
Instance Method Summary collapse
- #access_key_id ⇒ Object
- #bundle_type ⇒ Object
- #check_auth ⇒ Object
- #cleanup ⇒ Object
- #code_deploy ⇒ Object
- #code_deploy_options ⇒ Object
- #default_description ⇒ Object
- #github_revision ⇒ Object
- #needs_key? ⇒ Boolean
- #push_app ⇒ Object
- #revision ⇒ Object
- #revision_version_info ⇒ Object
- #s3_key ⇒ Object
- #s3_revision ⇒ Object
- #s3api ⇒ Object
- #secret_access_key ⇒ Object
- #uncleanup ⇒ Object
- #wait_until_deployed(deployment_id) ⇒ Object
Instance Method Details
#access_key_id ⇒ Object
24 25 26 |
# File 'lib/dpl/provider/code_deploy.rb', line 24 def access_key_id [:access_key_id] || context.env['AWS_ACCESS_KEY_ID'] || raise(Error, "missing access_key_id") end |
#bundle_type ⇒ Object
126 127 128 129 130 131 132 |
# File 'lib/dpl/provider/code_deploy.rb', line 126 def bundle_type if s3_key =~ /\.(tar|tgz|zip)$/ [:bundle_type] || $1 else option(:bundle_type) end end |
#check_auth ⇒ Object
142 143 144 |
# File 'lib/dpl/provider/code_deploy.rb', line 142 def check_auth log "Logging in with Access Key: #{access_key_id[-4..-1].rjust(20, '*')}" end |
#cleanup ⇒ Object
146 147 |
# File 'lib/dpl/provider/code_deploy.rb', line 146 def cleanup end |
#code_deploy ⇒ Object
7 8 9 |
# File 'lib/dpl/provider/code_deploy.rb', line 7 def code_deploy @code_deploy ||= Aws::CodeDeploy::Client.new() end |
#code_deploy_options ⇒ Object
15 16 17 18 19 20 21 22 |
# File 'lib/dpl/provider/code_deploy.rb', line 15 def = { region: [:region] || 'us-east-1', credentials: Aws::Credentials.new(access_key_id, secret_access_key) } [:endpoint] = [:endpoint] if [:endpoint] end |
#default_description ⇒ Object
138 139 140 |
# File 'lib/dpl/provider/code_deploy.rb', line 138 def default_description "Deploy build #{context.env['TRAVIS_BUILD_NUMBER']} via Travis CI" end |
#github_revision ⇒ Object
71 72 73 74 75 76 77 78 79 |
# File 'lib/dpl/provider/code_deploy.rb', line 71 def github_revision { revision_type: 'GitHub', git_hub_location: { commit_id: [:commit_id] || context.env['TRAVIS_COMMIT'] || `git rev-parse HEAD`.strip, repository: [:repository] || context.env['TRAVIS_REPO_SLUG'] || option(:repository) } } end |
#needs_key? ⇒ Boolean
32 33 34 |
# File 'lib/dpl/provider/code_deploy.rb', line 32 def needs_key? false end |
#push_app ⇒ 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 111 112 |
# File 'lib/dpl/provider/code_deploy.rb', line 81 def push_app rev = revision() rev_info = rev[:s3_location] if rev_info && rev_info[:version] log "Registering app revision with version=#{rev_info[:version]}, etag=#{rev_info[:e_tag]}" code_deploy.register_application_revision({ revision: rev, application_name: [:application] || option(:application_name), description: [:description] || default_description }) end data = code_deploy.create_deployment({ revision: revision, application_name: [:application] || option(:application_name), deployment_group_name: [:deployment_group] || option(:deployment_group_name), description: [:description] || default_description }) log "Triggered deployment #{data.deployment_id.inspect}." return unless [:wait_until_deployed] print "Deploying " deployment = wait_until_deployed(data[:deployment_id]) print "\n" if deployment[:status] == 'Succeeded' log "Deployment successful." else error "Deployment failed." end rescue Aws::CodeDeploy::Errors::DeploymentLimitExceededException => exception error(exception.) end |
#revision ⇒ Object
36 37 38 39 40 41 42 43 |
# File 'lib/dpl/provider/code_deploy.rb', line 36 def revision case [:revision_type].to_s.downcase when "s3" then s3_revision when "github" then github_revision when "" then [:bucket] ? s3_revision : github_revision else error("unknown revision type %p" % [:revision_type]) end end |
#revision_version_info ⇒ Object
45 46 47 48 49 50 51 52 |
# File 'lib/dpl/provider/code_deploy.rb', line 45 def revision_version_info s3api.head_object({ bucket: option(:bucket), key: s3_key }) rescue Aws::Errors::ServiceError {} end |
#s3_key ⇒ Object
134 135 136 |
# File 'lib/dpl/provider/code_deploy.rb', line 134 def s3_key [:key] || option(:s3_key) end |
#s3_revision ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/dpl/provider/code_deploy.rb', line 54 def s3_revision info = { revision_type: 'S3', s3_location: { bucket: option(:bucket), bundle_type: bundle_type, key: s3_key, } } unless revision_version_info.empty? info[:s3_location][:version] = revision_version_info[:version_id] info[:s3_location][:e_tag] = revision_version_info[:etag] end info end |
#s3api ⇒ Object
11 12 13 |
# File 'lib/dpl/provider/code_deploy.rb', line 11 def s3api @s3api ||= Aws::S3::Client.new() end |
#secret_access_key ⇒ Object
28 29 30 |
# File 'lib/dpl/provider/code_deploy.rb', line 28 def secret_access_key [:secret_access_key] || context.env['AWS_SECRET_ACCESS_KEY'] || raise(Error, "missing secret_access_key") end |
#uncleanup ⇒ Object
149 150 |
# File 'lib/dpl/provider/code_deploy.rb', line 149 def uncleanup end |
#wait_until_deployed(deployment_id) ⇒ Object
114 115 116 117 118 119 120 121 122 123 124 |
# File 'lib/dpl/provider/code_deploy.rb', line 114 def wait_until_deployed(deployment_id) deployment = {} loop do result = code_deploy.get_deployment(deployment_id: deployment_id) deployment = result[:deployment_info] break if deployment[:status] == "Succeeded" || deployment[:status] == "Failed" || deployment[:status] == "Stopped" print "." sleep 5 end deployment end |