-
Notifications
You must be signed in to change notification settings - Fork 6
/
Vagrantfile
executable file
·87 lines (67 loc) · 2.58 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
# -*- mode: ruby -*-
# vi: set ft=ruby :
# plugins expected:
# - `vagrant plugin install vagrant-hostmanager`
# - `vagrant plugin install vagrant-proxyconf`
# vars expected:
# - `LOCAL_PROXY`
# hack for vagrant-hostmanager
# https://github.com/devopsgroup-io/vagrant-hostmanager/issues/121
$logger = Log4r::Logger.new('vagrantfile')
def read_ip_address(machine)
command = "/usr/sbin/ip addr show eth1 | grep 'inet ' | xargs | cut -f 2 -d ' '| cut -f 1 -d '/' 2>&1"
result = ""
$logger.info "Processing #{ machine.name } ... "
begin
# sudo is needed for ifconfig
machine.communicate.sudo(command) do |type, data|
result << data if type == :stdout
end
$logger.info "Processing #{ machine.name } ... success"
rescue
result = "# NOT-UP"
$logger.info "Processing #{ machine.name } ... not running"
end
# the second inet is more accurate
result.chomp.split("\n").last
end
Vagrant.configure(2) do |config|
# hostmanager
config.hostmanager.enabled = true
config.hostmanager.manage_host = true
config.hostmanager.manage_guest = true
config.hostmanager.ignore_private_ip = false
config.hostmanager.include_offline = true
config.hostmanager.ip_resolver = proc do |vm, resolving_vm|
read_ip_address(vm)
end
# local proxy - e.g cntlm on windows (docker is a special case)
if ENV['LOCAL_PROXY'] == 'true'
config.proxy.http = "http://10.0.2.2:3128/"
config.proxy.https = "http://10.0.2.2:3128/"
config.vm.provision "shell", path: "docker-engine-proxy.sh"
end
# guest proxy
config.proxy.no_proxy = "localhost,127.0.0.1,docker1,docker2,docker3"
# misc
config.vm.box = "centos/7"
config.vm.network "private_network", type: "dhcp"
# does not appear to support vagrant-hostmanager ...
#config.vm.box = "bento/centos-7.2"
config.vm.provider :virtualbox do |v|
v.customize ["modifyvm", :id, "--memory", 1792]
end
config.vm.define "docker1" do |docker1|
#docker1.vm.network "forwarded_port", guest: 443, host: 4430
#docker1.vm.network "forwarded_port", guest: 8443, host: 4431
docker1.vm.provision "shell", path: "scripts/docker1.sh"
end
config.vm.define "docker2" do |docker2|
#docker2.vm.network "forwarded_port", guest: 8443, host: 4432
docker2.vm.provision "shell", path: "scripts/docker2.sh"
end
config.vm.define "docker3" do |docker3|
#docker3.vm.network "forwarded_port", guest: 8443, host: 4433
docker3.vm.provision "shell", path: "scripts/docker3.sh"
end
end