-
-
Save kyleparisi/44d1900d30a1df82af54 to your computer and use it in GitHub Desktop.
Generic multi-machine Vagrantfile that supports fast and easy way to get testing machines up and running. Provisioning is done through multi-tier shell scripting
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- mode: ruby -*- | |
# vi: set ft=ruby : | |
# Landrush domain name suffix | |
# https://github.com/phinze/landrush | |
# For linux: | |
# sudo apt-get install -y resolvconf dnsmasq | |
# sudo sh -c 'echo "server=/vm/127.0.0.1#10053" > /etc/dnsmasq.d/vagrant-landrush' | |
# sudo service dnsmasq restart | |
# | |
# ensure you run 'vagrant landrush restart' if it's changed | |
TLD = 'vm' | |
# IP number prefix for this set of machines | |
ip_prefix = "10.10.1." | |
# Example node listing | |
# 'name' => [ num_of_vms, starting_ip, domain, size, box, synced_folders ] | |
# 'node' => [1, 110, 'test.vm', 'small, 'generic, [['./www', '/srv/www', 'nfs'], ['./www2', '/srv/www2', 'nfs']] ] | |
nodes = { | |
'node' => [2, 200, "test.#{TLD}", "small", "generic", []], | |
} | |
box_map = { | |
'generic' => ['puphpet/debian75-x64', ">=1.0", "https://vagrantcloud.com/puphpet/boxes/debian75-x64.json"], | |
} | |
box_dimensions = { | |
'small' => { :cpus => 1, :mem => 512 }, | |
'medium' => { :cpus => 2, :mem => 1024 }, | |
'large' => { :cpus => 4, :mem => 2048 }, | |
'large_mem' => { :cpus => 4, :mem => 4096 }, | |
} | |
# Exclude these files from rsync syncing | |
rsync_exclude = ['.git/', '.idea'] | |
# Vagrant SHELL provisioning script | |
# Apply order: generic, node, nodeX | |
$provision_scripts = { | |
'generic' => " | |
sudo apt-get update | |
", | |
'node' => "echo 'Example NODE script'", | |
'node2' => "echo 'Example node2-specific script'" | |
} | |
# Vagrantfile API/syntax version. Don't touch unless you know what you're doing! | |
VAGRANTFILE_API_VERSION = "2" | |
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| | |
config.landrush.enable | |
config.landrush.guest_redirect_dns = false | |
config.landrush.tld = TLD | |
# run generic provision for all instances | |
config.vm.provision "shell", inline: $provision_scripts['generic'] | |
nodes.each do |prefix, (count, ip_start, domain, size, box, synced_folders)| | |
count.times do |i| | |
hostname = "#{prefix}#{i+1}" | |
config.vm.define hostname do |node| | |
box_info = box_map[box] | |
node.vm.box = box_info[0] | |
node.vm.box_version = box_info[1] | |
node.vm.box_url = box_info[2] | |
node.vm.hostname = "#{hostname}.#{domain}" | |
node.vm.network :private_network, ip: "#{ip_prefix}#{ip_start+i}" | |
synced_folders.each do |from, to, sync_type| | |
opts = {type: sync_type} | |
opts[:rsync__exclude] = rsync_exclude if sync_type == 'rsync' | |
config.vm.synced_folder from, to, opts | |
end | |
# Provisioning | |
if $provision_scripts.has_key?(prefix) | |
node.vm.provision "shell", inline: $provision_scripts[prefix] | |
end | |
if $provision_scripts.has_key?(hostname) | |
node.vm.provision "shell", inline: $provision_scripts[hostname] | |
end | |
# Virtualbox specific config | |
node.vm.provider :virtualbox do |v| | |
v.memory = box_dimensions[size][:mem] | |
v.cpus = box_dimensions[size][:cpus] | |
# Probleemid VBox dnsproxyga takistavad rubygems HTTPS liiklust: | |
v.customize ["modifyvm", :id, "--natdnsproxy1", "on"] | |
v.customize ["modifyvm", :id, "--natdnshostresolver1", "off"] | |
end | |
# Parallels specific config | |
node.vm.provider :parallels do |v| | |
v.update_guest_tools = true | |
v.memory = box_dimensions[size][:mem] | |
v.cpus = box_dimensions[size][:cpus] | |
# Enable closing GUI window | |
v.customize ['set', :id, '--on-window-close', 'keep-running'] | |
end | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment