class Dpl::Providers::Elasticbeanstalk

Constants

NON_PRINTABLE_CHARS

We do not actually know what characters are valid on AWS EB’s side, see: github.com/aws/aws-sdk-ruby/issues/1502

Reference: www.w3.org/TR/xml/#charsets

Attributes

object[R]
started[R]
version[R]

Public Instance Methods

archive_name() click to toggle source
# File lib/dpl/providers/elasticbeanstalk.rb, line 75
def archive_name
  "#{label}.zip"
end
bucket() click to toggle source
Calls superclass method
# File lib/dpl/providers/elasticbeanstalk.rb, line 184
def bucket
  @bucket ||= s3.bucket(super)
end
bucket_path() click to toggle source
# File lib/dpl/providers/elasticbeanstalk.rb, line 87
def bucket_path
  bucket_path? ? "#{super.gsub(%r{/*$}, '')}/#{archive_name}" : archive_name
end
check_deployment(msgs) click to toggle source
# File lib/dpl/providers/elasticbeanstalk.rb, line 141
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) click to toggle source
# File lib/dpl/providers/elasticbeanstalk.rb, line 198
def clean(str)
  str.gsub!(/[^#{NON_PRINTABLE_CHARS}]/, '') && info(:clean_description)
  str
end
create_version() click to toggle source
# File lib/dpl/providers/elasticbeanstalk.rb, line 114
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() click to toggle source
# File lib/dpl/providers/elasticbeanstalk.rb, line 99
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() click to toggle source
# File lib/dpl/providers/elasticbeanstalk.rb, line 176
def credentials
  Aws::Credentials.new(access_key_id, secret_access_key)
end
cwd() click to toggle source
# File lib/dpl/providers/elasticbeanstalk.rb, line 91
def cwd
  @cwd ||= "#{Dir.pwd}/"
end
debug(*args) click to toggle source
# File lib/dpl/providers/elasticbeanstalk.rb, line 203
def debug(*args)
  info(*args) if debug?
end
deploy() click to toggle source
# File lib/dpl/providers/elasticbeanstalk.rb, line 62
def deploy
  @started = Time.now
  bucket.create unless bucket.exists?
  create_zip unless zip_exists?
  upload
  create_version
  update_app if env?
end
description() click to toggle source
Calls superclass method
# File lib/dpl/providers/elasticbeanstalk.rb, line 83
def description
  super || git_commit_msg
end
eb() click to toggle source
# File lib/dpl/providers/elasticbeanstalk.rb, line 188
def eb
  @eb ||= Aws::ElasticBeanstalk::Client.new(retry_limit: 10)
end
environment() click to toggle source
# File lib/dpl/providers/elasticbeanstalk.rb, line 171
def environment
  args = { application_name: app, environment_names: [env] }
  eb.describe_environments(args)[:environments].first
end
events() click to toggle source
# File lib/dpl/providers/elasticbeanstalk.rb, line 166
def events
  args = { environment_name: env, start_time: started.utc.iso8601 }
  eb.describe_events(args)[:events].reverse
end
files() click to toggle source
# File lib/dpl/providers/elasticbeanstalk.rb, line 154
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) click to toggle source
# File lib/dpl/providers/elasticbeanstalk.rb, line 161
def filter(files, spec)
  spec = PathSpec.from_filename(spec)
  files.reject { |file| spec.match(file) }
end
label() click to toggle source
Calls superclass method
# File lib/dpl/providers/elasticbeanstalk.rb, line 79
def label
  @label ||= super || "travis-#{git_sha}-#{Time.now.to_i}"
end
login() click to toggle source
# File lib/dpl/providers/elasticbeanstalk.rb, line 53
def login
  info :login
end
s3() click to toggle source
# File lib/dpl/providers/elasticbeanstalk.rb, line 180
def s3
  @s3 ||= Aws::S3::Resource.new
end
setup() click to toggle source
# File lib/dpl/providers/elasticbeanstalk.rb, line 57
def setup
  info :login
  Aws.config.update(credentials:, region:)
end
update_app() click to toggle source
# File lib/dpl/providers/elasticbeanstalk.rb, line 127
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() click to toggle source
# File lib/dpl/providers/elasticbeanstalk.rb, line 108
def upload
  @object = bucket.object(bucket_path)
  object.put(body: File.open(zip_file))
  sleep 5 # s3 eventual consistency
end
wait_until_deployed() click to toggle source
# File lib/dpl/providers/elasticbeanstalk.rb, line 135
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?() click to toggle source
# File lib/dpl/providers/elasticbeanstalk.rb, line 95
def zip_exists?
  File.exist?(zip_file)
end
zip_file() click to toggle source
Calls superclass method
# File lib/dpl/providers/elasticbeanstalk.rb, line 71
def zip_file
  zip_file? ? expand(super) : archive_name
end