Class: Dpl::Providers::Elasticbeanstalk
Constant Summary
collapse
- NON_PRINTABLE_CHARS =
"\u0009\u000A\u000D\u0020-\uD7FF\uE000-\uFFFD\u10000-\u10FFFF"
Dpl::Provider::FOLDS, Dpl::Provider::STAGES
Instance Attribute Summary collapse
#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, #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 Attribute Details
#object ⇒ Object
Returns the value of attribute object.
48
49
50
|
# File 'lib/dpl/providers/elasticbeanstalk.rb', line 48
def object
@object
end
|
#started ⇒ Object
Returns the value of attribute started.
48
49
50
|
# File 'lib/dpl/providers/elasticbeanstalk.rb', line 48
def started
@started
end
|
#version ⇒ Object
Returns the value of attribute version.
48
49
50
|
# File 'lib/dpl/providers/elasticbeanstalk.rb', line 48
def version
@version
end
|
Instance Method Details
#archive_name ⇒ Object
72
73
74
|
# File 'lib/dpl/providers/elasticbeanstalk.rb', line 72
def archive_name
"#{label}.zip"
end
|
#bucket ⇒ Object
181
182
183
|
# File 'lib/dpl/providers/elasticbeanstalk.rb', line 181
def bucket
@bucket ||= s3.bucket(super)
end
|
#bucket_path ⇒ Object
84
85
86
|
# File 'lib/dpl/providers/elasticbeanstalk.rb', line 84
def bucket_path
bucket_path? ? "#{super.gsub(/\/*$/, '')}/#{archive_name}" : archive_name
end
|
#check_deployment(msgs) ⇒ Object
138
139
140
141
142
143
144
145
146
147
148
149
|
# File 'lib/dpl/providers/elasticbeanstalk.rb', line 138
def check_deployment(msgs)
sleep 5
events.each do |event|
msg = "#{event.event_date} [#{event.severity}] #{event.message}"
error "Deployment failed: #{msg}" if event.severity == 'ERROR'
info msg unless msgs.include?(msg)
msgs << msg
end
environment[:status] == 'Ready'
rescue Aws::Errors::ServiceError => e
info "Caught #{e}: #{e.message}. Retrying ..."
end
|
#clean(str) ⇒ Object
195
196
197
198
|
# File 'lib/dpl/providers/elasticbeanstalk.rb', line 195
def clean(str)
str.gsub!(/[^#{NON_PRINTABLE_CHARS}]/, '') && info(:clean_description)
str
end
|
#create_version ⇒ Object
111
112
113
114
115
116
117
118
119
120
121
122
|
# File 'lib/dpl/providers/elasticbeanstalk.rb', line 111
def create_version
@version = eb.create_application_version(
application_name: app,
version_label: label,
description: clean(description[0, 200]),
source_bundle: {
s3_bucket: bucket.name,
s3_key: object.key
},
auto_create_application: false
)
end
|
#create_zip ⇒ Object
96
97
98
99
100
101
102
103
|
# File 'lib/dpl/providers/elasticbeanstalk.rb', line 96
def create_zip
::Zip::File.open(zip_file, ::Zip::File::CREATE) do |zip|
files.each do |path|
debug :zip_add, path
zip.add(path.sub(cwd, ''), path)
end
end
end
|
#credentials ⇒ Object
173
174
175
|
# File 'lib/dpl/providers/elasticbeanstalk.rb', line 173
def credentials
Aws::Credentials.new(access_key_id, secret_access_key)
end
|
#cwd ⇒ Object
88
89
90
|
# File 'lib/dpl/providers/elasticbeanstalk.rb', line 88
def cwd
@cwd ||= "#{Dir.pwd}/"
end
|
#debug(*args) ⇒ Object
200
201
202
|
# File 'lib/dpl/providers/elasticbeanstalk.rb', line 200
def debug(*args)
info *args if debug?
end
|
#deploy ⇒ Object
59
60
61
62
63
64
65
66
|
# File 'lib/dpl/providers/elasticbeanstalk.rb', line 59
def deploy
@started = Time.now
bucket.create unless bucket.exists?
create_zip unless zip_exists?
upload
create_version
update_app if env?
end
|
#description ⇒ Object
80
81
82
|
# File 'lib/dpl/providers/elasticbeanstalk.rb', line 80
def description
super || git_commit_msg
end
|
#eb ⇒ Object
185
186
187
|
# File 'lib/dpl/providers/elasticbeanstalk.rb', line 185
def eb
@eb ||= Aws::ElasticBeanstalk::Client.new(retry_limit: 10)
end
|
#environment ⇒ Object
168
169
170
171
|
# File 'lib/dpl/providers/elasticbeanstalk.rb', line 168
def environment
args = { application_name: app, environment_names: [env] }
eb.describe_environments(args)[:environments].first
end
|
#events ⇒ Object
163
164
165
166
|
# File 'lib/dpl/providers/elasticbeanstalk.rb', line 163
def events
args = { environment_name: env, start_time: started.utc.iso8601 }
eb.describe_events(args)[:events].reverse
end
|
#files ⇒ Object
151
152
153
154
155
156
|
# File 'lib/dpl/providers/elasticbeanstalk.rb', line 151
def files
files = Dir.glob('**/*', File::FNM_DOTMATCH)
ignore = %w(.ebignore .gitignore).detect { |file| file?(file) }
files = filter(files, ignore) if ignore
files
end
|
#filter(files, spec) ⇒ Object
158
159
160
161
|
# File 'lib/dpl/providers/elasticbeanstalk.rb', line 158
def filter(files, spec)
spec = PathSpec.from_filename(spec)
files.reject { |file| spec.match(file) }
end
|
#label ⇒ Object
76
77
78
|
# File 'lib/dpl/providers/elasticbeanstalk.rb', line 76
def label
@label ||= super || "travis-#{git_sha}-#{Time.now.to_i}"
end
|
#login ⇒ Object
50
51
52
|
# File 'lib/dpl/providers/elasticbeanstalk.rb', line 50
def login
info :login
end
|
#s3 ⇒ Object
177
178
179
|
# File 'lib/dpl/providers/elasticbeanstalk.rb', line 177
def s3
@s3 ||= Aws::S3::Resource.new
end
|
#setup ⇒ Object
54
55
56
57
|
# File 'lib/dpl/providers/elasticbeanstalk.rb', line 54
def setup
info :login
Aws.config.update(credentials: credentials, region: region)
end
|
#update_app ⇒ Object
124
125
126
127
128
129
130
|
# File 'lib/dpl/providers/elasticbeanstalk.rb', line 124
def update_app
eb.update_environment(
environment_name: env,
version_label: version[:application_version][:version_label]
)
wait_until_deployed if wait_until_deployed?
end
|
#upload ⇒ Object
105
106
107
108
109
|
# File 'lib/dpl/providers/elasticbeanstalk.rb', line 105
def upload
@object = bucket.object(bucket_path)
object.put(body: File.open(zip_file))
sleep 5 end
|
#wait_until_deployed ⇒ Object
132
133
134
135
136
|
# File 'lib/dpl/providers/elasticbeanstalk.rb', line 132
def wait_until_deployed
msgs = []
1.upto(wait_until_deployed_timeout / 5) { return if check_deployment(msgs) }
error 'Deploy status unknown due to timeout. Increase the wait_until_deployed_timeout option'
end
|
#zip_exists? ⇒ Boolean
92
93
94
|
# File 'lib/dpl/providers/elasticbeanstalk.rb', line 92
def zip_exists?
File.exists?(zip_file)
end
|
#zip_file ⇒ Object
68
69
70
|
# File 'lib/dpl/providers/elasticbeanstalk.rb', line 68
def zip_file
zip_file? ? expand(super) : archive_name
end
|