class DEIS::Upgrade

Attributes

deploy_to[RW]
proxy[RW]
ssh[RW]
token[RW]

Public Class Methods

new(options, previous=nil) click to toggle source
# File lib/rdeis/upgrade.rb, line 7
def initialize(options, previous=nil)
  @repo = DEIS::Git.name
  @verbose = options[:verbose]
  @environment = options[:environment]
  @proxy = if ! options["proxy"].nil? then options["proxy"] elsif ! ENV['RDEIS_PROXY'].nil? then ENV['RDEIS_PROXY'] else nil end
  @ssh = SSH.new({:host => @proxy, :user => nil}) if ! @proxy.nil?
  @previous = if previous.nil? then DEIS::LAST_VERSION else previous end
end

Public Instance Methods

all() click to toggle source
# File lib/rdeis/upgrade.rb, line 18
def all
  # check for current version
  previous_version = DEIS::Storage::BASE_PATH.gsub(DEIS::VERSION, @previous)
  local_prev = previous_version.gsub("$HOME", ENV['HOME'])
  current_version = DEIS::Storage::BASE_PATH
  local_curr = current_version.gsub("$HOME", ENV['HOME'])
  # local
  # if no found, look for previous version
  if ! File.directory?(local_curr) && File.directory?(local_prev)
    say("Found previous version config files locally, migrating..", :green)
    `mv -f #{local_prev} #{local_curr}`
    # find local profile
    content = File.open(self.local_profile, "r"){|f| f.read }
    File.open(self.local_profile, "w"){|f| f.write(content.gsub(previous_version, current_version)) }
  end
  # remote
  remote_current = run("ls -lart #{current_version} 2> /dev/null | wc -l").to_i
  remote_previous = run("ls -lart #{previous_version} 2> /dev/null | wc -l").to_i
  if remote_current == 0 && remote_previous > 1
    say("Found previous remote version, migration..", :green)
    run("mv -f #{previous_version} #{current_version}")
    # replace profile
    run("cat #{self.remote_profile} | sed -E 's##{previous_version.gsub("$", "\\\$")}##{current_version.gsub("$", "\\\$")}#' > #{self.remote_profile}.new && mv #{self.remote_profile} #{self.remote_profile}.bk && mv #{self.remote_profile}.new #{self.remote_profile}")
  end
end