Last active
April 18, 2018 09:48
-
-
Save v-kolesnikov/20fdfc94e8d7dac75349ab5735b59285 to your computer and use it in GitHub Desktop.
Nomad sandbox
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
# frozen_string_literal: true | |
# -*- mode: ruby -*- | |
# vi: set ft=ruby : | |
script = <<~SCRIPT | |
# Update apt and get dependencies | |
sudo apt-get update | |
sudo DEBIAN_FRONTEND=noninteractive apt-get install -y unzip curl vim \ | |
apt-transport-https \ | |
ca-certificates \ | |
software-properties-common \ | |
bash-completion \ | |
htop \ | |
# Download Nomad | |
NOMAD_VERSION=0.8.1 | |
echo "Fetching Nomad..." | |
cd /tmp/ | |
curl -sSL https://releases.hashicorp.com/nomad/${NOMAD_VERSION}/nomad_${NOMAD_VERSION}_linux_amd64.zip -o nomad.zip | |
echo "Fetching Consul..." | |
curl -sSL https://releases.hashicorp.com/consul/1.0.7/consul_1.0.7_linux_amd64.zip > consul.zip | |
echo "Installing Nomad..." | |
unzip nomad.zip | |
sudo install nomad /usr/bin/nomad | |
sudo mkdir -p /etc/nomad.d | |
sudo chmod a+w /etc/nomad.d | |
# Set hostname's IP to made advertisement Just Work | |
#sudo sed -i -e "s/.*nomad.*/$(ip route get 1 | awk '{print $NF;exit}') nomad/" /etc/hosts | |
echo "Installing Docker..." | |
if [[ -f /etc/apt/sources.list.d/docker.list ]]; then | |
echo "Docker repository already installed; Skipping" | |
else | |
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add - | |
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | |
sudo apt-get update | |
fi | |
sudo DEBIAN_FRONTEND=noninteractive apt-get install -y docker-ce | |
# Restart docker to make sure we get the latest version of the daemon if there is an upgrade | |
sudo service docker restart | |
# Make sure we can actually use docker as the vagrant user | |
sudo usermod -aG docker vagrant | |
sudo curl -s -L https://raw.githubusercontent.com/docker/machine/v0.13.0/contrib/completion/bash/docker-machine.bash -o /etc/bash_completion.d/docker-machine | |
echo "Install Docker Compose..." | |
sudo curl -s -L https://github.com/docker/compose/releases/download/1.21.0/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose | |
sudo chmod +x /usr/local/bin/docker-compose | |
echo "Installing Consul..." | |
unzip /tmp/consul.zip | |
sudo install consul /usr/bin/consul | |
( | |
cat <<-EOF | |
[Unit] | |
Description=consul agent | |
Requires=network-online.target | |
After=network-online.target | |
[Service] | |
Restart=on-failure | |
ExecStart=/usr/bin/consul agent -dev -ui -client=0.0.0.0 | |
ExecReload=/bin/kill -HUP $MAINPID | |
[Install] | |
WantedBy=multi-user.target | |
EOF | |
) | sudo tee /etc/systemd/system/consul.service | |
sudo systemctl enable consul.service | |
sudo systemctl start consul | |
for bin in cfssl cfssl-certinfo cfssljson | |
do | |
echo "Installing $bin..." | |
curl -sSL https://pkg.cfssl.org/R1.2/${bin}_linux-amd64 > /tmp/${bin} | |
sudo install /tmp/${bin} /usr/local/bin/${bin} | |
done | |
echo "Installing autocomplete..." | |
nomad -autocomplete-install | |
SCRIPT | |
Vagrant.configure(2) do |config| | |
config.vm.box = 'bento/ubuntu-16.04' # 16.04 LTS | |
config.vm.hostname = 'nomad' | |
config.vm.provision 'shell', inline: script, privileged: false | |
config.vm.provision 'docker' do |docker| # Just install it | |
docker.run 'registry:2', | |
args: '-p 5000:5000 --restart=always --name registry', | |
daemonize: true | |
end | |
config.ssh.forward_agent = true | |
config.vm.network 'private_network', ip: '192.168.33.10' | |
# Expose the Consul api and ui to the host | |
config.vm.network 'forwarded_port', guest: 8500, host: 8501, | |
auto_correct: true | |
# Expose the Nomad api and ui to the host | |
config.vm.network 'forwarded_port', guest: 4646, host: 4646, | |
auto_correct: true | |
config.vm.synced_folder './', '/vagrant', type: 'nfs' | |
config.vm.provider 'virtualbox' do |vb| | |
vb.memory = '2048' | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment