Class: AvoDeploy::Task::LocalTaskExecutionEnvironment
- Inherits:
-
TaskExecutionEnvironment
- Object
- TaskExecutionEnvironment
- AvoDeploy::Task::LocalTaskExecutionEnvironment
- Defined in:
- lib/avodeploy/task/local_task_execution_environment.rb
Instance Method Summary collapse
-
#chdir(dir) ⇒ Object
Changes the directory for commands to be executed in.
-
#check_util_availability(utils) ⇒ Object
Checks, if all utilities are available for the deployment process to be executed.
-
#command(cmd) ⇒ CommandExecutionResult
Executes a command locally in the current directory.
-
#copy_to_target(target, file, remote) ⇒ Object
Copies a file to a remote system (= target).
-
#cwd ⇒ String
Returns the current working directory.
-
#initialize(config) ⇒ LocalTaskExecutionEnvironment
constructor
Initialized the environment.
-
#targets ⇒ Hash
Returns all target systems to deploy to.
Methods inherited from TaskExecutionEnvironment
#get, #handle_abort, #log, #scm_provider=, #set
Constructor Details
#initialize(config) ⇒ LocalTaskExecutionEnvironment
Initialized the environment
26 27 28 29 30 |
# File 'lib/avodeploy/task/local_task_execution_environment.rb', line 26 def initialize(config) super @dir = Dir.pwd end |
Instance Method Details
#chdir(dir) ⇒ Object
Changes the directory for commands to be executed in
43 44 45 46 47 48 |
# 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) ⇒ Object
Checks, if all utilities are available for the deployment process to be executed
36 37 38 |
# File 'lib/avodeploy/task/local_task_execution_environment.rb', line 36 def check_util_availability(utils) super(utils, 'locally') end |
#command(cmd) ⇒ CommandExecutionResult
Executes a command locally in the current directory
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/avodeploy/task/local_task_execution_environment.rb', line 96 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 rescue Exception => e handle_abort e end result end |
#copy_to_target(target, file, remote) ⇒ Object
Copies a file to a remote system (= target)
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# 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] ) 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 ⇒ String
Returns the current working directory
53 54 55 |
# File 'lib/avodeploy/task/local_task_execution_environment.rb', line 53 def cwd @dir end |
#targets ⇒ Hash
Returns all target systems to deploy to
60 61 62 |
# File 'lib/avodeploy/task/local_task_execution_environment.rb', line 60 def targets AvoDeploy::Deployment.instance.config.targets end |