Class: DPL::Provider::OpsWorks
Instance Attribute Summary
#context, #options
Instance Method Summary
collapse
apt_get, #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
#api ⇒ Object
9
10
11
|
# File 'lib/dpl/provider/ops_works.rb', line 9
def api
@api ||= AWS::OpsWorks.new
end
|
#check_app ⇒ Object
21
22
23
|
# File 'lib/dpl/provider/ops_works.rb', line 21
def check_app
end
|
#check_auth ⇒ Object
29
30
31
32
|
# File 'lib/dpl/provider/ops_works.rb', line 29
def check_auth
setup_auth
log "Logging in with Access Key: #{option(:access_key_id)[-4..-1].rjust(20, '*')}"
end
|
#client ⇒ Object
13
14
15
|
# File 'lib/dpl/provider/ops_works.rb', line 13
def client
@client ||= api.client
end
|
#create_deployment ⇒ Object
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
|
# File 'lib/dpl/provider/ops_works.rb', line 71
def create_deployment
data = client.create_deployment(
stack_id: ops_works_app[:stack_id],
app_id: option(:app_id),
command: {name: 'deploy'},
comment: ,
custom_json: custom_json.to_json
)
log "Deployment created: #{data[:deployment_id]}"
return unless options[:wait_until_deployed]
print "Deploying "
deployment = wait_until_deployed(data[:deployment_id])
print "\n"
if deployment[:status] == 'successful'
log "Deployment successful."
else
error "Deployment failed."
end
end
|
#current_sha ⇒ Object
47
48
49
|
# File 'lib/dpl/provider/ops_works.rb', line 47
def current_sha
@current_sha ||= `git rev-parse HEAD`.chomp
end
|
#custom_json ⇒ Object
34
35
36
37
38
39
40
41
42
43
44
45
|
# File 'lib/dpl/provider/ops_works.rb', line 34
def custom_json
{
deploy: {
ops_works_app[:shortname] => {
migrate: !!options[:migrate],
scm: {
revision: current_sha
}
}
}
}
end
|
#deploy ⇒ Object
107
108
109
110
111
112
113
|
# File 'lib/dpl/provider/ops_works.rb', line 107
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_app ⇒ Object
55
56
57
58
59
60
61
|
# File 'lib/dpl/provider/ops_works.rb', line 55
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
17
18
19
|
# File 'lib/dpl/provider/ops_works.rb', line 17
def needs_key?
false
end
|
#ops_works_app ⇒ Object
51
52
53
|
# File 'lib/dpl/provider/ops_works.rb', line 51
def ops_works_app
@ops_works_app ||= fetch_ops_works_app
end
|
#push_app ⇒ Object
63
64
65
66
67
68
69
|
# File 'lib/dpl/provider/ops_works.rb', line 63
def push_app
Timeout::timeout(600) do
create_deployment
end
rescue Timeout::Error
error 'Timeout: Could not finish deployment in 10 minutes.'
end
|
#setup_auth ⇒ Object
25
26
27
|
# File 'lib/dpl/provider/ops_works.rb', line 25
def setup_auth
AWS.config(access_key_id: option(:access_key_id), secret_access_key: option(:secret_access_key))
end
|
103
104
105
|
# File 'lib/dpl/provider/ops_works.rb', line 103
def
"Deploy build #{ENV['TRAVIS_BUILD_NUMBER'] || current_sha} via Travis CI"
end
|
#wait_until_deployed(deployment_id) ⇒ Object
91
92
93
94
95
96
97
98
99
100
101
|
# File 'lib/dpl/provider/ops_works.rb', line 91
def wait_until_deployed(deployment_id)
deployment = nil
loop do
result = client.describe_deployments(deployment_ids: [deployment_id])
deployment = result[:deployments].first
break unless deployment[:status] == "running"
print "."
sleep 5
end
deployment
end
|