Vagrantfile 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. # -*- mode: ruby -*-
  2. # vi: set ft=ruby :
  3. # Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
  4. VAGRANTFILE_API_VERSION = "2"
  5. $consul=<<SCRIPT
  6. apt-get update
  7. apt-get -y install wget
  8. wget -qO- https://experimental.docker.com/ | sh
  9. gpasswd -a vagrant docker
  10. service docker restart
  11. docker run -d -p 8500:8500 -p 8300-8302:8300-8302/tcp -p 8300-8302:8300-8302/udp -h consul progrium/consul -server -bootstrap
  12. SCRIPT
  13. $bootstrap=<<SCRIPT
  14. apt-get update
  15. apt-get -y install wget curl
  16. apt-get -y install bridge-utils
  17. wget -qO- https://experimental.docker.com/ | sh
  18. gpasswd -a vagrant docker
  19. echo DOCKER_OPTS=\\"--cluster-store=consul://192.168.33.10:8500 --cluster-advertise=${1}:0\\" >> /etc/default/docker
  20. cp /vagrant/docs/vagrant-systemd/docker.service /etc/systemd/system/
  21. systemctl daemon-reload
  22. systemctl restart docker.service
  23. SCRIPT
  24. Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
  25. config.ssh.shell = "bash -c 'BASH_ENV=/etc/profile exec bash'"
  26. num_nodes = 2
  27. base_ip = "192.168.33."
  28. net_ips = num_nodes.times.collect { |n| base_ip + "#{n+11}" }
  29. config.vm.define "consul-server" do |consul|
  30. consul.vm.box = "ubuntu/trusty64"
  31. consul.vm.hostname = "consul-server"
  32. consul.vm.network :private_network, ip: "192.168.33.10"
  33. consul.vm.provider "virtualbox" do |vb|
  34. vb.customize ["modifyvm", :id, "--memory", "512"]
  35. end
  36. consul.vm.provision :shell, inline: $consul
  37. end
  38. num_nodes.times do |n|
  39. config.vm.define "net-#{n+1}" do |net|
  40. net.vm.box = "ubuntu/vivid64"
  41. net_ip = net_ips[n]
  42. net_index = n+1
  43. net.vm.hostname = "net-#{net_index}"
  44. net.vm.provider "virtualbox" do |vb|
  45. vb.customize ["modifyvm", :id, "--memory", "1024"]
  46. end
  47. net.vm.network :private_network, ip: "#{net_ip}"
  48. net.vm.provision :shell, inline: $bootstrap, :args => "#{net_ip}"
  49. end
  50. end
  51. end