/
Vagrantfile
101 lines (85 loc) · 3.26 KB
/
Vagrantfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure("2") do |config|
config.vm.box = "ubuntu/focal64"
# Expose ports to the host.
config.vm.network "forwarded_port", guest: 4646, host: 4646, host_ip: "127.0.0.1" # Nomad HTTP API/UI
config.vm.network "forwarded_port", guest: 8500, host: 8500, host_ip: "127.0.0.1" # Consul HTTP API/UI
config.vm.network "forwarded_port", guest: 9090, host: 9090, host_ip: "127.0.0.1" # Prometheus HTTP API/UI
# Share current directory with jobs and configuration files with the VM. Add
# the shared files in a sub-dir.
config.vm.synced_folder "./", "/home/vagrant/nomad-autoscaler"
config.vm.synced_folder "../shared", "/home/vagrant/nomad-autoscaler-shared"
# VM configuration.
config.vm.provider "virtualbox" do |vb|
vb.customize [ "modifyvm", :id, "--uartmode1", "file", File::NULL ]
vb.memory = "2048"
vb.cpus = 2
end
# Provision demo dependencies.
# - Downloads and install Nomad, Consul and Docker
# Only runs when the VM is created.
config.vm.provision "deps", type: "shell", inline: <<-SHELL
mkdir /tmp/downloads
# Install dependencies.
apt-get update
apt-get install -y \
apt-transport-https \
ca-certificates \
curl \
gnupg-agent \
jq \
redis-server \
software-properties-common \
zip
nomad_version=1.0.3+ent
consul_version=$(curl -s https://checkpoint-api.hashicorp.com/v1/check/consul | jq -r '.current_version')
# Download and install Docker.
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
add-apt-repository \
"deb [arch=amd64] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) \
stable"
apt-get update
apt-get install -y \
docker-ce \
docker-ce-cli \
containerd.io
docker run hello-world
usermod -aG docker vagrant
# Create the HashiCorp binary destination.
mkdir -p /opt/hashicorp/bin
# Download and install Nomad and Consul.
pushd /tmp/downloads
curl --silent --show-error --remote-name-all \
https://releases.hashicorp.com/nomad/${nomad_version}/nomad_${nomad_version}_linux_amd64.zip \
https://releases.hashicorp.com/consul/${consul_version}/consul_${consul_version}_linux_amd64.zip
unzip nomad_${nomad_version}_linux_amd64.zip
unzip consul_${consul_version}_linux_amd64.zip
mv nomad consul /opt/hashicorp/bin
chmod +x /opt/hashicorp/bin/{nomad,consul}
ln -s /opt/hashicorp/bin/{nomad,consul} /usr/local/bin
popd
rm -fr /tmp/downloads
SHELL
# Setup demo dependencies.
# - Create daemons for Nomad and Consul
# Runs everytime the VM starts.
config.vm.provision "app:setup", type: "shell", run: "always", inline: <<-SHELL
# Configure the Nomad and Consul daemons.
pushd /home/vagrant/nomad-autoscaler-shared
for t in consul nomad; do
cp ${t}.service /etc/systemd/system/
mkdir -p /etc/${t}.d
done
popd
# Copy across the config files.
cp /home/vagrant/nomad-autoscaler-shared/consul.hcl /etc/consul.d/
cp /home/vagrant/nomad-autoscaler/files/nomad.hcl /etc/nomad.d/
# Enable and start the daemons
systemctl enable consul
systemctl start consul
sudo systemctl enable nomad
sudo systemctl start nomad
SHELL
end