class AvoDeploy::Task::LocalTaskExecutionEnvironment

Public Class Methods

new(config) click to toggle source

Initialized the environment

@param config [Hash] deployment configuration

Calls superclass method
# File lib/avodeploy/task/local_task_execution_environment.rb, line 26
def initialize(config)
  super

  @dir = Dir.pwd
end

Public Instance Methods

chdir(dir) click to toggle source

Changes the directory for commands to be executed in

@param dir [String] the directory to change to

# File lib/avodeploy/task/local_task_execution_environment.rb, line 43
def chdir(dir)
  log.debug "changing directory [#{dir.yellow}] " + "locally".cyan

  Dir.chdir(dir)
  @dir = Dir.pwd
end
check_util_availability(utils) click to toggle source

Checks, if all utilities are available for the deployment process to be executed

@param utils [Array] array with utilities to check

Calls superclass method
# File lib/avodeploy/task/local_task_execution_environment.rb, line 36
def check_util_availability(utils)
  super(utils, 'locally')
end
command(cmd) click to toggle source

Executes a command locally in the current directory

@param cmd [String] the command to execute @return [CommandExecutionResult] result of the command exection

# File lib/avodeploy/task/local_task_execution_environment.rb, line 100
def command(cmd)
  log = AvoDeploy::Deployment.instance.log

  log.info "Executing [" + cmd.yellow + "] " + "locally".cyan

  result = AvoDeploy::CommandExecutionResult.new

  begin
    stdout, stderr, status = ::Open3.capture3(cmd, :chdir => cwd())

    result.stdin = cmd
    result.stdout = stdout
    result.stderr = stderr
    result.retval = status.exitstatus

    if result.stdout.nil? == false && result.stdout.empty? == false
      log.debug 'Stdout: ' + result.stdout.green
    end

    if result.stderr.nil? == false && result.stderr.empty? == false
      log.debug 'Stderr: ' + result.stderr.red
    end

    log.debug 'Retval: ' + result.retval.to_s
  rescue Exception => e
    handle_abort e
  end

  result
end
copy_to_target(target, file, remote) click to toggle source

Copies a file to a remote system (= target)

@param target [Target] the target system to deploy to @param file [String] the local file to upload @param remote [String] path on the remote system

# File lib/avodeploy/task/local_task_execution_environment.rb, line 69
def copy_to_target(target, file, remote)
  log = AvoDeploy::Deployment.instance.log

  log.info "started upload of file #{file} to #{target.name}"

  Net::SSH.start(
      target.config[:host],
      target.config[:user],
      {
        :port => target.config[:port],
        :auth_methods => [ 'publickey', 'hostbased' ],
      }
  ) do |session|
    session.scp.upload!(file, remote, :recursive => true) do |ch, name, sent, total|
      percentage = 0

      begin
        percentage = (sent.to_f * 100 / total.to_f).to_i
      rescue Exception => e
        AvoDeploy::Deployment.instance.handle_abort(e)
      end
    end
  end

  log.info "upload completed"
end
cwd() click to toggle source

Returns the current working directory

@return [String] current working directory

# File lib/avodeploy/task/local_task_execution_environment.rb, line 53
def cwd
  @dir
end
targets() click to toggle source

Returns all target systems to deploy to

@return [Hash] hash of target systems

# File lib/avodeploy/task/local_task_execution_environment.rb, line 60
def targets
  AvoDeploy::Deployment.instance.config.targets
end