class AvoDeploy::Task::LocalTaskExecutionEnvironment
Public Class Methods
Initialized the environment
@param config [Hash] deployment configuration
# File lib/avodeploy/task/local_task_execution_environment.rb, line 26 def initialize(config) super @dir = Dir.pwd end
Public Instance Methods
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
Checks, if all utilities are available for the deployment process to be executed
@param utils [Array] array with utilities to check
# File lib/avodeploy/task/local_task_execution_environment.rb, line 36 def check_util_availability(utils) super(utils, 'locally') end
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
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
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
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