Class: Automan::Beanstalk::Version

Inherits:
Automan::Base show all
Includes:
Mixins::Utils
Defined in:
lib/automan/beanstalk/version.rb

Constant Summary

Constants included from Mixins::AwsCaller

Mixins::AwsCaller::S3_PROTO

Instance Attribute Summary

Attributes inherited from Automan::Base

#logger, #wait

Attributes included from Mixins::AwsCaller

#as, #cfn, #eb, #ec, #ec2, #elb, #r53, #rds, #s3

Instance Method Summary collapse

Methods included from Mixins::Utils

#region_from_az

Methods inherited from Automan::Base

add_option, #initialize, #log_options, #wait_until

Methods included from Mixins::AwsCaller

#account, #configure_aws, #looks_like_s3_path?, #parse_s3_path, #s3_object_exists?, #s3_read

Constructor Details

This class inherits a constructor from Automan::Base

Instance Method Details

#create(package) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/automan/beanstalk/version.rb', line 35

def create(package)
  logger.info "creating version #{label}"

  bucket, key = parse_s3_path(package)
  opts = {
    application_name: application,
    version_label:    label,
    source_bundle: {
      s3_bucket:      bucket,
      s3_key:         key
    }
  }

  response = eb.create_application_version opts

  unless response.successful?
    raise RequestFailedError, "create_application_version failed: #{response.error}"
  end
end

#cull_versions(max_versions) ⇒ Object



80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/automan/beanstalk/version.rb', line 80

def cull_versions(max_versions)
  log_options

  my_versions = versions
  if my_versions.size <= max_versions
    return
  end

  to_cull = my_versions.size - max_versions
  logger.info "culling oldest #{to_cull} versions"

  condemned = my_versions.sort_by {|v| v[:date_created] }[0..to_cull-1]

  condemned.each do |i|
    delete_by_label i[:version_label]
  end
end

#deleteObject



74
75
76
77
78
# File 'lib/automan/beanstalk/version.rb', line 74

def delete
  log_options

  delete_by_label label
end

#delete_by_label(version_label) ⇒ Object



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/automan/beanstalk/version.rb', line 55

def delete_by_label(version_label)
  logger.info "deleting version #{version_label} for application #{application}"

  opts = {
    application_name: application,
    version_label: version_label,
    delete_source_bundle: true
  }

  begin
    response = eb.delete_application_version opts
    unless response.successful?
      raise RequestFailedError, "delete_application_version failed #{response.error}"
    end
  rescue AWS::ElasticBeanstalk::Errors::SourceBundleDeletionFailure => e
    logger.warn e.message
  end
end

#exists?Boolean

Returns:

  • (Boolean)


25
26
27
28
29
30
31
32
33
# File 'lib/automan/beanstalk/version.rb', line 25

def exists?
  versions.each do |v|
    if v[:application_name] == application && v[:version_label] == label
      return true
    end
  end

  return false
end

#versionsObject



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/automan/beanstalk/version.rb', line 9

def versions
  logger.info "listing versions for #{application}"

  opts = {
    application_name: application
  }

  response = eb.describe_application_versions opts

  unless response.successful?
    raise RequestFailedError "describe_application_versions failed: #{response.error}"
  end

  response.data[:application_versions]
end