class Papa::Command::Larga::Deploy

Constants

RELEASE_OR_INTEGRATION_LIFESPAN
RELEASE_OR_INTEGRATION_PROTECTION

Public Class Methods

new(options) click to toggle source
Calls superclass method Papa::Command::Base::new
# File lib/papa/command/larga/deploy.rb, line 10
def initialize(options)
  @options = options

  command = "larga #{larga_options.join(' ')}"
  super(command, silent: false)
end

Public Instance Methods

failed?() click to toggle source
# File lib/papa/command/larga/deploy.rb, line 32
def failed?
  stdout.include?('Cowardly refusing') || stdout.include?('Error')
end
failure_message() click to toggle source
# File lib/papa/command/larga/deploy.rb, line 27
def failure_message
  message = "Error while running #{command.bold}"
  Helper::Output.error message
end
run() click to toggle source
# File lib/papa/command/larga/deploy.rb, line 17
def run
  Helper::Output.stdout "Running #{command.bold}..."
  @stdout = ''
  IO.popen(command).each do |line|
    @stdout << line
    Helper::Output.info line
  end
  self
end

Private Instance Methods

destroy_old_instances(previous_branches) click to toggle source
# File lib/papa/command/larga/deploy.rb, line 69
def destroy_old_instances(previous_branches)
  Helper::Output.stdout "Destroying old instances..."
  previous_branches.each do |previous_branch|
    destroy_command = "larga -action destroy -branch #{previous_branch}"
    Helper::Output.stdout "Running #{destroy_command.bold}..."
    IO.popen(destroy_command).each do |line|
      Helper::Output.info line
    end
  end
end
determine_action() click to toggle source
# File lib/papa/command/larga/deploy.rb, line 54
def determine_action
  previous_branches = `larga -action show -branch x | grep https://#{@options[:hostname]} | awk '{print $1}'`.chomp.split("\n")
  if previous_branches.empty?
    # If there are no old instances with the same hostname, continue building instance.
    return 'build'
  elsif previous_branches.count == 1 && previous_branches.include?(@options[:branch])
    # If the old instance has the same branch name, skip building and just deploy.
    return 'deploy'
  else
    # If all else fails, destroy old instance(s), and continue building.
    destroy_old_instances(previous_branches)
    return 'build'
  end
end
larga_options() click to toggle source
# File lib/papa/command/larga/deploy.rb, line 38
def larga_options
  action = determine_action
  branch = @options[:branch]
  lifespan = RELEASE_OR_INTEGRATION_LIFESPAN
  protection = RELEASE_OR_INTEGRATION_PROTECTION
  hostname = @options[:hostname]

  options = []
  options << "-action #{action}"
  options << "-branch #{branch}"
  options << "-lifespan #{lifespan}"
  options << "-protection #{protection}"
  options << "-hostname #{hostname}"
  options
end