Class: Dpl::Providers::Opsworks
Constant Summary
Dpl::Provider::FOLDS, Dpl::Provider::STAGES
Instance Attribute Summary
#key_name, #repo_name
Instance Method Summary
collapse
#before_finish, #before_init, #before_install, #before_prepare, #before_setup, #chmod, #cleanup, #cmd, #compact, #err, #error, #escape, examples, #expand, #file?, #finish?, #fold, #fold?, #info, #initialize, install_deps, install_deps?, #mkdir_p, move_files, #msg, #mv, #only, #open, #opt_for, #opt_key, #opts_for, #print, #quote, #read, #remove_dpl_dir, #rm_rf, #run, #run_cmd, #run_cmds, #run_stage, #run_stage?, #script, #setup_dpl_dir, #setup_git_config, #setup_git_http_user_agent, #setup_git_ssh, #setup_ssh_key, #shell, #sq, #ssh_keygen, #symbolize, #try_ssh_access, #uncleanup, unmove_files, validate_runtimes, #wait_for_ssh_access, #warn
#apt, #apt?, #cmds, #description, #env, #errs, #full_name, #gem, #gem?, #keep, #move, #msgs, #needs, #needs?, #node_js, #npm, #npm?, #opt, #path, #pip, #pip?, #python, #ruby_pre?, #ruby_version, #runtimes, #status, #strs, #summary, #user_agent, #vars
Methods included from Squiggle
#sq
Methods included from Assets
#asset
Methods included from Env
included, #opts
Methods included from ConfigFile
included, #opts
#interpolate, #obfuscate, #vars
Methods included from Memoize
included
Constructor Details
This class inherits a constructor from Dpl::Provider
Instance Method Details
#app ⇒ Object
107
108
109
|
# File 'lib/dpl/providers/opsworks.rb', line 107
def app
@app ||= describe_app
end
|
#build_number ⇒ Object
115
116
117
|
# File 'lib/dpl/providers/opsworks.rb', line 115
def build_number
super || sha
end
|
111
112
113
|
# File 'lib/dpl/providers/opsworks.rb', line 111
def
interpolate(msg(:comment))
end
|
#create_deployment ⇒ Object
52
53
54
55
56
57
|
# File 'lib/dpl/providers/opsworks.rb', line 52
def create_deployment
print :create_deploy
id = opsworks.create_deployment(deploy_config)[:deployment_id]
info :done, id
wait_until_deployed(id) if wait_until_deployed?
end
|
#credentials ⇒ Object
133
134
135
|
# File 'lib/dpl/providers/opsworks.rb', line 133
def credentials
Aws::Credentials.new(access_key_id, secret_access_key)
end
|
#custom_json ⇒ Object
99
100
101
|
# File 'lib/dpl/providers/opsworks.rb', line 99
def custom_json
super || { deploy: { app[:shortname] => { migrate: migrate?, scm: { revision: git_sha } } } }.to_json
end
|
#deploy ⇒ Object
46
47
48
49
50
|
# File 'lib/dpl/providers/opsworks.rb', line 46
def deploy
timeout(600) { create_deployment }
rescue Aws::Errors::ServiceError => e
error :service_error, e.message
end
|
#deploy_config ⇒ Object
59
60
61
62
63
64
65
66
67
68
69
|
# File 'lib/dpl/providers/opsworks.rb', line 59
def deploy_config
compact(
stack_id: stack_id,
app_id: app_id,
command: { name: 'deploy' },
comment: ,
custom_json: custom_json,
instance_ids: instance_ids,
layer_ids: layer_ids
)
end
|
#describe_app ⇒ Object
119
120
121
122
123
|
# File 'lib/dpl/providers/opsworks.rb', line 119
def describe_app
data = opsworks.describe_apps(app_ids: [app_id])
error :app_not_found, app_id unless data[:apps] && data[:apps].any?
data[:apps].first
end
|
#describe_deployments(id) ⇒ Object
125
126
127
|
# File 'lib/dpl/providers/opsworks.rb', line 125
def describe_deployments(id)
opsworks.describe_deployments(deployment_ids: [id])
end
|
#login ⇒ Object
42
43
44
|
# File 'lib/dpl/providers/opsworks.rb', line 42
def login
info :login
end
|
#opsworks ⇒ Object
129
130
131
|
# File 'lib/dpl/providers/opsworks.rb', line 129
def opsworks
@opsworks ||= Aws::OpsWorks::Client.new(region: region, credentials: credentials)
end
|
#poll_deployment(id) ⇒ Object
79
80
81
82
83
|
# File 'lib/dpl/providers/opsworks.rb', line 79
def poll_deployment(id)
print '.'
sleep 5
describe_deployments(id)[:deployments].first
end
|
#stack_id ⇒ Object
103
104
105
|
# File 'lib/dpl/providers/opsworks.rb', line 103
def stack_id
app[:stack_id]
end
|
#timeout(sec, &block) ⇒ Object
137
138
139
140
141
|
# File 'lib/dpl/providers/opsworks.rb', line 137
def timeout(sec, &block)
Timeout::timeout(sec, &block)
rescue Timeout::Error
error :timeout
end
|
#update_app ⇒ Object
85
86
87
88
|
# File 'lib/dpl/providers/opsworks.rb', line 85
def update_app
info :update_app
opsworks.update_app(update_config)
end
|
#update_config ⇒ Object
90
91
92
93
94
95
96
97
|
# File 'lib/dpl/providers/opsworks.rb', line 90
def update_config
{
app_id: app_id,
app_source: {
revision: git_sha,
}
}
end
|
#wait_until_deployed(id) ⇒ Object
71
72
73
74
75
76
77
|
# File 'lib/dpl/providers/opsworks.rb', line 71
def wait_until_deployed(id)
print :waiting
depl = poll_deployment(id) while depl.nil? || depl[:status] == 'running'
error :failed if depl[:status] != 'successful'
info :success
update_app if update_on_success?
end
|