-
Notifications
You must be signed in to change notification settings - Fork 20
ENT-5725: Added vagrant provider for spawning VMs #156
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
include cf_remote/nt-discovery.sh | ||
include cf_remote/Vagrantfile | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
# -*- mode: ruby -*- | ||
# vi: set ft=ruby : | ||
require 'json' | ||
|
||
config_path = File.expand_path("../config.json", __FILE__) | ||
if !File.file?(config_path) | ||
abort "Need a config file for this host at " + config_path | ||
end | ||
config = JSON.parse(File.read(config_path)) | ||
|
||
VM_BOX = config['box'] | ||
VM_COUNT = config['count'] | ||
VM_MEMORY = config['memory'] | ||
VM_CPUS = config['cpus'] | ||
VM_PROVISION = File.expand_path(config['provision'], __FILE__) | ||
VM_NAME = config['name'] | ||
SYNC_FOLDER = config['sync_folder'] | ||
|
||
Vagrant.configure("2") do |config| | ||
|
||
(1..VM_COUNT).each do |i| | ||
|
||
config.vm.define "#{VM_NAME}-#{i}" do |node| | ||
node.vm.hostname = "#{VM_NAME}-#{i}" | ||
node.vm.network "private_network", ip: "192.168.56.#{9 + i}" | ||
node.vm.box = VM_BOX | ||
|
||
node.vm.provision "shell" do |s| | ||
ssh_pub_key = File.readlines("#{Dir.home}/.ssh/id_rsa.pub").first.strip | ||
s.inline = <<-SHELL | ||
echo #{ssh_pub_key} >> /home/vagrant/.ssh/authorized_keys | ||
echo #{ssh_pub_key} >> /root/.ssh/authorized_keys | ||
SHELL | ||
end | ||
node.vm.provision "bootstrap", type: "shell", path: VM_PROVISION | ||
node.vm.synced_folder ".", "/vagrant", | ||
rsync__args: ["--verbose", "--archive", "--delete", "-z", "--links"] | ||
node.vm.synced_folder "#{SYNC_FOLDER}", "/synched_folder", | ||
rsync__args: ["--verbose", "--archive", "--delete", "-z", "--links"] | ||
|
||
# https://bugs.launchpad.net/cloud-images/+bug/1874453 | ||
NOW = Time.now.strftime("%d.%m.%Y.%H:%M:%S") | ||
FILENAME = "serial-debug-%s.log" % NOW | ||
node.vm.provider "virtualbox" do |vb| | ||
vb.memory = VM_MEMORY | ||
vb.cpus = VM_CPUS | ||
vb.customize [ "guestproperty", "set", :id, "/VirtualBox/GuestAdd/VBoxService/--timesync-set-threshold", 1000 ] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. regarding time and dns you might need to include this snippet from jenkins-vms that handles darwin/macos |
||
vb.customize [ "modifyvm", :id, "--uart1", "0x3F8", "4" ] | ||
vb.customize [ "modifyvm", :id, "--uartmode1", "file", | ||
File.join(Dir.pwd, FILENAME) ] | ||
end | ||
|
||
node.vm.provider :libvirt do |v, override| | ||
v.memory = VM_MEMORY | ||
v.cpus = VM_CPUS | ||
# Fedora 30+ uses QEMU sessions by default, breaking pretty much all | ||
# previously working Vagrantfiles: | ||
# https://fedoraproject.org/wiki/Changes/Vagrant_2.2_with_QEMU_Session#Upgrade.2Fcompatibility_impact | ||
v.qemu_use_session = false | ||
override.vm.synced_folder "./", "/vagrant", type: :rsync | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. synced folders are also tricky for older distributions like debian-9: here are some workarounds for centos-7 and old debians: |
||
override.vm.synced_folder "#{SYNC_FOLDER}", "/synched_folder", type: :rsync | ||
end | ||
end | ||
end | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.