This repository has been archived by the owner on May 25, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 37
/
Copy pathVagrantfile.pkg
76 lines (63 loc) · 2.61 KB
/
Vagrantfile.pkg
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
require "yaml"
require "json"
# Initialize config
def deep_merge!(target, data)
merger = proc{|key, v1, v2|
Hash === v1 && Hash === v2 ? v1.merge(v2, &merger) : v2 }
target.merge! data, &merger
end
_config = {
"synced_folders" => {
"/var/www" => File.join(Dir.pwd, "www"),
"/home/vagrant/Projects" => File.join(Dir.pwd, "Projects")
},
"nfs" => !!(RUBY_PLATFORM =~ /darwin/ || RUBY_PLATFORM =~ /linux/),
"virtualbox" => {
"name" => "joomlatools-box",
"memory" => 1024,
"cpus" => 1,
"natdnshostresolver1" => "on",
"uartmode1" => "disconnected",
"cpuexecutioncap" => "90"
},
"ip" => "33.33.33.58",
"mount_options" => ["vers=3", "rw", "tcp", "nolock", "noacl", "async"],
"linux_nfs_options" => ['rw', 'no_subtree_check', 'all_squash','async']
}
# Local-specific/not-git-managed config -- config.custom.yaml
begin
deep_merge!(_config, YAML.load(File.open(File.join(Dir.pwd, "config.custom.yaml"), File::RDONLY).read))
rescue Errno::ENOENT
# No config.custom.yaml found -- that's OK; just use the defaults.
end
CONF = _config
Vagrant.configure("2") do |config|
config.vm.network :private_network, ip: CONF["ip"]
config.ssh.forward_agent = true
config.vm.hostname = "joomlatools" # Important: we use this in joomla-console to determine if we are being run in the Vagrant box or not!
if CONF.has_key?('virtualbox')
parameters = Array['name', 'memory', 'cpus', 'natdnshostresolver1', 'uartmode1', 'cpuexecutioncap']
config.vm.provider :virtualbox do |v|
parameters.each { |parameter|
if (CONF['virtualbox'].has_key?(parameter) && !CONF['virtualbox'][parameter].to_s.empty?)
v.customize ["modifyvm", :id, "--" + parameter, CONF['virtualbox'][parameter]]
end
}
end
end
if CONF.has_key?('synced_folders')
CONF['synced_folders'].each { |target, source|
if source
config.vm.synced_folder source, target, :nfs => CONF['nfs'], :linux__nfs_options => CONF['linux_nfs_options'], :mount_options => CONF["mount_options"], :create => true
end
}
# Store the shared paths as an environment variable on the box
pwd = Dir.pwd
pwd << '/' unless pwd.end_with?('/')
mapping = Hash[ CONF['synced_folders'].each_pair.map { |key, value| [key, value.gsub(/^\.\//, pwd)] }]
json = mapping.to_json.gsub(/"/, '\\\\\\\\\"')
paths = 'SetEnv BOX_SHARED_PATHS \"' + json + '\"'
shell_cmd = 'echo "' + paths + '" > /etc/apache2/conf.d/25-shared_paths.conf && service apache2 restart'
config.vm.provision :shell, :inline => shell_cmd, :run => "always"
end
end