Class: DPL::Provider::OpsWorks

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

Instance Attribute Summary

Attributes inherited from DPL::Provider

#context, #options

Instance Method Summary collapse

Methods inherited from DPL::Provider

#cleanup, context, #create_key, #error, experimental, #initialize, #log, new, npm_g, #option, pip, requires, #run, #setup_git_credentials, #setup_git_ssh, #sha, shell, #uncleanup

Constructor Details

This class inherits a constructor from DPL::Provider

Instance Method Details

#apiObject



7
8
9
# File 'lib/dpl/provider/ops_works.rb', line 7

def api
  @api ||= AWS::OpsWorks.new
end

#check_appObject



19
20
21
# File 'lib/dpl/provider/ops_works.rb', line 19

def check_app

end

#check_authObject



27
28
29
30
# File 'lib/dpl/provider/ops_works.rb', line 27

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

#clientObject



11
12
13
# File 'lib/dpl/provider/ops_works.rb', line 11

def client
  @client ||= api.client
end

#current_shaObject



45
46
47
# File 'lib/dpl/provider/ops_works.rb', line 45

def current_sha
  @current_sha ||= `git rev-parse HEAD`.chomp
end

#custom_jsonObject



32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/dpl/provider/ops_works.rb', line 32

def custom_json
  {
    deploy: {
      ops_works_app[:shortname] => {
        migrate: !!options[:migrate],
        scm: {
          revision: current_sha
        }
      }
    }
  }
end

#deployObject



76
77
78
79
80
81
82
# File 'lib/dpl/provider/ops_works.rb', line 76

def deploy
  super
rescue AWS::Errors::ClientError => error
  raise Error, "Stopping Deploy, OpsWorks error: #{error.message}", error.backtrace
rescue AWS::Errors::ServerError => error
  raise Error, "Stopping Deploy, OpsWorks server error: #{error.message}", error.backtrace
end

#fetch_ops_works_appObject



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

def fetch_ops_works_app
  data = client.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

Returns:

  • (Boolean)


15
16
17
# File 'lib/dpl/provider/ops_works.rb', line 15

def needs_key?
  false
end

#ops_works_appObject



49
50
51
# File 'lib/dpl/provider/ops_works.rb', line 49

def ops_works_app
  @ops_works_app ||= fetch_ops_works_app
end

#push_appObject



61
62
63
64
65
66
67
68
69
70
# File 'lib/dpl/provider/ops_works.rb', line 61

def push_app
  data = client.create_deployment(
    stack_id: ops_works_app[:stack_id],
    app_id: option(:app_id),
    command: {name: 'deploy'},
    comment: travis_deploy_comment,
    custom_json: custom_json.to_json
  )
  log "Deployment created: #{data[:deployment_id]}"
end

#setup_authObject



23
24
25
# File 'lib/dpl/provider/ops_works.rb', line 23

def setup_auth
  AWS.config(access_key_id: option(:access_key_id), secret_access_key: option(:secret_access_key))
end

#travis_deploy_commentObject



72
73
74
# File 'lib/dpl/provider/ops_works.rb', line 72

def travis_deploy_comment
  "Deploy #{ENV['TRAVIS_COMMIT'] || current_sha} via Travis CI"
end