This simplifies the stand-up of a sandbox:

Only 2 main Vagrant calls are now needed (`vagrant up` and `vagrant up machine1`).
This PR only updates the Vagrant Virtualbox setup. The Vagrant Libvirt and Terraform
still need to be updated.

This uses docker-compose as the entry point for standing up the stack and makes the stand-up
of the sandbox more portal. Vagrant and Terraform are only responsible for standing up infrastructure
and then running docker-compose, not for running any glue scripts.

The docker-compose calls out to single-shot services to do all the glue required to get the fully
functional Tinkerbell stack up and running. All the single-shot services are idempotent.
This increases portability and the development iteration loop. This also simplifies the required
steps needed to get a fully functioning sandbox up and running.

This is intended to help people looking to get started by getting them to a provisioned
machine quicker and more easily.

Signed-off-by: Jacob Weinstock <jakobweinstock@gmail.com>
This commit is contained in:
Jacob Weinstock
2021-08-09 08:04:06 -06:00
parent 1ebcf482de
commit 6b841fee7c
58 changed files with 1862 additions and 1020 deletions

View File

@ -1,109 +1,43 @@
ENV['VAGRANT_NO_PARALLEL'] = 'yes'
# -*- mode: ruby -*-
# vi: set ft=ruby :
num_workers = ENV['TINKERBELL_NUM_WORKERS'] || '1'
PROVISIONER_IP = "192.168.50.4"
MACHINE1_IP = "192.168.50.43"
# Returns true if `GUI` environment variable exists, value does not matter.
# Defaults to false
def worker_gui_enabled?
ENV.include?('VAGRANT_WORKER_GUI')
unless Vagrant.has_plugin?("vagrant-docker-compose")
system("vagrant plugin install vagrant-docker-compose")
puts "Dependencies installed, please try the command again."
exit
end
# Returns true if `SCALE` environment variable exists, value does not matter.
# Defaults to false
def worker_display_scale_enabled?
ENV.include?('VAGRANT_WORKER_SCALE')
end
def configure_nat
return ENV.has_key?('TINKERBELL_CONFIGURE_NAT') ? ENV['TINKERBELL_CONFIGURE_NAT'] : 'true'
end
def libvirt_forward_mode
return configure_nat == 'false' ? 'nat' : 'none'
end
Vagrant.configure('2') do |config|
config.vm.define :provisioner do |provisioner|
provisioner.vm.box = "tinkerbelloss/sandbox-ubuntu1804"
provisioner.vm.box_version = "0.2.0"
provisioner.vm.hostname = 'provisioner'
provisioner.vm.synced_folder './../../', '/vagrant'
provisioner.vm.provision :shell,
path: './scripts/tinkerbell.sh',
env: {
'TINKERBELL_CONFIGURE_NAT': configure_nat,
}
provisioner.vm.network :private_network,
virtualbox__intnet: "tink_network",
libvirt__network_name: "tink_network",
libvirt__host_ip: "192.168.1.6",
libvirt__netmask: "255.255.255.248",
libvirt__dhcp_enabled: false,
libvirt__forward_mode: libvirt_forward_mode,
libvirt__adapter: 1,
auto_config: false
provisioner.vm.network "forwarded_port", guest: 42113, host: 42113
provisioner.vm.network "forwarded_port", guest: 42114, host: 42114
provisioner.vm.provider :libvirt do |lv, override|
lv.memory = 2*1024
lv.cpus = 2
lv.cpu_mode = 'host-passthrough'
Vagrant.configure("2") do |config|
config.vm.define "provisioner" do |provisioner|
provisioner.vm.box = "generic/ubuntu2004"
provisioner.vm.synced_folder '../', '/vagrant'
provisioner.vm.provider "virtualbox" do |v|
v.memory = 2048
v.cpus = 2
end
provisioner.vm.network "private_network", ip: PROVISIONER_IP
provisioner.vm.provider :virtualbox do |vb, override|
vb.memory = 2*1024
vb.cpus = 2
end
provisioner.vm.provision :docker
# vagrant plugin install vagrant-docker-compose
provisioner.vm.provision :docker_compose, compose_version: "1.29.1", yml: "/vagrant/docker-compose.yml", run:"always", env: {"TINKERBELL_HOST_IP": PROVISIONER_IP, "TINKERBELL_CLIENT_IP": MACHINE1_IP, "REPO_TOP_LEVEL": "/vagrant"}
end
(1..num_workers.to_i).each do |i|
mac_suffix = "%02x" % i
worker_suffix = i==1 ? "" : "i"
config.vm.define "worker#{worker_suffix}" do |worker|
worker.vm.box = nil
worker.vm.network :private_network,
mac: "0800270000#{mac_suffix}",
virtualbox__intnet: "tink_network",
libvirt__network_name: "tink_network",
libvirt__dhcp_enabled: false,
libvirt__forward_mode: libvirt_forward_mode,
auto_config: false
worker.vm.provider :libvirt do |lv|
lv.memory = 4*1024
lv.cpus = 1
lv.boot 'network'
lv.mgmt_attach = false
lv.storage :file, :size => '40G'
lv.random :model => 'random'
end
worker.vm.provider :virtualbox do |vb, worker|
worker.vm.box = 'generic/alpine38'
vb.memory = 4*1024
vb.cpus = 1
vb.gui = worker_gui_enabled?
vb.customize [
'setextradata', :id,
'GUI/ScaleFactor', '3.0'
] if worker_display_scale_enabled?
vb.customize [
'modifyvm', :id,
'--nic1', 'none',
'--boot1', 'net',
'--boot2', 'none',
'--boot3', 'none',
'--boot4', 'none',
'--macaddress1', "0800270000#{mac_suffix}"
]
end
config.vm.define :machine1, autostart: false do |machine1|
machine1.vm.box = 'jtyr/pxe'
machine1.vm.provider "virtualbox" do |v|
v.memory = 2048
v.cpus = 2
v.gui = true
v.customize ['modifyvm', :id, '--nic1', 'hostonly', '--nic2', 'nat', '--boot1', 'disk', '--boot2', 'net']
v.customize ['setextradata', :id, 'GUI/ScaleFactor', '3.0']
v.check_guest_additions = false
end
machine1.ssh.insert_key = false
machine1.vm.boot_timeout = 10
machine1.vm.synced_folder '.', '/vagrant', disabled: true
machine1.vm.network "private_network", ip: MACHINE1_IP, mac: "0800279EF53A", adapter: 1
end
end