This repository has been archived by the owner on Apr 13, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
/
Vagrantfile
104 lines (85 loc) · 4.29 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
Vagrant.require_version ">= 1.8.5"
required_plugins = %w(vagrant-hostsupdater vagrant-vbguest)
plugins_to_install = required_plugins.select { |plugin| not Vagrant.has_plugin? plugin }
if not plugins_to_install.empty?
puts "Installing plugins: #{plugins_to_install.join(' ')}"
if system "vagrant plugin install #{plugins_to_install.join(' ')}"
exec "vagrant #{ARGV.join(' ')}"
else
abort "Installation of one or more plugins has failed. Aborting."
end
end
require 'json'
class ::Hash
def deep_merge(second)
merger = proc { |key, v1, v2| Hash === v1 && Hash === v2 ? v1.merge(v2, &merger) : v2 }
self.merge(second, &merger)
end
end
vagrant_dir = File.expand_path(File.dirname(__FILE__))
data_dir = File.join(vagrant_dir, 'www', 'default', 'data')
default_settings = File.join(data_dir, 'defaults.json')
custom_settings = File.join(data_dir, 'settings.json')
settings = JSON.parse(File.read(default_settings))
if File.exists?(custom_settings)
settings = settings.deep_merge(JSON.parse(File.read(custom_settings)))
end
Vagrant.configure(2) do |config|
config.vm.box = "ubuntu/xenial64"
config.vm.hostname = "phalcon-vm"
config.vm.provider :virtualbox do |v|
v.name = File.basename(vagrant_dir) + "_" + (Digest::SHA256.hexdigest vagrant_dir)[0..10]
v.customize ["modifyvm", :id, "--memory", 1024]
v.customize ["modifyvm", :id, "--cpus", 1]
v.customize ["modifyvm", :id, "--natdnshostresolver1", "on"]
v.customize ["modifyvm", :id, "--natdnsproxy1", "on"]
v.customize ["modifyvm", :id, "--rtcuseutc", "on"]
v.customize ["modifyvm", :id, "--audio", "none"]
v.customize ["modifyvm", :id, "--paravirtprovider", "kvm"]
end
config.vm.provider :parallels do |v, override| override.vm.box = "parallels/ubuntu-14.04"; end
config.vm.provider :vmware_fusion do |v, override| override.vm.box = "netsensia/ubuntu-trusty64"; end
config.vm.provider :vmware_workstation do |v, override| override.vm.box = "netsensia/ubuntu-trusty64"; end
config.vm.provider :hyperv do |v, override| override.vm.box = "ericmann/trusty64"; end
config.ssh.forward_agent = true
config.vm.network "private_network", ip: "192.168.50.99"
config.vm.provider :hyperv do |v, override| override.vm.network :private_network, id: "avm_primary", ip: nil; end
if settings['varnish']['enabled'] === true
config.vm.network "forwarded_port", guest: settings['varnish']['port'], host: settings['varnish']['port']
end
if settings['mysql']['enabled'] === true and settings['mysql']['forward_port'] === true
config.vm.network "forwarded_port", guest: settings['mysql']['port'], host: settings['mysql']['port']
end
if settings['redis']['enabled'] === true and settings['redis']['forward_port'] === true
config.vm.network "forwarded_port", guest: settings['redis']['port'], host: settings['redis']['port']
end
if settings['memcached']['enabled'] === true and settings['memcached']['forward_port'] === true
config.vm.network "forwarded_port", guest: settings['memcached']['port'], host: settings['memcached']['port']
end
if settings['elasticsearch']['enabled'] === true and settings['elasticsearch']['forward_port'] === true
config.vm.network "forwarded_port", guest: settings['elasticsearch']['port'], host: settings['elasticsearch']['port']
end
config.vm.synced_folder "provision/", "/srv/provision/"
config.vm.synced_folder "ssh/", "/root/.ssh/", :owner => "root"
# config.vm.synced_folder "log/", "/srv/log/", :owner => "www-data"
config.vm.synced_folder "www/", "/srv/www/", :owner => "www-data", :mount_options => [ "dmode=775", "fmode=774" ]
# config.vm.synced_folders.each do |id, options|
# # Make sure we use Samba for file mounts on Windows
# if ! options[:type] && Vagrant::Util::Platform.windows?
# options[:type] = "smb"
# end
# end
if defined?(VagrantPlugins::HostsUpdater)
hosts = settings['sites'].map do |site|
site['domains']
end
config.hostsupdater.aliases = hosts
config.hostsupdater.remove_on_suspend = true
end
config.vm.provision "fix-no-tty", type: "shell" do |s|
s.privileged = false
s.inline = "sudo sed -i '/tty/!s/mesg n/tty -s \\&\\& mesg n/' /root/.profile"
end
config.vm.provision "provision", type: "shell", path: File.join( "provision", "provision.sh" )
config.vm.provision "startup", type: "shell", path: File.join( "provision", "startup.sh" ), run: "always"
end