Last active
June 23, 2022 14:16
-
-
Save joshuacox/7f9e45f6741a1ca18e059116650734f4 to your computer and use it in GitHub Desktop.
NomadConsulWaypointVagrantfile
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- mode: ruby -*- | |
# vi: set ft=ruby : | |
Vagrant.configure("2") do |config| | |
config.vm.box = "generic/ubuntu2004" | |
config.vm.provision "shell", inline: <<-SHELL | |
#!/bin/bash | |
: ${NOMAD_VERSION:=1.3.1} | |
: ${WAYPOINT_VERSION:=0.8.2} | |
: ${CONSUL_VERSION:=1.12.2} | |
set -ux | |
sudo apt-get update | |
sudo apt-get -yqq install ca-certificates curl gnupg lsb-release | |
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg | |
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null | |
sudo apt-get update | |
sudo apt-get install -yqq docker-ce docker-ce-cli containerd.io docker-compose-plugin | |
cd | |
echo 'export PATH=$HOME/bin:$PATH' >> .bashrc | |
git clone --depth=1 https://github.com/hashicorp/waypoint-examples.git | |
mkdir bin | |
cd bin | |
curl https://releases.hashicorp.com/nomad/${NOMAD_VERSION}/nomad_${NOMAD_VERSION}_linux_amd64.zip -o nomad_${NOMAD_VERSION}_linux_amd64.zip | |
unzip nomad_${NOMAD_VERSION}_linux_amd64.zip | |
rm -v nomad_${NOMAD_VERSION}_linux_amd64.zip | |
chmod +x nomad | |
curl https://releases.hashicorp.com/waypoint/${WAYPOINT_VERSION}/waypoint_${WAYPOINT_VERSION}_linux_amd64.zip -o waypoint_${WAYPOINT_VERSION}_linux_amd64.zip | |
unzip waypoint_${WAYPOINT_VERSION}_linux_amd64.zip | |
rm -v waypoint_${WAYPOINT_VERSION}_linux_amd64.zip | |
chmod +x waypoint | |
curl https://releases.hashicorp.com/consul/${CONSUL_VERSION}/consul_${CONSUL_VERSION}_linux_amd64.zip -o consul_${CONSUL_VERSION}_linux_amd64.zip | |
unzip consul_${CONSUL_VERSION}_linux_amd64.zip | |
rm -v consul_${CONSUL_VERSION}_linux_amd64.zip | |
chmod +x consul | |
ls -alh | |
cd | |
mkdir -p /data/waypoint-server | |
chown 100 /data/waypoint-server | |
echo 'client { host_volume "waypoint-server" { path = "/data/waypoint-server", read_only = false }}'>nomad.config | |
echo 'IFACE=eth0 | |
echo -n 'starting consul...' | |
consul agent -dev 1> /tmp/consul.log 2>/tmp/consul.err & | |
consul_up=1 | |
while [[ ! $consul_up == 0 ]] | |
do | |
echo -n '.' | |
curl -s http://127.0.0.1:8500/v1/agent/services &>/dev/null | |
consul_up=$? | |
sleep 1 | |
done | |
echo '.' | |
echo 'consul is up' | |
sleep 1 | |
nomad agent -dev -network-interface=$IFACE -config=nomad.config 1>/tmp/nomad.stdout 2>/tmp/nomad.stderr & | |
THIS_RESULT=1 | |
THIS_COUNT=0 | |
echo -n "Awaiting nomad to start." | |
until [[ $THIS_RESULT == 0 ]]; | |
do | |
nomad status &> /dev/null | |
THIS_RESULT=$? | |
sleep 2 | |
((++THIS_COUNT)) | |
done | |
echo "# $THIS_COUNT" | |
time waypoint install -platform=nomad -accept-tos -nomad-host-volume=waypoint-server -nomad-consul-service=false | |
cd ~/waypoint-examples/nomad/nodejs | |
waypoint init | |
waypoint up' > start.sh | |
chmod +x start.sh | |
SHELL | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment