forked from Zimbra/vagrant-provision-zimbra
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Vagrantfile
139 lines (123 loc) · 4.55 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
# -*- mode: ruby -*-
# vi: set ft=ruby :
def load_conf(cfile)
conf = Hash.new
if File.exists?("VMBOX")
print "loading VMBOX...\n" if ENV["DEBUG"]
conf["VMBOX"] = IO.read("VMBOX").gsub(/\s+/,"")
end
if File.exists?(cfile)
print "loading ", cfile, "...\n" if ENV["DEBUG"]
File.open(cfile).each_line do |line|
next if /^\s*(?:#|$)/.match(line)
key, val = line.strip.split(/\s*=\s*/, 2)
if /^'([^']*)'/.match(val) || /^"([^"]*)"/.match(val)
val = $1
elsif /^([^#]*)/.match(val)
val = $1.strip
end
val = val.split(/\s+/) if /^PROVARGS$/.match(key)
conf[key] = val
end
end
return conf
end
# Notes:
# - boxes ref: https://atlas.hashicorp.com/boxes/search
# - set HOSTNAME based on config or current directory name
# - set PROVARGS based on HOSTNAME ("-d" if name ends in d or dev)
# -b == build, -d == dev, -r == runtime
# Additional optional config items:
# MYUSER, HOMEDIR, SRCDIR
conf = load_conf("Vagrantfile.conf")
conf["VMMEMORY"] ||= 4096
conf["VMCPUS"] ||= 2
conf["HOMEDIR"] ||= File.expand_path('~' + conf["MYUSER"]) if conf["MYUSER"]
conf["HOSTNAME"] ||= File.basename(File.dirname(File.absolute_path(__FILE__)))
conf["PROVARGS"] ||= ["-d"]
conf["PROVPATH"] ||= File.join(File.dirname(File.absolute_path(__FILE__)),
"vsetup.sh")
if /^(?:up|provision|ssh|status)/.match(ARGV[0])
print "HOSTNAME (VMBOX): ", conf["HOSTNAME"], " (", conf["VMBOX"] || "default", ")\n"
if /^(?:up|provision)/.match(ARGV[0])
print "Provision path (args): ", conf["PROVPATH"], " (", conf["PROVARGS"] * " ", ")\n"
if conf["SRCDIR"]
print "SRCDIR: ", (conf["SRCDIR"] || ""), "\n"
end
end
end
conf.sort.each { |k, v| print "DEBUG: conf: ", k, " => ", v, "\n" } if ENV["DEBUG"]
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
if conf["VMBOX"] == "centos6"
config.vm.provider :docker do |docker|
docker.build_dir = conf["VMBOX"]
docker.has_ssh = true
docker.name = conf["HOSTNAME"]
end
end
config.vm.host_name = conf["HOSTNAME"]
if conf["HOMEDIR"]
config.vm.synced_folder conf["HOMEDIR"],
"/home/" + File.basename(conf["HOMEDIR"])
end
# virtualbox: mmap broken on mapped filesystems
# - ref: https://www.virtualbox.org/ticket/819
if conf["SRCDIR"]
config.vm.synced_folder conf["SRCDIR"], conf["SRCDIR"] #, type: "nfs"
end
# map vagrant user/grp to me, not root
config.nfs.map_uid = Process.uid
config.nfs.map_gid = Process.gid
config.vm.provider :lxc do |lxc, o|
o.vm.box = conf["VMBOX"] || "fgrehm/trusty64-lxc"
lxc.container_name = conf["VMNAME"] if conf["VMNAME"]
lxc.customize "network.link", conf["VMBRIDGE"] if conf["VMBRIDGE"]
end
config.vm.provider :virtualbox do |vb, o|
o.vm.box = conf["VMBOX"] || "ubuntu/trusty64"
vb.memory = conf["VMMEMORY"]
vb.cpus = conf["VMCPUS"]
vb.name = conf["VMNAME"] if conf["VMNAME"]
end
config.vm.provider :libvirt do |vd, o|
o.vm.box = conf["VMBOX"] || "ubuntu/trusty64"
vd.memory = conf["VMMEMORY"]
vd.cpus = conf["VMCPUS"]
end
config.vm.provider :parallels do |prl, o|
o.vm.box = conf["VMBOX"] || "parallels/ubuntu-14.04"
prl.memory = conf["VMMEMORY"]
prl.cpus = conf["VMCPUS"]
prl.name = conf["VMNAME"] if conf["VMNAME"]
end
config.vm.provider :vmware_fusion do |vmw, o|
o.vm.box = conf["VMBOX"] || "phusion/ubuntu-14.04-amd64"
vmw.vmx["memsize"] = conf["VMMEMORY"]
vmw.vmx["numvcpus"] = conf["VMCPUS"]
vmw.vmx["displayName"] = conf["VMNAME"] if conf["VMNAME"]
end
# http://fgrehm.viewdocs.io/vagrant-cachier
if Vagrant.has_plugin?("vagrant-cachier")
config.cache.scope = :box
end
# https://github.com/tmatilai/vagrant-timezone
if Vagrant.has_plugin?("vagrant-timezone")
config.timezone.value = :host
end
# this triggers a warning with lxc, but we work around that earlier
if conf["VMBRIDGE"]
config.vm.network "public_network", bridge: conf["VMBRIDGE"]
end
# refs: nfs[1] with private_network[2] and dhcp conflicting host adapter[3]
# 1. http://docs.vagrantup.com/v2/synced-folders/nfs.html
# 2. http://docs.vagrantup.com/v2/networking/private_network.html
# 3. https://github.com/mitchellh/vagrant/issues/3083 workaround:
# VBoxManage dhcpserver remove --netname HostInterfaceNetworking-vboxnet0
if conf["PROVPATH"]
config.vm.provision "ppath", type: "shell", path: conf["PROVPATH"], args: conf["PROVARGS"]
end
if conf["PROVCUSTOM"]
config.vm.provision "shell", inline: conf["PROVCUSTOM"]
end
end