-
Notifications
You must be signed in to change notification settings - Fork 1
/
Vagrantfile
102 lines (81 loc) · 3.18 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
# -*- mode: ruby -*-
# vi: set ft=ruby :
require_relative 'lib/util'
require_relative 'lib/env_config'
require_relative 'lib/trigger_config'
SERVER_ENV = File.read('.env').gsub(/[\r\n]/,'')
VAGRANT_PATH = Dir.pwd
config_file = File.join(VAGRANT_PATH, 'config', Util.append_extension(SERVER_ENV,'yml'))
EnvConfig::Handler.load_config(config_file)
Vagrant.require_version '>= 1.5.1'
Vagrant.configure('2') do |config|
config.vm.box = 'ubuntu/trusty64'
config.vm.network :private_network, ip: EnvConfig::Handler.config['vagrant']['ip']
config.vm.hostname = EnvConfig::Handler.config['vagrant']['hostname']
sites = EnvConfig::Handler.config['sites']
if Vagrant::Util::Platform.windows?
sites.each do |site|
config.vm.synced_folder site['local_path'], remote_site_path(site), owner: 'vagrant', group: 'www-data', mount_options: ['dmode=776', 'fmode=775']
end
else
if !Vagrant.has_plugin? 'vagrant-bindfs'
raise Vagrant::Errors::VagrantError.new,
"vagrant-bindfs missing, please install the plugin:\nvagrant plugin install vagrant-bindfs"
else
sites.each do |site|
config.vm.synced_folder site['local_path'], nfs_path(site), type: 'nfs'
config.bindfs.bind_folder nfs_path(site), remote_site_path(site), u: 'vagrant', g: 'www-data'
end
end
end
if !Vagrant.has_plugin? 'vagrant-triggers'
raise Vagrant::Errors::VagrantError.new,
"vagrant-triggers missing, please install the plugin:\nvagrant plugin install vagrant-triggers"
else
Dir.glob('scripts/triggers/*.rb').each do |script_file|
require_relative Util.remove_ext(script_file)
end
TriggerConfig::Handler.triggers_for_env(SERVER_ENV).each do |t|
t[:trigger].each do |command, trigger|
t[:trigger_call].call config, command, trigger
end
end
end
Dir.glob('scripts/provisions/*.sh').each do |script_file|
begin
require_relative Util.remove_ext(script_file)
rescue LoadError
#do nothing, there are cases where args formatter might not be needed for a script
end
script_name = Util.strip_name(script_file)
script_config = EnvConfig::Handler.config[script_name]
if !script_config.nil?
script_args_arr = EnvConfig::Handler.args_formatters[script_name].call(script_config)
script_args_arr.each do |script_args|
config.vm.provision "shell", path: script_file, args: script_args
end
else
config.vm.provision "shell", path: script_file
end
end
config.vm.provider 'virtualbox' do |vb|
# Give VM access to all cpu cores on the host
cpus = case RbConfig::CONFIG['host_os']
when /darwin/ then `sysctl -n hw.ncpu`.to_i
when /linux/ then `nproc`.to_i
else 2
end
# Customize memory in MB
vb.customize ['modifyvm', :id, '--memory', 1024]
vb.customize ['modifyvm', :id, '--cpus', cpus]
# Fix for slow external network connections
vb.customize ['modifyvm', :id, '--natdnshostresolver1', 'on']
vb.customize ['modifyvm', :id, '--natdnsproxy1', 'on']
end
end
def nfs_path(site)
"/vagrant-nfs-#{site['site_name']}"
end
def remote_site_path(site)
File.join('/var/www/', site['site_name'], 'current')
end