Skip to content

Commit 2e78fc3

Browse files
committed
vagrant: Move all provisioner code into just one script
This just seems easier to manage one script instead of many ruby blocks. Bonus points for having it look similar to terraform/setup.sh so common things look the same(ish). Signed-off-by: Manuel Mendez <[email protected]>
1 parent ec27082 commit 2e78fc3

File tree

2 files changed

+65
-39
lines changed

2 files changed

+65
-39
lines changed

deploy/vagrant/Vagrantfile

Lines changed: 2 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -37,46 +37,9 @@ Vagrant.configure("2") do |config|
3737
override.vm.synced_folder "../compose/", "/vagrant/compose/", type: "rsync"
3838
end
3939

40-
provisioner.vm.provision "shell", name: "Setup interactive goodies", inline: <<-SCRIPT.gsub(/^ {6}/, "")
41-
set -x
42-
grep -q 'cd /vagrant/compose' ~vagrant/.bashrc || echo 'cd /vagrant/compose' >>~vagrant/.bashrc
43-
read -r -d '' aliases <<-'EOF'
44-
dc=docker-compose
45-
EOF
46-
while read -r alias; do
47-
grep -q "$alias" ~vagrant/.bash_aliases || echo alias "$alias" >>~vagrant/.bash_aliases
48-
done <<<"$aliases"
49-
SCRIPT
50-
51-
provisioner.vm.provision "file", source: "tink", destination: "~/.local/bin/tink"
52-
53-
provisioner.vm.provision "shell", name: "Setup eth1", inline: <<-SCRIPT.gsub(/^ {6}/, "")
54-
set -x
55-
ip addr show dev eth1 | grep -q #{PROVISIONER_IP} && exit 0
56-
ip addr add #{PROVISIONER_IP}/24 dev eth1
57-
ip link set dev eth1 up
58-
SCRIPT
59-
60-
provisioner.vm.provision "shell", name: "Setup provider specific overrides", inline: <<-SCRIPT.gsub(/^ {6}/, "")
61-
set -x
62-
if lsblk | grep -q vda; then
63-
sed -i 's|sda|vda|g' /vagrant/compose/create-tink-records/manifests/template/ubuntu.yaml
64-
fi
65-
read -r -d '' lines <<-'EOF'
66-
TINKERBELL_HOST_IP=#{PROVISIONER_IP}
67-
TINKERBELL_CLIENT_IP=#{MACHINE1_IP}
68-
EOF
69-
while read -r line; do
70-
grep -q "$line" /vagrant/compose/.env && continue
71-
echo "$line" >>/vagrant/compose/.env
72-
done <<<"$lines"
73-
SCRIPT
74-
7540
provisioner.vm.provision :docker
76-
provisioner.vm.provision :docker_compose,
77-
compose_version: "1.29.2",
78-
yml: "/vagrant/compose/docker-compose.yml",
79-
run: "always"
41+
provisioner.vm.provision :docker_compose, compose_version: "1.29.2"
42+
provisioner.vm.provision :shell, path: "setup.sh", args: [PROVISIONER_IP, MACHINE1_IP]
8043
end
8144

8245
config.vm.define :machine1, autostart: false do |machine1|

deploy/vagrant/setup.sh

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
#!/usr/bin/env bash
2+
3+
setup_layer2_network() {
4+
host_addr=$1
5+
ip addr show dev eth1 | grep -q "$host_addr" && return 0
6+
ip addr add "$host_addr/24" dev eth1
7+
ip link set dev eth1 up
8+
}
9+
10+
setup_compose_env_overrides() {
11+
local host_addr=$1
12+
local worker_addr=$2
13+
if lsblk | grep -q vda; then
14+
sed -i 's|sda|vda|g' /vagrant/compose/create-tink-records/manifests/template/ubuntu.yaml
15+
fi
16+
readarray lines <<-EOF
17+
TINKERBELL_HOST_IP="$host_addr"
18+
TINKERBELL_CLIENT_IP="$worker_addr"
19+
EOF
20+
for line in "${lines[@]}"; do
21+
grep -q "$line" /vagrant/compose/.env && continue
22+
echo "$line" >>/vagrant/compose/.env
23+
done
24+
}
25+
26+
create_tink_helper_script() {
27+
mkdir -p ~vagrant/.local/bin
28+
cat >~vagrant/.local/bin/tink <<-'EOF'
29+
#!/usr/bin/env bash
30+
31+
exec docker-compose -f /vagrant/compose/docker-compose.yml exec tink-cli tink "$@"
32+
EOF
33+
chmod +x ~vagrant/.local/bin/tink
34+
}
35+
36+
tweak_bash_interactive_settings() {
37+
grep -q 'cd /vagrant/compose' ~vagrant/.bashrc || echo 'cd /vagrant/compose' >>~vagrant/.bashrc
38+
readarray aliases <<-EOF
39+
dc=docker-compose
40+
EOF
41+
for alias in "${aliases[@]}"; do
42+
grep -q "$alias" ~vagrant/.bash_aliases || echo "alias $alias" >>~vagrant/.bash_aliases
43+
done
44+
}
45+
46+
main() {
47+
local host_addr=$1
48+
local worker_addr=$2
49+
50+
setup_layer2_network "$host_addr"
51+
52+
setup_compose_env_overrides "$host_addr" "$worker_addr"
53+
docker-compose -f /vagrant/compose/docker-compose.yml up -d
54+
55+
create_tink_helper_script
56+
tweak_bash_interactive_settings
57+
}
58+
59+
if [[ ${BASH_SOURCE[0]} == "$0" ]]; then
60+
set -euxo pipefail
61+
62+
main "$@"
63+
fi

0 commit comments

Comments
 (0)