class Deploy::Runner

Public Class Methods

new(tag) click to toggle source
# File lib/deploy.rb, line 17
def initialize(tag)
  @tag = tag
end

Public Instance Methods

run() click to toggle source
# File lib/deploy.rb, line 21
def run
  trap_int
  precheck!
  validate!
  perform!
end

Private Instance Methods

app_bucket() click to toggle source
# File lib/deploy.rb, line 156
def app_bucket
  configuration.config_bucket_for(@name)
end
apps() click to toggle source
# File lib/deploy.rb, line 160
def apps
  configuration.apps
end
beanstalk_application(app) click to toggle source
# File lib/deploy.rb, line 172
def beanstalk_application(app)
  @beanstalk_application ||= Eb::Application.new(app)
end
check_for_aws_access!() click to toggle source
# File lib/deploy.rb, line 72
def check_for_aws_access!
  # Verify up AWS params, i.e. that we have access key and region.
  # Do so by connecting to IAM directly
  # Why IAM? If your user doesn't exist, nothing else will work.
  user =  IAM::Client.connection
  log "You are connected as #{user}."
end
check_for_changelog!() click to toggle source
# File lib/deploy.rb, line 65
def check_for_changelog!
  changelog_updated =
      cli.agree "Now hold on there for just a second, partner. "\
                "Have you updated the changelog ?"
  abort 'Better hop to it then ay?' unless changelog_updated
end
check_for_unstaged_changes!() click to toggle source
# File lib/deploy.rb, line 60
def check_for_unstaged_changes!
  return unless repo.index_modified?
  abort "You have staged changes! Please sort your life out mate, innit?"
end
cli() click to toggle source
# File lib/deploy.rb, line 93
def cli
  @cli ||= HighLine.new
end
config_bucket_name() click to toggle source
# File lib/deploy.rb, line 109
def config_bucket_name
  @config_bucket_name ||= set_config_bucket_name!
end
configuration() click to toggle source
# File lib/deploy.rb, line 97
def configuration
  @configuration ||= set_configuration
end
configure!() click to toggle source
# File lib/deploy.rb, line 122
def configure!
  return if on_beanstalk?
  # Pull in and verify our deployment configurations
  log "Checking available configurations... Please wait..."
  configuration.verify!
  unless configuration.created_folders.empty?
    configuration.created_folders.each do |folder|
      log "\tCreated #{folder}"
    end
  end
  log "Check done."
end
deploy!() click to toggle source
# File lib/deploy.rb, line 200
def deploy!
  log 'Deployment commencing.'
  success = @platform.deploy!
  abort "Deployment Failed or timed out. See system output." unless success
  log 'All done.'
end
deployment_target() click to toggle source
# File lib/deploy.rb, line 135
def deployment_target
  app = select_from_list(apps)
  return app unless on_beanstalk?
  select_from_list(eb_env_list(app))
end
eb() click to toggle source
# File lib/deploy.rb, line 164
def eb
  @eb ||= Eb::State.new(@name)
end
eb_env_list(app) click to toggle source
# File lib/deploy.rb, line 141
def eb_env_list(app)
  beanstalk_application(app).environments
end
log(msg) click to toggle source
# File lib/deploy.rb, line 48
def log(msg)
  # Currently no logging mechanism besides message to stdout
  puts msg
end
on_beanstalk?() click to toggle source
# File lib/deploy.rb, line 80
def on_beanstalk?
  @on_beanstalk ||= Eb::Platform.configured?
end
perform!() click to toggle source
# File lib/deploy.rb, line 42
def perform!
  request_confirmation!
  synchronize_repo!
  deploy!
end
precheck!() click to toggle source
# File lib/deploy.rb, line 30
def precheck!
  check_for_unstaged_changes!
  check_for_changelog!
  check_for_aws_access!
end
repo() click to toggle source
# File lib/deploy.rb, line 84
def repo
  @repo ||= Repository.new
end
request_confirmation!() click to toggle source
# File lib/deploy.rb, line 195
def request_confirmation!
  confirm_launch = cli.agree "Deploy release \'#{@tag}\' to \'#{@name}\' ?"
  abort 'Bailing out.' unless confirm_launch
end
s3() click to toggle source
# File lib/deploy.rb, line 168
def s3
  @s3 ||= S3::State.new(@name, app_bucket)
end
select_from_list(list) click to toggle source
# File lib/deploy.rb, line 145
def select_from_list(list)
  # Have the user decide what to deploy
  log "Configured applications are:"
  name = cli.choose do |menu|
    menu.prompt = "Choose application to deploy, by index or name."
    menu.choices *list
  end
  log "Selected \"#{name}\"."
  name
end
set_config_bucket_name!() click to toggle source
# File lib/deploy.rb, line 113
def set_config_bucket_name!
  bucket_name = ENV['S3_CONFIG_BUCKET']
  unless bucket_name
    fail 'Please set your S3 config bucket name in '\
         'ENV[\'S3_CONFIG_BUCKET\']'
  end
  bucket_name
end
set_configuration() click to toggle source
# File lib/deploy.rb, line 101
def set_configuration
  if on_beanstalk?
    Eb::Configuration.new
  else
    S3::Configuration.new(config_bucket_name)
  end
end
synchronize_repo!() click to toggle source
# File lib/deploy.rb, line 88
def synchronize_repo!
  log 'Preparing the tagged release version for deployment.'
  repo.prepare!(@tag)
end
trap_int() click to toggle source
# File lib/deploy.rb, line 53
def trap_int
  Signal.trap('INT') {
    abort "\nGot Ctrl-C, exiting.\n\
    You will have to abort any in-progress deployments manually."
  }
end
validate!() click to toggle source
# File lib/deploy.rb, line 36
def validate!
  configure!
  @name       = deployment_target
  @platform   = verify_platform
end
verify_platform() click to toggle source
# File lib/deploy.rb, line 176
def verify_platform
  if eb.exists?
    fail "EB app found but you did not \'eb init\'" unless on_beanstalk?
    platform = Eb::Platform.new(eb: eb, tag: @tag)
    log "Environment \'#{@name}\' found on EB."
  elsif s3.exists?
    platform = S3::Platform.new(s3: s3, tag: @tag)
    log "Website \'#{@name}\' found on S3."
    log "Config bucket version \"#{s3.version}\" selected."
  end
  unless platform
    abort  "Application given as \'#{@name}\'. "\
           "EB environment \'#{@name}\' was not found. "\
           "S3 bucket \'#{@name}\' was not found either. "\
           "Please fix this before attempting to deploy."
  end
  platform
end