Skip to content

Instantly share code, notes, and snippets.

@dliappis
Created November 29, 2017 13:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dliappis/13005bc90c8487129a06e2552bcdb7da to your computer and use it in GitHub Desktop.
Save dliappis/13005bc90c8487129a06e2552bcdb7da to your computer and use it in GitHub Desktop.
Vagrantfile for testing Docker issues
# -*- mode: ruby -*-
# vi: set ft=ruby :
require "ipaddr"
boxname = "elastic/ubuntu-16.04-x86_64"
base_ip = "192.168.124.101"
domain_name = "example.com"
default_cpu = 2
default_ram = 6144
default_nodes = 1
nodes = []
for i in 1..default_nodes
nodes += [{ hostname: "m%02d" % [i], domain: domain_name, autostart: true }]
end
$install_docker_script = <<EOF
# Install and configure Docker
groups vagrant | grep -q docker >/dev/null 2>&1 || ( \
apt-get clean && \
rm -rf /var/lib/apt/lists/* && \
apt-get update && \
apt-get install -y apt-transport-https ca-certificates curl software-properties-common && \
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | 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 && \
usermod -aG docker vagrant \
)
# Use overlay2 storage driver due to https://bugs.launchpad.net/ubuntu/+source/aufs-tools/+bug/1442892
CURRENT_DOCKER_STORAGE_DRIVER=$( docker info -f "{{ json .Driver}}" | sed 's/\"//g' )
if [[ $CURRENT_DOCKER_STORAGE_DRIVER == "aufs" ]]; then
systemctl stop docker
echo '{"storage-driver": "overlay2"}' >/etc/docker/daemon.json
systemctl start docker
fi
# Install Docker Compose
docker-compose --version >/dev/null 2>&1 || ( \
apt-get install -y python-pip python3 python3-pip && \
pip install --upgrade pip && \
pip install docker-compose virtualenv && \
pip3 install virtualenv \
)
# Tweak sysctl so ES will start.
grep -q '^vm.max_map_count=' /etc/sysctl.conf || ( \
echo 'vm.max_map_count=262144' >> /etc/sysctl.conf && \
sysctl --load
)
EOF
Vagrant.configure("2") do |config|
ip_address = IPAddr.new base_ip
config.vm.provision 'shell', inline: <<-EOF
apt-get clean
rm -rf /var/lib/apt/lists/*
EOF
nodes.each do |node|
fqdn = node[:hostname] + '.' + node[:domain]
config.vm.define node[:hostname], autostart: (node[:autostart] || false) do |node_config|
node_config.vm.box = node[:box] || boxname
node_config.vm.hostname = fqdn
node_config.ssh.forward_agent = true
node_config.vm.network :private_network, ip: ip_address.to_s
node_config.vm.provider :virtualbox do |virtualbox, override|
virtualbox.name = fqdn
virtualbox.memory = node[:memory] || default_ram
virtualbox.cpus = node[:cpu] || default_cpu
override.vm.synced_folder "./","/vagrant"
end
config.vm.provision "shell", inline: $install_docker_script
# Increment to ip_address+1
ip_address = ip_address.succ
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment