Last active
March 2, 2016 23:16
-
-
Save diasjorge/78a52002f98c118f0968 to your computer and use it in GitHub Desktop.
consul-swarm
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 : | |
# Vagrantfile API/syntax version. Don't touch unless you know what you're doing! | |
VAGRANTFILE_API_VERSION = "2" | |
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| | |
config.vm.box = "phusion/ubuntu-14.04-amd64" | |
if Vagrant.has_plugin?("vagrant-cachier") | |
config.cache.scope = :machine | |
end | |
(1..3).each do |id| | |
config.vm.define "master_#{id}" do |node| | |
node.vm.hostname = "master-#{id}" | |
ip = "172.20.20.#{10 + id}" | |
node.vm.network "private_network", ip: ip | |
node.vm.provision :shell, inline: "echo DOCKER_OPTS=\\\"-H tcp://#{ip}:2375 -H tcp://127.0.0.1:2375 -H unix:///var/run/docker.sock\\\" > /etc/default/docker" | |
node.vm.provision :docker, images: ["progrium/consul", "swarm", "gliderlabs/registrator"] do |d| | |
consul_args = <<CMD.strip | |
--restart always \ | |
-h $HOSTNAME -v /mnt:/data/consul \ | |
-p #{ip}:8300:8300 \ | |
-p #{ip}:8301:8301 \ | |
-p #{ip}:8301:8301/udp \ | |
-p #{ip}:8302:8302 \ | |
-p #{ip}:8302:8302/udp \ | |
-p #{ip}:8400:8400 \ | |
-p #{ip}:8500:8500 \ | |
-p 172.17.42.1:53:53/udp | |
CMD | |
if id == 1 | |
consul_cmd = "-server -advertise #{ip} -bootstrap-expect 3" | |
else | |
consul_cmd = "-server -advertise #{ip} -join 172.20.20.11" | |
end | |
d.run "progrium/consul", args: consul_args, cmd: consul_cmd | |
d.run "gliderlabs/registrator", args: "--restart always --dns 172.17.42.1 -v /var/run/docker.sock:/tmp/docker.sock -h $HOSTNAME", cmd: "consul://consul.service.consul:8500" | |
d.run "swarm", args: "--restart always --dns 172.17.42.1", cmd: "join --addr=#{ip}:2375 consul://consul.service.consul:8500/swarm" | |
if id == 1 | |
d.run "swarm-manager", image: "swarm", args: "--restart always --dns 172.17.42.1 -p 12375:2375", cmd: "manage consul://consul.service.consul:8500/swarm" | |
end | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment