-
Notifications
You must be signed in to change notification settings - Fork 67
/
Vagrantfile
161 lines (143 loc) · 5.38 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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
# -*- mode: ruby -*-
# vi: set ft=ruby :
#
# dvm - Effortless Docker-in-a-box for unsupported Docker platforms
# For more details, please visit http://fnichol.github.io/dvm
#
def shq(s) # sh(1)-style quoting
sprintf("'%s'", s.gsub(/'/, "'\\\\''"))
end
ip = ENV.fetch("DOCKER_IP", "192.168.42.43")
port = ENV.fetch("DOCKER_PORT", "2375")
memory = ENV.fetch("DOCKER_MEMORY", "512")
cpus = ENV.fetch("DOCKER_CPUS", "1")
cidr = ENV.fetch("DOCKER0_CIDR", "")
args = ENV.fetch("DOCKER_ARGS", "")
b2d_version = "1.2.0"
release_url = "https://github.com/fnichol/boot2docker-vagrant-box/releases/download/v#{b2d_version}"
docker0_bridge_setup = ""
bridge_utils_url = "ftp://ftp.nl.netbsd.org/vol/2/metalab/distributions/tinycorelinux/4.x/x86/tcz/bridge-utils.tcz"
unless cidr.empty?
args += " --bip=#{cidr}"
as_docker_usr = 'su - docker -c'
dl_dir = '/home/docker'
filename = 'bridge-utils.tcz'
dl_br_utils = "wget -P #{dl_dir} -O #{filename} #{shq(bridge_utils_url)}"
install_br_utils = "tce-load -i #{dl_dir}/#{filename}"
brctl = '/usr/local/sbin/brctl'
ifcfg = '/sbin/ifconfig'
take_docker0_down = "#{ifcfg} docker0 down"
delete_docker0 = "#{brctl} delbr docker0"
docker0_bridge_setup = <<-BRIDGE_SETUP
sudo $INITD stop
echo #{shq("#{as_docker_usr} #{shq(dl_br_utils)}")}
#{as_docker_usr} #{shq(dl_br_utils)}
echo #{shq("#{as_docker_usr} #{shq(install_br_utils)}")}
#{as_docker_usr} #{shq(install_br_utils)}
sudo #{take_docker0_down}
sudo #{delete_docker0}
BRIDGE_SETUP
end
def tinycore_supported?
Gem::Version.new(Vagrant::VERSION) >= Gem::Version.new("1.5.0")
end
module VagrantPlugins
module GuestTinyCore
module Cap ; end
class Plugin < Vagrant.plugin("2")
name "TinyCore Linux guest."
description "TinyCore Linux guest support."
if !tinycore_supported?
guest("tinycore", "linux") do
class ::VagrantPlugins::GuestTinyCore::Guest < Vagrant.plugin("2", :guest)
def detect?(machine)
machine.communicate.test("cat /etc/issue | grep 'Core Linux'")
end
end
Guest
end
end
if !tinycore_supported?
guest_capability("tinycore", "halt") do
class ::VagrantPlugins::GuestTinyCore::Cap::Halt
def self.halt(machine)
machine.communicate.sudo("poweroff")
rescue IOError
# Do nothing, because it probably means the machine shut down
# and SSH connection was lost.
end
end
Cap::Halt
end
end
guest_capability("tinycore", "configure_networks") do
class ::VagrantPlugins::GuestTinyCore::Cap::ConfigureNetworks
def self.configure_networks(machine, networks)
require 'ipaddr'
machine.communicate.tap do |comm|
networks.each do |n|
ifc = "/sbin/ifconfig eth#{n[:interface]}"
pid = "/var/run/udhcpc.eth#{n[:interface]}.pid"
broadcast = (IPAddr.new(n[:ip]) | (~ IPAddr.new(n[:netmask]))).to_s
comm.sudo("#{ifc} down")
comm.sudo("if [ -f #{pid} ]; then kill `cat #{pid}` && rm -f #{pid}; fi")
comm.sudo("#{ifc} #{n[:ip]} netmask #{n[:netmask]} broadcast #{broadcast}")
comm.sudo("#{ifc} up")
end
end
end
end
Cap::ConfigureNetworks
end
end
end
end
Vagrant.configure("2") do |config|
config.vm.box = "boot2docker-#{b2d_version}"
config.vm.network "forwarded_port",
guest: 2375, host: 2375, id: "docker", disabled: true
config.vm.network "private_network", :ip => ip
config.vm.provider :virtualbox do |v, override|
override.vm.box_url = "#{release_url}/boot2docker_virtualbox.box"
v.customize ["modifyvm", :id, "--natdnsproxy1", "on"]
v.customize ["modifyvm", :id, "--natdnshostresolver1", "on"]
v.customize ["modifyvm", :id, "--memory", Integer(memory)]
v.customize ["modifyvm", :id, "--cpus", Integer(cpus)]
end
["vmware_fusion", "vmware_workstation"].each do |vmware|
config.vm.provider vmware do |v, override|
override.vm.box_url = "#{release_url}/boot2docker_vmware.box"
v.vmx["memsize"] = Integer(memory)
v.vmx["numvcpus"] = Integer(cpus)
end
end
config.vm.provider :parallels do |v, override|
override.vm.box_url = "#{release_url}/boot2docker_parallels.box"
v.memory = Integer(memory)
v.cpus = Integer(cpus)
end
args = "export EXTRA_ARGS=#{shq args.strip}" unless args.empty?
config.vm.provision :shell, :inline => <<-PREPARE
INITD=/usr/local/etc/init.d/docker
PROFILE=/var/lib/boot2docker/profile
#{docker0_bridge_setup}
rm -f $PROFILE && touch $PROFILE
if [ #{port} -ne '2375' ]; then
echo "---> Configuring docker to listen on port '#{port}'"
echo "export DOCKER_HOST='-H tcp://0.0.0.0:#{port}'" >> $PROFILE
fi
if [ -n #{shq(args)} ]; then
echo '---> Configuring docker with args "'#{shq(args)}'"'
echo #{shq(args)} >> $PROFILE
fi
if ! grep -q '8\.8\.8\.8' /etc/resolv.conf >/dev/null; then
echo "nameserver 8.8.8.8" >> /etc/resolv.conf
fi
if [ -s "$PROFILE" ]; then
echo '---> Restarting docker daemon'
sudo $INITD restart
fi
echo "boot2docker: $(cat /etc/version)"
PREPARE
config.vm.define :dvm
end