Skip to content

Commit

Permalink
Merge pull request #165 from gauravgahlot/vagrant
Browse files Browse the repository at this point in the history
Setup tinkerbell stack locally using Vagrant
  • Loading branch information
grahamc authored Jun 17, 2020
2 parents c32858a + eae335b commit db1c9c2
Show file tree
Hide file tree
Showing 4 changed files with 165 additions and 1 deletion.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,6 @@ cmd/tink-worker/tink-worker
.terraform
terraform.tfstate
terraform.tfstate.backup

# Vagrant
**/.vagrant
61 changes: 61 additions & 0 deletions deploy/vagrant/Vagrantfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
ENV['VAGRANT_NO_PARALLEL'] = 'yes'

Vagrant.configure('2') do |config|

config.vm.define :provisioner do |provisioner|
provisioner.vm.box = 'generic/ubuntu1804'
provisioner.vm.hostname = 'provisioner'
provisioner.vm.synced_folder './../../', '/vagrant'
provisioner.vm.provision :shell, path: './scripts/tinkerbell.sh'

provisioner.vm.network :private_network,
virtualbox__intnet: "tink_network",
libvirt__dhcp_enabled: false,
libvirt__forward_mode: 'none',
auto_config: false

provisioner.vm.provider :libvirt do |lv, override|
lv.memory = 2*1024
lv.cpus = 2
lv.cpu_mode = 'host-passthrough'
end

provisioner.vm.provider :virtualbox do |vb, override|
vb.memory = 2*1024
vb.cpus = 2
end
end

config.vm.define "worker" do |worker|
worker.vm.box = nil
worker.vm.network :private_network,
mac: "080027000001",
virtualbox__intnet: "tink_network",
libvirt__dhcp_enabled: false,
libvirt__forward_mode: 'none',
auto_config: false

worker.vm.provider :libvirt do |lv|
lv.memory = 1*1024
lv.cpus = 1
lv.boot 'network'
lv.mgmt_attach = false
end

worker.vm.provider :virtualbox do |vb, worker|
worker.vm.box = 'generic/alpine38'
vb.memory = 1*1024
vb.cpus = 1
vb.gui = true
vb.customize [
'modifyvm', :id,
'--nic1', 'none',
'--boot1', 'net',
'--boot2', 'none',
'--boot3', 'none',
'--boot4', 'none',
'--macaddress1', '080027000001'
]
end
end
end
100 changes: 100 additions & 0 deletions deploy/vagrant/scripts/tinkerbell.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
#!/bin/bash

# abort this script on errors
set -euxo pipefail

whoami

cd /vagrant

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 docker-ce docker-ce-cli containerd.io
)

setup_docker_compose() (
# from https://docs.docker.com/compose/install/
sudo curl -L \
"https://github.com/docker/compose/releases/download/1.26.0/docker-compose-$(uname -s)-$(uname -m)" \
-o /usr/local/bin/docker-compose

sudo chmod +x /usr/local/bin/docker-compose
)

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"
)

command_exists() (
command -v "$@" >/dev/null 2>&1
)

configure_vagrant_user() (
sudo usermod -aG docker vagrant

echo -n "$TINKERBELL_REGISTRY_PASSWORD" |
sudo -iu vagrant docker login \
--username="$TINKERBELL_REGISTRY_USERNAME" \
--password-stdin "$TINKERBELL_HOST_IP"
)

main() (
export DEBIAN_FRONTEND=noninteractive

apt-get update

if ! command_exists docker; then
setup_docker
fi

if ! command_exists docker-compose; then
setup_docker_compose
fi

if ! command_exists jq; then
sudo apt-get install -y jq
fi

if [ ! -f ./envrc ]; then
./generate-envrc.sh eth1 >envrc
fi

# shellcheck disable=SC1091
. ./envrc

make_certs_writable

./setup.sh

secure_certs

configure_vagrant_user

)

main
2 changes: 1 addition & 1 deletion setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ setup_osie() (

local osie_current=$STATEDIR/webroot/misc/osie/current
local tink_workflow=$STATEDIR/webroot/workflow/
if [ ! -d "$osie_current" ] && [ ! -d "$tink_workflow" ]; then
if [ ! -d "$osie_current" ] || [ ! -d "$tink_workflow" ]; then
mkdir -p "$osie_current"
mkdir -p "$tink_workflow"
pushd "$SCRATCH"
Expand Down

0 comments on commit db1c9c2

Please sign in to comment.