-
Notifications
You must be signed in to change notification settings - Fork 0
/
Vagrantfile
97 lines (86 loc) · 2.99 KB
/
Vagrantfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# -*- mode: ruby -*-
# vi: set ft=ruby :
auto = ENV['AUTO_START_SWARM'] || false
# Increase numworkers if you want more than 3 nodes
numworkers = 2
# VirtualBox settings
# Increase vmmemory if you want more than 512mb memory in the vm's
vmmemory = 512
# Increase numcpu if you want more cpu's per vm
numcpu = 1
manager_ip = "192.168.56.2"
instances = []
(1..numworkers).each do |n|
instances.push({:name => "worker#{n}", :ip => "192.168.56.#{n+2}"})
end
http_proxy = ""
# Proxy configuration
if ENV['http_proxy']
http_proxy = ENV['http_proxy']
https_proxy = ENV['https_proxy']
end
no_proxy = "localhost,127.0.0.1,#{manager_ip}"
instances.each do |instance|
no_proxy += ",#{instance[:ip]}"
end
# Check if the necessary plugins are installed
if not http_proxy.to_s.strip.empty?
required_plugins = %w( vagrant-proxyconf )
plugins_to_install = required_plugins.select { |plugin| not Vagrant.has_plugin? plugin }
if not plugins_to_install.empty?
puts "Installing plugins: #{plugins_to_install.join(' ')}"
if system "vagrant plugin install #{plugins_to_install.join(' ')}"
exec "vagrant #{ARGV.join(' ')}"
else
abort "Installation of one or more plugins has failed. Aborting."
end
end
end
Vagrant.configure("2") do |config|
config.vm.provider "virtualbox" do |v|
v.memory = vmmemory
v.cpus = numcpu
end
config.vm.define "manager" do |i|
i.vm.box = "ubuntu/trusty64"
i.vm.hostname = "manager"
i.vm.network "private_network", ip: "#{manager_ip}"
# Proxy
if not http_proxy.to_s.strip.empty?
i.proxy.http = http_proxy
i.proxy.https = https_proxy
i.proxy.no_proxy = no_proxy
end
if Vagrant::Util::Platform.windows? then
# Configuration SPECIFIC for Windows 10 hosts
i.vm.synced_folder "files", "/home/vagrant/files",
id: "vagrant-root", ouner: "vagrant", group: "vagrant",
mount_options: ["dmode=775,fmode=664"]
else
# Configuration for Unix/Linux hosts
i.vm.synced_folder "files", "/home/vagrant/files"
end
i.vm.provision "shell", path: "./provision_manager.sh"
if auto
i.vm.provision "shell", inline: "docker swarm init --advertise-addr #{manager_ip}"
i.vm.provision "shell", inline: "docker swarm join-token -q worker > /vagrant/token"
end
end
instances.each do |instance|
config.vm.define instance[:name] do |i|
i.vm.box = "ubuntu/trusty64"
i.vm.hostname = instance[:name]
i.vm.network "private_network", ip: "#{instance[:ip]}"
# Proxy
if not http_proxy.to_s.strip.empty?
i.proxy.http = http_proxy
i.proxy.https = https_proxy
i.proxy.no_proxy = no_proxy
end
i.vm.provision "shell", path: "./provision_worker.sh"
if auto
i.vm.provision "shell", inline: "docker swarm join --advertise-addr #{instance[:ip]} --listen-addr #{instance[:ip]}:2377 --token `cat /vagrant/token` #{manager_ip}:2377"
end
end
end
end