module Vagrant

Public Class Methods

artifact_path() click to toggle source
# File lib/rake_ci_tools/runners/vagrant.rb, line 17
def self.artifact_path
    ENV['ARTIFACT_PATH'] || 'ci-artifacts'
end
command(command, box_name) click to toggle source
# 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) click to toggle source
# 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) click to toggle source

ALL BELOW UNTESTED REFACTOR

# 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) click to toggle source
# 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("./",box_name)
    ensure
        sh "vagrant destroy -f #{box_name}"
    end
end
get_file_from_guest(localLocation, box_name) click to toggle source
# 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}/#{artifact_path}",localLocation,box_name)
end
get_ssh_details(regex, box_name) click to toggle source
# 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() click to toggle source
# 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) click to toggle source
# 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='./') click to toggle source
# 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