Module: Vagrant
- Defined in:
- lib/rake_ci_tools/runners/vagrant.rb
Class Method Summary collapse
- .artifact_path ⇒ Object
- .command(command, box_name) ⇒ Object
- .copy_file_to_guest(localLocation, box_name) ⇒ Object
-
.create_box(box_name) ⇒ Object
ALL BELOW UNTESTED REFACTOR.
- .destroy_box(box_name) ⇒ Object
- .get_file_from_guest(localLocation, box_name) ⇒ Object
- .get_ssh_details(regex, box_name) ⇒ Object
- .remoteLocation ⇒ Object
- .scp(from, to, box_name) ⇒ Object
- .task(box_name, tasks = [], project_location = './') ⇒ Object
Class Method Details
.artifact_path ⇒ Object
17 18 19 |
# File 'lib/rake_ci_tools/runners/vagrant.rb', line 17 def self.artifact_path ENV['ARTIFACT_PATH'] || 'ci-artifacts' end |
.command(command, box_name) ⇒ Object
35 36 37 |
# File 'lib/rake_ci_tools/runners/vagrant.rb', line 35 def self.command(command, box_name) sh "vagrant ssh #{box_name} --command \"cd #{remoteLocation} && #{command}\"" end |
.copy_file_to_guest(localLocation, box_name) ⇒ Object
39 40 41 42 |
# File 'lib/rake_ci_tools/runners/vagrant.rb', line 39 def self.copy_file_to_guest(localLocation, box_name) serverIp = get_ssh_details(/(?<=HostName ).*/, box_name) scp(localLocation,"vagrant@#{serverIp}:#{remoteLocation}", box_name) end |
.create_box(box_name) ⇒ Object
ALL BELOW UNTESTED REFACTOR
22 23 24 |
# File 'lib/rake_ci_tools/runners/vagrant.rb', line 22 def self.create_box(box_name) sh "vagrant up #{box_name} --provision" end |
.destroy_box(box_name) ⇒ Object
26 27 28 29 30 31 32 33 |
# File 'lib/rake_ci_tools/runners/vagrant.rb', line 26 def self.destroy_box(box_name) puts "Destorying: #{box_name}" begin get_file_from_guest("./#{artifact_path}",box_name) ensure sh "vagrant destroy -f #{box_name}" end end |
.get_file_from_guest(localLocation, box_name) ⇒ Object
44 45 46 47 |
# File 'lib/rake_ci_tools/runners/vagrant.rb', line 44 def self.get_file_from_guest(localLocation, box_name) serverIp = get_ssh_details(/(?<=HostName ).*/,box_name) scp("vagrant@#{serverIp}:#{remoteLocation}",localLocation,box_name) end |
.get_ssh_details(regex, box_name) ⇒ Object
57 58 59 60 |
# File 'lib/rake_ci_tools/runners/vagrant.rb', line 57 def self.get_ssh_details(regex, box_name) response = `vagrant ssh-config #{box_name}` return response.match(regex) end |
.remoteLocation ⇒ Object
13 14 15 |
# File 'lib/rake_ci_tools/runners/vagrant.rb', line 13 def self.remoteLocation ENV['VAGANT_REMOTE_DEST'] || 'vagrant_build' end |
.scp(from, to, box_name) ⇒ Object
49 50 51 52 53 54 55 |
# File 'lib/rake_ci_tools/runners/vagrant.rb', line 49 def self.scp(from, to, box_name) portNum = get_ssh_details(/(?<=Port ).*/,box_name) keyPath = get_ssh_details(/(?<=IdentityFile ).*/,box_name) puts "PortNum: #{portNum}" sh "scp -o 'StrictHostKeyChecking no' -i #{keyPath} -P #{portNum} -r #{from} #{to}" end |
.task(box_name, tasks = [], project_location = './') ⇒ Object
2 3 4 5 6 7 8 9 10 11 |
# File 'lib/rake_ci_tools/runners/vagrant.rb', line 2 def self.task(box_name, tasks=[], project_location='./') begin puts "Creating Vagrantbox for Process ID: #{Process.pid}" create_box(box_name) copy_file_to_guest(project_location,box_name) tasks.each { |task| command(task,box_name) } ensure destroy_box(box_name) end end |