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 +0,0 @@
.vagrant

View File

@ -1 +0,0 @@
https://tinkerbell.org/docs/setup/local-with-vagrant/

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

View File

@ -1 +0,0 @@
output*

View File

@ -1,30 +0,0 @@
This directory contains a provisioning mechanism for the Vagrant boxes we ship
as part of Sandbox.
In order to self contain and distribute the required dependencies for Tinkerbell
and Sandbox without having to download all of them at runtime we decided to use
[Packer.io](https://packer.io) to build boxes that you can use when provisioning
Tinkerbell on Vagrant.
Currently the generated boxes are available via [Vagrant
Cloud](https://app.vagrantup.com/tinkerbelloss).
---
## Build
To build the boxes checkout the right directory and run
```terminal
$ packer build --parallel-builds=1 ./template.json
```
`-parallel-builds=1` is required because the template builds images for multiple
providers using the [Vagrant
builder](https://www.packer.io/docs/builders/vagrant) and I didn't manage to get
it to work in parallel yet.
## Deploy to Vagrant Cloud
I didn't find a way to make the Vagrant Cloud post processor to work. But I use
the vagrant cli `vagrant cloud publish` command.

View File

@ -1,57 +0,0 @@
#!/bin/bash
# abort this script on errors
set -euxo pipefail
setup_docker() (
# steps from https://docs.docker.com/engine/install/ubuntu/
sudo apt-get install -y \
apt-transport-https \
ca-certificates \
curl \
gnupg-agent \
software-properties-common \
;
curl -fsSL https://download.docker.com/linux/ubuntu/gpg |
sudo apt-key add -
local repo
repo=$(
printf "deb [arch=amd64] https://download.docker.com/linux/ubuntu %s stable" \
"$(lsb_release -cs)"
)
sudo add-apt-repository "$repo"
sudo apt-get update
sudo apt-get install -y \
containerd.io \
docker-ce \
docker-ce-cli \
;
)
# from https://docs.docker.com/compose/install/
setup_docker_compose() (
local name url
name=docker-compose-$(uname -s)-$(uname -m)
url=https://github.com/docker/compose/releases/download/1.26.0/$name
curl -fsSLO "$url"
curl -fsSLO "$url.sha256"
sha256sum -c <"$name.sha256"
rm -f "$name.sha256"
chmod +x "$name"
sudo mv "$name" /usr/local/bin/docker-compose
)
main() (
export DEBIAN_FRONTEND=noninteractive
sudo apt-get update
setup_docker
setup_docker_compose
sudo apt-get install -y jq
sudo usermod -aG docker vagrant
)
main
sync # do not remove!

View File

@ -1,27 +0,0 @@
{
"builders": [
{
"communicator": "ssh",
"name": "vagrant-virtualbox",
"provider": "virtualbox",
"source_path": "generic/ubuntu1804",
"type": "vagrant"
},
{
"communicator": "ssh",
"name": "vagrant-libvirt",
"provider": "libvirt",
"source_path": "generic/ubuntu1804",
"type": "vagrant"
}
],
"provisioners": [
{
"script": "provision.sh",
"type": "shell"
}
],
"variables": {
"cloud_token": "{{ env `VAGRANT_CLOUD_TOKEN` }}"
}
}

View File

@ -1,59 +0,0 @@
#!/bin/bash
# abort this script on errors
set -euxo pipefail
whoami
cd /vagrant
make_certs_writable() (
local certdir="/etc/docker/certs.d/$TINKERBELL_HOST_IP"
sudo mkdir -p "$certdir"
sudo chown -R "$USER" "$certdir"
)
secure_certs() (
local certdir="/etc/docker/certs.d/$TINKERBELL_HOST_IP"
sudo chown "root" "$certdir"
)
configure_vagrant_user() (
echo -n "$TINKERBELL_REGISTRY_PASSWORD" |
sudo -iu vagrant docker login \
--username="$TINKERBELL_REGISTRY_USERNAME" \
--password-stdin "$TINKERBELL_HOST_IP"
)
setup_nat() (
iptables -A FORWARD -i eth1 -o eth0 -j ACCEPT
iptables -A FORWARD -i eth0 -o eth1 -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
)
main() (
export DEBIAN_FRONTEND=noninteractive
if ! [[ -f ./.env ]]; then
./generate-env.sh eth1 >.env
fi
# shellcheck disable=SC1091
source ./.env
make_certs_writable
./setup.sh
if [[ ${TINKERBELL_CONFIGURE_NAT:=true} != "false" ]]; then
setup_nat
fi
secure_certs
configure_vagrant_user
set +x # don't want the stderr output from xtrace messing with the post-setup-message
[[ -f /tmp/post-setup-message ]] && cat /tmp/post-setup-message
)
main