forked from henriquemacosi/vagrant
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Vagrantfile
308 lines (259 loc) · 11.4 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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
# -*- mode: ruby -*-
# vi: set ft=ruby :
require 'yaml'
dir = File.dirname(File.expand_path(__FILE__))
configValues = YAML.load_file("#{dir}/vagrant/config.yaml")
data = configValues['vagrantfile-local']
# Check if I have the required additional files
if !File.file?("#{dir}/vagrant/config_projects.yaml")
print "Please rename and configure config_projects.yaml-dist to config_projects.yaml to continue\n"
exit
end
if !File.file?("#{dir}/vagrant/config_sites.yaml")
print "Please rename and configure config_sites.yaml-dist to config_sites.yaml to continue\n"
exit
end
rawProjects = YAML.load_file("#{dir}/vagrant/config_projects.yaml")
projects = rawProjects['projects']
rawSites = YAML.load_file("#{dir}/vagrant/config_sites.yaml")
sites = rawSites['installsites']
# Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
# Run hostmanager as the very last action
if Vagrant.has_plugin?("vagrant-hostmanager")
config.hostmanager.enabled = false
config.hostmanager.manage_host = true
config.hostmanager.ignore_private_ip = false
config.hostmanager.aliases = Array.new
end
# Which box should I use?
config.vm.box = "#{data['vm']['box']}"
config.vm.box_url = "#{data['vm']['box_url']}"
config.vm.define "devbox" do |devbox|
if Vagrant.has_plugin?("vagrant-hostmanager")
devbox.hostmanager.aliases = Array.new
end
# Set up the hostname of the guest, if specified
if data['vm']['hostname'].to_s.strip.length != 0
devbox.vm.hostname = "#{data['vm']['hostname']}"
end
# Set up automatic update checks
if !data['vm']['box_check_update'].nil?
devbox.vm.box_check_update = "#{data['vm']['box_check_update']}"
end
# Set up forwarded ports
data['vm']['network']['forwarded_port'].each do |i, port|
if port['guest'] != '' && port['host'] != ''
devbox.vm.network :forwarded_port, guest: port['guest'].to_i, host: port['host'].to_i
end
end
# A message to show after vagrant up
if !data['vm']['post_up_message'].nil?
devbox.vm.post_up_message = "#{data['vm']['post_up_message']}"
end
# Create a private network
if data['vm']['network']['private_network'].to_s != ''
devbox.vm.network 'private_network', ip: "#{data['vm']['network']['private_network']}"
end
# Create a public network
if !data['vm']['public_network'].to_i == 1
devbox.vm.network "public_network"
end
# Configure SSH access to the Vagrant box
if !data['ssh']['host'].nil?
config.ssh.host = "#{data['ssh']['host']}"
end
if !data['ssh']['port'].nil?
config.ssh.port = "#{data['ssh']['port']}"
end
if !data['ssh']['username'].nil?
config.ssh.username = "#{data['ssh']['username']}"
end
if !data['ssh']['guest_port'].nil?
config.ssh.guest_port = data['ssh']['guest_port']
end
if !data['ssh']['shell'].nil?
config.ssh.shell = "#{data['ssh']['shell']}"
end
if !data['ssh']['keep_alive'].nil?
config.ssh.keep_alive = data['ssh']['keep_alive']
end
if !data['ssh']['forward_agent'].nil?
config.ssh.forward_agent = data['ssh']['forward_agent']
end
if !data['ssh']['forward_x11'].nil?
config.ssh.forward_x11 = data['ssh']['forward_x11']
end
# Set up folder shares
if !data['vm']['synced_folder'].nil?
data['vm']['synced_folder'].each do |i, folder|
if folder['source'] != '' && folder['target'] != ''
sync_owner = !folder['sync_owner'].nil? ? folder['sync_owner'] : 'www-data'
sync_group = !folder['sync_group'].nil? ? folder['sync_group'] : 'www-data'
if folder['sync_type'] == 'nfs'
devbox.vm.synced_folder "#{folder['source']}", "#{folder['target']}", id: "#{i}", type: 'nfs'
elsif folder['sync_type'] == 'smb'
devbox.vm.synced_folder "#{folder['source']}", "#{folder['target']}", id: "#{i}", type: 'smb'
elsif folder['sync_type'] == 'rsync'
rsync_args = !folder['rsync']['args'].nil? ? folder['rsync']['args'] : ['--verbose', '--archive', '-z']
rsync_auto = !folder['rsync']['auto'].nil? ? folder['rsync']['auto'] : true
rsync_exclude = !folder['rsync']['exclude'].nil? ? folder['rsync']['exclude'] : ['.vagrant/']
devbox.vm.synced_folder "#{folder['source']}", "#{folder['target']}", id: "#{i}",
rsync__args: rsync_args, rsync__exclude: rsync_exclude, rsync__auto: rsync_auto, type: 'rsync', group: sync_group, owner: sync_owner
else
devbox.vm.synced_folder "#{folder['source']}", "#{folder['target']}", id: "#{i}",
group: sync_group, owner: sync_owner, mount_options: ['dmode=775', 'fmode=764']
end
end
end
end
# Set up project folders
projects['synced_folder'].each do |i, folder|
if folder['source'] != '' && folder['target'] != ''
sync_owner = !folder['sync_owner'].nil? ? folder['sync_owner'] : 'www-data'
sync_group = !folder['sync_group'].nil? ? folder['sync_group'] : 'www-data'
if folder['sync_type'] == 'nfs'
devbox.vm.synced_folder "#{folder['source']}", "#{folder['target']}", id: "#{i}", type: 'nfs'
elsif folder['sync_type'] == 'smb'
devbox.vm.synced_folder "#{folder['source']}", "#{folder['target']}", id: "#{i}", type: 'smb'
elsif folder['sync_type'] == 'rsync'
rsync_args = !folder['rsync']['args'].nil? ? folder['rsync']['args'] : ['--verbose', '--archive', '-z']
rsync_auto = !folder['rsync']['auto'].nil? ? folder['rsync']['auto'] : true
rsync_exclude = !folder['rsync']['exclude'].nil? ? folder['rsync']['exclude'] : ['.vagrant/']
devbox.vm.synced_folder "#{folder['source']}", "#{folder['target']}", id: "#{i}",
rsync__args: rsync_args, rsync__exclude: rsync_exclude, rsync__auto: rsync_auto, type: 'rsync', group: sync_group, owner: sync_owner
else
devbox.vm.synced_folder "#{folder['source']}", "#{folder['target']}", id: "#{i}",
group: sync_group, owner: sync_owner, mount_options: ['dmode=775', 'fmode=764']
end
end
end
# VirtualBox configuration
devbox.vm.provider :virtualbox do |virtualbox|
data['vm']['provider']['virtualbox']['modifyvm'].each do |key, value|
if key == 'memory'
next
end
if key == 'cpus'
next
end
if key == 'natdnshostresolver1'
value = value ? 'on' : 'off'
end
virtualbox.customize ['modifyvm', :id, "--#{key}", "#{value}"]
end
virtualbox.customize ['modifyvm', :id, '--memory', "#{data['vm']['memory']}"]
virtualbox.customize ['modifyvm', :id, '--cpus', "#{data['vm']['cpus']}"]
if data['vm']['provider']['virtualbox']['modifyvm']['name'].nil? ||
data['vm']['provider']['virtualbox']['modifyvm']['name'].empty?
if data['vm']['hostname'].to_s.strip.length != 0
virtualbox.customize ['modifyvm', :id, '--name', devbox.vm.hostname]
end
end
end
# Provider-specific configuration so you can fine-tune various
# backing providers for Vagrant. These expose provider-specific options.
# Example for VirtualBox:
#
devbox.vm.provider "virtualbox" do |vb|
# Don't boot with headless mode
# vb.gui = true
# Use VBoxManage to customize the VM. For example to change memory:
vb.customize ["modifyvm", :id, "--memory", "512"]
end
# Enable the Vagrant Cachier plugin if it's installed
if Vagrant.has_plugin?('vagrant-cachier')
config.cache.scope = :box
end
# Provisioning – run once
# ====================================================================================================================
# Initial provisioning. Installs all the necessary packages.
devbox.vm.provision :shell, :path => "vagrant/initial-provision.sh"
# Download and compile every configured PHP version
data['multiphp'].each do |phpversion, values|
if values['install'].to_i == 1
devbox.vm.provision 'shell' do |s|
s.path = 'vagrant/install-php.sh'
s.args = [values['source_url'], "#{phpversion}", values['default'].to_i, values['hostname']]
end
end
end
# Download and compile XDebug for every configured PHP version
data['multiphp'].each do |phpversion, values|
if (values['install'].to_i == 1) && (values['xdebug_install'].to_i == 1)
devbox.vm.provision 'shell' do |s|
s.path = 'vagrant/install-xdebug.sh'
s.args = [values['xdebug_url'], "#{phpversion}"]
end
end
end
# Install PEAR. This is a separate script as it uses GNU expect to run the installation
devbox.vm.provision :shell, :path => "vagrant/install-pear.sh"
# Install Composer, phpUnit, Phing, PHP CodeSniffer, PHP Mess Detector
devbox.vm.provision :shell, :path => "vagrant/install-composer-and-friends.sh"
# Download and install additional PHP scripts
data['extrascripts'].each do |subdomain, values|
if values['install'].to_i == 1
devbox.vm.provision 'shell' do |s|
s.path = 'vagrant/install-extrascript.sh'
s.args = [values['source_url'], subdomain]
end
end
end
# Install all the Joomla! sites
sites.each do |subdomain, values|
devbox.vm.provision 'shell' do |s|
s.path = 'vagrant/install-site-' + values['type'] + '.sh'
s.args = [values['source'], subdomain]
end
values['linkextensions'].each do |tag|
if projects['extensions'][tag].nil?
next
end
extval = projects['extensions'][tag]
if extval['type'] == 'relink'
devbox.vm.provision 'shell' do |s|
s.path = 'vagrant/link-joomla-extension.sh'
s.args = [extval['source'], subdomain, tag]
end
end
if extval['type'] == 'library'
devbox.vm.provision 'shell' do |s|
s.path = 'vagrant/link-joomla-library.sh'
s.args = [extval['source'], extval['target'], subdomain]
end
end
end
end
# Install Mail Catcher
devbox.vm.provision :shell, :path => "vagrant/install-mailcatcher.sh"
# Set up host aliases for each PHP version and site
if Vagrant.has_plugin?("vagrant-hostmanager")
data['multiphp'].each do |phpversion, values|
if values['install'].to_i == 1
# Main domain
devbox.hostmanager.aliases.push(values['hostname'])
# Extra scripts' domains
data['extrascripts'].each do |subdomain, extravalues|
if extravalues['install'].to_i == 1
devbox.hostmanager.aliases.push(subdomain + '.' + values['hostname'])
end
end
# Joomla! site's domains
sites.each do |subdomain, extravalues|
devbox.hostmanager.aliases.push(subdomain + '.' + values['hostname'])
end
end
end
end
# Provisioning – every time we spin up the box
# ====================================================================================================================
# Restart Apache. Makes sure that Apache can see directories added/mounted after the boot sequence.
devbox.vm.provision "shell", inline: "service apache2 restart", run: "always"
# Hosts file management
if Vagrant.has_plugin?("vagrant-hostmanager")
devbox.vm.provision :hostmanager
end
end
end