-
Notifications
You must be signed in to change notification settings - Fork 48
/
Vagrantfile.XENIAL
121 lines (107 loc) · 4.13 KB
/
Vagrantfile.XENIAL
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
# -*- mode: ruby -*-
# vi: set ft=ruby :
# All Vagrant configuration is done below. The "2" in Vagrant.configure
# configures the configuration version (we support older styles for
# backwards compatibility). Please don't change it unless you know what
# you're doing.
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 = 2048
# Increase numcpu if you want more cpu's per vm
numcpu = 1
instances = []
(1..numworkers).each do |n|
instances.push({:name => "worker#{n}", :ip => "192.168.10.#{n+2}"})
end
manager_ip = "192.168.10.2"
File.open("./hosts", 'w') { |file|
instances.each do |i|
file.write("#{i[:ip]} #{i[:name]} #{i[:name]}\n")
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
# Vagrant version requirement
Vagrant.require_version ">= 1.8.4"
# 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/xenial64"
i.vm.box_url = "https://cloud-images.ubuntu.com/xenial/current/xenial-server-cloudimg-amd64-vagrant.box"
i.vm.hostname = "manager"
i.vm.network "private_network", ip: "#{manager_ip}"
i.vm.network "forwarded_port", guest:2375, host:2375
i.vm.network "forwarded_port", guest:2376, host:2376
i.vm.network "forwarded_port", guest:8080, host:8080
i.vm.network "forwarded_port", guest:8081, host:8081
i.vm.network "forwarded_port", guest:8082, host:8082
i.vm.network "forwarded_port", guest:8083, host:8083
i.vm.network "forwarded_port", guest:8084, host:8084
i.vm.network "forwarded_port", guest:8085, host:8085
i.vm.synced_folder "synced/manager", "/data"
# 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.sh"
if File.file?("./hosts")
i.vm.provision "file", source: "hosts", destination: "/tmp/hosts"
i.vm.provision "shell", inline: "cat /tmp/hosts >> /etc/hosts", privileged: true
end
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/xenial64"
i.vm.box_url = "https://cloud-images.ubuntu.com/xenial/current/xenial-server-cloudimg-amd64-vagrant.box"
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.sh"
if File.file?("./hosts")
i.vm.provision "file", source: "hosts", destination: "/tmp/hosts"
i.vm.provision "shell", inline: "cat /tmp/hosts >> /etc/hosts", privileged: true
end
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