class DPL::Provider::ElasticBeanstalk
Constants
- DEFAULT_REGION
Public Instance Methods
access_key_id()
click to toggle source
# File lib/dpl/provider/elastic_beanstalk.rb, line 17 def access_key_id options[:access_key_id] || context.env['AWS_ACCESS_KEY_ID'] || raise(Error, "missing access_key_id") end
check_app()
click to toggle source
# File lib/dpl/provider/elastic_beanstalk.rb, line 33 def check_app end
check_auth()
click to toggle source
# File lib/dpl/provider/elastic_beanstalk.rb, line 25 def check_auth options = { :region => region, :credentials => Aws::Credentials.new(access_key_id, secret_access_key) } Aws.config.update(options) end
needs_key?()
click to toggle source
# File lib/dpl/provider/elastic_beanstalk.rb, line 13 def needs_key? false end
only_create_app_version()
click to toggle source
# File lib/dpl/provider/elastic_beanstalk.rb, line 36 def only_create_app_version options[:only_create_app_version] end
push_app()
click to toggle source
# File lib/dpl/provider/elastic_beanstalk.rb, line 40 def push_app @start_time = Time.now create_bucket unless bucket_exists? if options[:zip_file] zip_file = File.expand_path(options[:zip_file]) else zip_file = create_zip end s3_object = upload(archive_name, zip_file) sleep 5 #s3 eventual consistency version = create_app_version(s3_object) if !only_create_app_version update_app(version) wait_until_deployed if options[:wait_until_deployed] end end
secret_access_key()
click to toggle source
# File lib/dpl/provider/elastic_beanstalk.rb, line 21 def secret_access_key options[:secret_access_key] || context.env['AWS_SECRET_ACCESS_KEY'] || raise(Error, "missing secret_access_key") end
Private Instance Methods
app_name()
click to toggle source
# File lib/dpl/provider/elastic_beanstalk.rb, line 61 def app_name option(:app) end
archive_name()
click to toggle source
# File lib/dpl/provider/elastic_beanstalk.rb, line 77 def archive_name "#{version_label}.zip" end
bucket_exists?()
click to toggle source
# File lib/dpl/provider/elastic_beanstalk.rb, line 101 def bucket_exists? s3.bucket(bucket_name).exists? end
bucket_name()
click to toggle source
# File lib/dpl/provider/elastic_beanstalk.rb, line 85 def bucket_name option(:bucket_name) end
bucket_path()
click to toggle source
# File lib/dpl/provider/elastic_beanstalk.rb, line 89 def bucket_path @bucket_path ||= options[:bucket_path] ? option(:bucket_path).gsub(/\/*$/,'/') : nil end
create_app_version(s3_object)
click to toggle source
# File lib/dpl/provider/elastic_beanstalk.rb, line 136 def create_app_version(s3_object) # Elastic Beanstalk doesn't support descriptions longer than 200 characters description = version_description[0, 200] options = { :application_name => app_name, :version_label => version_label, :description => description, :source_bundle => { :s3_bucket => bucket_name, :s3_key => s3_object.key }, :auto_create_application => false } eb.create_application_version(options) end
create_bucket()
click to toggle source
# File lib/dpl/provider/elastic_beanstalk.rb, line 105 def create_bucket s3.bucket(bucket_name).create end
create_zip()
click to toggle source
# File lib/dpl/provider/elastic_beanstalk.rb, line 113 def create_zip directory = Dir.pwd zipfile_name = File.join(directory, archive_name) Zip::File.open(zipfile_name, Zip::File::CREATE) do |zipfile| files_to_pack.each do |file| relative_archive_path = File.join(directory, '/') zipfile.add(file.sub(relative_archive_path, ''), file) end end zipfile_name end
eb()
click to toggle source
# File lib/dpl/provider/elastic_beanstalk.rb, line 97 def eb @eb ||= Aws::ElasticBeanstalk::Client.new end
env_name()
click to toggle source
# File lib/dpl/provider/elastic_beanstalk.rb, line 65 def env_name options[:env] || context.env['ELASTIC_BEANSTALK_ENV'] || raise(Error, "missing env") end
files_to_pack()
click to toggle source
# File lib/dpl/provider/elastic_beanstalk.rb, line 109 def files_to_pack `git ls-files -z`.split("\x0") end
region()
click to toggle source
# File lib/dpl/provider/elastic_beanstalk.rb, line 81 def region options[:region] || DEFAULT_REGION end
s3()
click to toggle source
# File lib/dpl/provider/elastic_beanstalk.rb, line 93 def s3 @s3 ||= Aws::S3::Resource.new end
update_app(version)
click to toggle source
# File lib/dpl/provider/elastic_beanstalk.rb, line 186 def update_app(version) options = { :environment_name => env_name, :version_label => version[:application_version][:version_label] } eb.update_environment(options) end
upload(key, file)
click to toggle source
# File lib/dpl/provider/elastic_beanstalk.rb, line 126 def upload(key, file) options = { :body => Pathname.new(file).open } bucket = s3.bucket(bucket_name) obj = bucket_path ? bucket.object("#{bucket_path}#{key}") : bucket.object(key) obj.put(options) obj end
version_description()
click to toggle source
# File lib/dpl/provider/elastic_beanstalk.rb, line 73 def version_description context.env['ELASTIC_BEANSTALK_DESCRIPTION'] || commit_msg end
version_label()
click to toggle source
# File lib/dpl/provider/elastic_beanstalk.rb, line 69 def version_label context.env['ELASTIC_BEANSTALK_LABEL'] || "travis-#{sha}-#{Time.now.to_i}" end
wait_until_deployed()
click to toggle source
Wait until EB environment update finishes
# File lib/dpl/provider/elastic_beanstalk.rb, line 153 def wait_until_deployed errorEvents = 0 # errors counter, should remain 0 for successful deployment events = [] loop do environment = eb.describe_environments({ :application_name => app_name, :environment_names => [env_name] })[:environments].first eb.describe_events({ :environment_name => env_name, :start_time => @start_time.utc.iso8601, })[:events].reverse.each do |event| message = "#{event[:event_date]} [#{event[:severity]}] #{event[:message]}" unless events.include?(message) events.push(message) if event[:severity] == "ERROR" errorEvents += 1 warn(message) else log(message) end end end break if environment[:status] == "Ready" sleep 5 end if errorEvents > 0 then error("Deployment failed.") end end