k3s/Vagrantfile

56 lines
1.8 KiB
Ruby
Raw Normal View History

DISTRO = (ENV['DISTRO'] || "alpine312")
BOX_REPO = (ENV['BOX_REPO'] || "generic")
2020-07-10 22:36:46 +00:00
HOME = ENV['HOME']
PROJ_HOME = File.dirname(__FILE__)
PROJECT = File.basename(PROJ_HOME)
2019-04-21 18:43:04 +00:00
NUM_NODES = (ENV['NUM_NODES'] || 0).to_i
NODE_CPUS = (ENV['NODE_CPUS'] || 4).to_i
2020-07-10 22:36:46 +00:00
NODE_MEMORY = (ENV['NODE_MEMORY'] || 8192).to_i
2019-04-21 18:43:04 +00:00
NETWORK_PREFIX = ENV['NETWORK_PREFIX'] || "10.135.135"
VAGRANT_PROVISION = ENV['VAGRANT_PROVISION'] || "./scripts/provision/vagrant"
2021-02-09 01:03:11 +00:00
MOUNT_TYPE = ENV['MOUNT_TYPE'] || "virtualbox"
2019-04-21 18:43:04 +00:00
# --- Rules for /etc/sudoers to avoid password entry configuring NFS:
# %admin ALL = (root) NOPASSWD: /usr/bin/sed -E -e * -ibak /etc/exports
# %admin ALL = (root) NOPASSWD: /usr/bin/tee -a /etc/exports
# %admin ALL = (root) NOPASSWD: /sbin/nfsd restart
# --- May need to add terminal to System Preferences -> Security & Privacy -> Privacy -> Full Disk Access
2020-03-02 16:38:07 +00:00
def provision(vm, node_num)
node_os = (ENV["DISTRO_#{node_num}"] || DISTRO)
2020-03-02 16:38:07 +00:00
vm.box = (ENV["BOX_#{node_num}"] || ENV["BOX"] || "#{BOX_REPO}/#{node_os}")
2021-02-09 01:03:11 +00:00
vm.hostname = "#{PROJECT}-#{node_num}-#{vm.box.gsub(/^.*\//,"")}"
2020-03-02 16:38:07 +00:00
vm.network "private_network", ip: "#{NETWORK_PREFIX}.#{100+node_num}"
vm.provision "shell",
path: VAGRANT_PROVISION,
2020-07-10 22:36:46 +00:00
env: { 'HOME' => PROJ_HOME, 'GOPATH' => ENV['GOPATH'], 'BOX' => vm.box }
2019-04-21 18:43:04 +00:00
end
Vagrant.configure("2") do |config|
2019-04-21 18:43:04 +00:00
config.vm.provider "virtualbox" do |v|
v.cpus = NODE_CPUS
v.memory = NODE_MEMORY
v.customize ["modifyvm", :id, "--audio", "none"]
end
config.vm.provider "libvirt" do |v|
v.cpus = NODE_CPUS
v.memory = NODE_MEMORY
end
if Vagrant.has_plugin?("vagrant-timezone")
config.timezone.value = :host
end
2020-07-10 22:36:46 +00:00
config.vm.synced_folder HOME, HOME, type: MOUNT_TYPE
2019-04-21 18:43:04 +00:00
if NUM_NODES==0
2020-03-02 16:38:07 +00:00
provision(config.vm, 0)
else
(1..NUM_NODES).each do |i|
config.vm.define ".#{i}" do |node|
2020-03-02 16:38:07 +00:00
provision(node.vm, i)
end
2019-04-21 18:43:04 +00:00
end
end
2019-04-21 18:43:04 +00:00
end