Class: DPL::Provider::CodeDeploy

Inherits:
DPL::Provider show all
Defined in:
lib/dpl/provider/code_deploy.rb

Instance Attribute Summary

Attributes inherited from DPL::Provider

#context, #options

Instance Method Summary collapse

Methods inherited from DPL::Provider

apt_get, #check_app, #commit_msg, context, #create_key, #default_text_charset, #default_text_charset?, #deploy, deprecated, #detect_encoding?, #encoding_for, #error, experimental, #initialize, #log, new, npm_g, #option, pip, requires, #run, #setup_git_credentials, #setup_git_ssh, #sha, shell, #user_agent, #warn

Constructor Details

This class inherits a constructor from DPL::Provider

Instance Method Details

#access_key_idObject



21
22
23
# File 'lib/dpl/provider/code_deploy.rb', line 21

def access_key_id
  options[:access_key_id] || context.env['AWS_ACCESS_KEY_ID'] || raise(Error, "missing access_key_id")
end

#bundle_typeObject



96
97
98
99
100
101
102
# File 'lib/dpl/provider/code_deploy.rb', line 96

def bundle_type
  if s3_key =~ /\.(tar|tgz|zip)$/
    options[:bundle_type] || $1
  else
    option(:bundle_type)
  end
end

#check_authObject



112
113
114
# File 'lib/dpl/provider/code_deploy.rb', line 112

def check_auth
  log "Logging in with Access Key: #{access_key_id[-4..-1].rjust(20, '*')}"
end

#cleanupObject



116
117
# File 'lib/dpl/provider/code_deploy.rb', line 116

def cleanup
end

#code_deployObject



8
9
10
# File 'lib/dpl/provider/code_deploy.rb', line 8

def code_deploy
  @code_deploy ||= Aws::CodeDeploy::Client.new(code_deploy_options)
end

#code_deploy_optionsObject



12
13
14
15
16
17
18
19
# File 'lib/dpl/provider/code_deploy.rb', line 12

def code_deploy_options
  code_deploy_options = {
    region:      options[:region] || 'us-east-1',
    credentials: Aws::Credentials.new(access_key_id, secret_access_key)
  }
  code_deploy_options[:endpoint] = options[:endpoint] if options[:endpoint]
  code_deploy_options
end

#default_descriptionObject



108
109
110
# File 'lib/dpl/provider/code_deploy.rb', line 108

def default_description
  "Deploy build #{context.env['TRAVIS_BUILD_NUMBER']} via Travis CI"
end

#github_revisionObject



53
54
55
56
57
58
59
60
61
# File 'lib/dpl/provider/code_deploy.rb', line 53

def github_revision
  {
    revision_type: 'GitHub',
    git_hub_location: {
      commit_id:  options[:commit_id]  || context.env['TRAVIS_COMMIT']    || `git rev-parse HEAD`.strip,
      repository: options[:repository] || context.env['TRAVIS_REPO_SLUG'] || option(:repository)
    }
  }
end

#needs_key?Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/dpl/provider/code_deploy.rb', line 29

def needs_key?
  false
end

#push_appObject



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/dpl/provider/code_deploy.rb', line 63

def push_app
  data = code_deploy.create_deployment({
    revision:               revision,
    application_name:       options[:application]      || option(:application_name),
    deployment_group_name:  options[:deployment_group] || option(:deployment_group_name),
    description:            options[:description]      || default_description
  })
  log "Triggered deployment #{data.deployment_id.inspect}."
  return unless options[: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.message)
end

#revisionObject



33
34
35
36
37
38
39
40
# File 'lib/dpl/provider/code_deploy.rb', line 33

def revision
  case options[:revision_type].to_s.downcase
  when "s3"     then s3_revision
  when "github" then github_revision
  when ""       then options[:bucket] ? s3_revision : github_revision
  else error("unknown revision type %p" % options[:revision_type])
  end
end

#s3_keyObject



104
105
106
# File 'lib/dpl/provider/code_deploy.rb', line 104

def s3_key
  options[:key] || option(:s3_key)
end

#s3_revisionObject



42
43
44
45
46
47
48
49
50
51
# File 'lib/dpl/provider/code_deploy.rb', line 42

def s3_revision
  {
    revision_type: 'S3',
    s3_location: {
      bucket:      option(:bucket),
      bundle_type: bundle_type,
      key:         s3_key
    }
  }
end

#secret_access_keyObject



25
26
27
# File 'lib/dpl/provider/code_deploy.rb', line 25

def secret_access_key
  options[:secret_access_key] || context.env['AWS_SECRET_ACCESS_KEY'] || raise(Error, "missing secret_access_key")
end

#uncleanupObject



119
120
# File 'lib/dpl/provider/code_deploy.rb', line 119

def uncleanup
end

#wait_until_deployed(deployment_id) ⇒ Object



84
85
86
87
88
89
90
91
92
93
94
# File 'lib/dpl/provider/code_deploy.rb', line 84

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