Module: Vagrant
- Defined in:
- lib/rake_ci_tools/runners/vagrant.rb
Class Method Summary collapse
- .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
.command(command, box_name) ⇒ Object
31 32 33 |
# File 'lib/rake_ci_tools/runners/vagrant.rb', line 31 def self.command(command, box_name) sh "vagrant ssh #{box_name} --command \"cd #{remoteLocation} && #{command}\"" end |
.copy_file_to_guest(localLocation, box_name) ⇒ Object
35 36 37 38 |
# File 'lib/rake_ci_tools/runners/vagrant.rb', line 35 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
18 19 20 |
# File 'lib/rake_ci_tools/runners/vagrant.rb', line 18 def self.create_box(box_name) sh "vagrant up #{box_name} --provision" end |
.destroy_box(box_name) ⇒ Object
22 23 24 25 26 27 28 29 |
# File 'lib/rake_ci_tools/runners/vagrant.rb', line 22 def self.destroy_box(box_name) puts "Destorying: #{box_name}" begin get_file_from_guest('./',"#{remoteLocation}/ci-artifacts",box_name) ensure sh "vagrant destroy -f #{box_name}" end end |
.get_file_from_guest(localLocation, box_name) ⇒ Object
40 41 42 43 |
# File 'lib/rake_ci_tools/runners/vagrant.rb', line 40 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
53 54 55 56 |
# File 'lib/rake_ci_tools/runners/vagrant.rb', line 53 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
45 46 47 48 49 50 51 |
# File 'lib/rake_ci_tools/runners/vagrant.rb', line 45 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: $$" 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 |