forked from Varying-Vagrant-Vagrants/VVV
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Vagrantfile
402 lines (353 loc) · 18.1 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
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
# -*- mode: ruby -*-
# vi: set ft=ruby :
dir = Dir.pwd
vagrant_dir = File.expand_path(File.dirname(__FILE__))
Vagrant.configure("2") do |config|
config.vm.define "nginx" do |nginx|
# Store the current version of Vagrant for use in conditionals when dealing
# with possible backward compatible issues.
vagrant_version = Vagrant::VERSION.sub(/^v/, '')
# Configurations from 1.0.x can be placed in Vagrant 1.1.x specs like the following.
nginx.vm.provider :virtualbox do |v|
v.customize ["modifyvm", :id, "--memory", 1024]
v.customize ["modifyvm", :id, "--natdnshostresolver1", "on"]
v.customize ["modifyvm", :id, "--natdnsproxy1", "on"]
end
# Configuration options for the Parallels Provider
nginx.vm.provider :parallels do |v|
v.update_guest_tools = true
v.optimize_power_consumption = false
v.memory = 1024
end
# Forward Agent
#
# Enable agent forwarding on vagrant ssh commands. This allows you to use ssh keys
# on your host machine inside the guest. See the manual for `ssh-add`.
nginx.ssh.forward_agent = true
# Default Ubuntu Box
#
# This box is provided by Ubuntu vagrantcloud.com and is a nicely sized (332MB)
# box containing the Ubuntu 14.04 Trusty 64 bit release. Once this box is downloaded
# to your host computer, it is cached for future use under the specified box name.
nginx.vm.box = "ubuntu/trusty64"
# The Parallels Provider uses a different naming scheme.
nginx.vm.provider :parallels do |v, override|
override.vm.box = "parallels/ubuntu-14.04"
end
nginx.vm.hostname = "vvv"
# Local Machine Hosts
#
# If the Vagrant plugin hostsupdater (https://github.com/cogitatio/vagrant-hostsupdater) is
# installed, the following will automatically configure your local machine's hosts file to
# be aware of the domains specified below. Watch the provisioning script as you may need to
# enter a password for Vagrant to access your hosts file.
#
# By default, we'll include the domains set up by VVV through the vvv-hosts file
# located in the www/ directory.
#
# Other domains can be automatically added by including a vvv-hosts file containing
# individual domains separated by whitespace in subdirectories of www/.
if defined?(VagrantPlugins::HostsUpdater)
# Recursively fetch the paths to all vvv-hosts files under the www/ directory.
paths = Dir[File.join(vagrant_dir, 'www', '**', 'vvv-hosts')]
# Parse the found vvv-hosts files for host names.
hosts = paths.map do |path|
# Read line from file and remove line breaks
lines = File.readlines(path).map(&:chomp)
# Filter out comments starting with "#"
lines.grep(/\A[^#]/)
end.flatten.uniq # Remove duplicate entries
# Pass the found host names to the hostsupdater plugin so it can perform magic.
nginx.hostsupdater.aliases = hosts
nginx.hostsupdater.remove_on_suspend = true
end
# Default Box IP Address
#
# This is the IP address that your host will communicate to the guest through. In the
# case of the default `192.168.50.4` that we've provided, VirtualBox will setup another
# network adapter on your host machine with the IP `192.168.50.1` as a gateway.
#
# If you are already on a network using the 192.168.50.x subnet, this should be changed.
# If you are running more than one VM through VirtualBox, different subnets should be used
# for those as well. This includes other Vagrant boxes.
nginx.vm.network :private_network, ip: "192.168.50.4"
# External IP Address (example)
#
# To enable outside access to the virtual machine, a line similar to the following is
# required. Look for the IP address and adapter name in VirtualBox or by running
# `vboxmanage list bridgedifs` in a terminal on the host system. The common adapter name
# in OSX is `en0: Wi-Fi (AirPort)`. You will likely find a variety similar to the example
# below on Windows hosts.
#
# nginx.vm.network :public_network, :bridge => 'Realtek PCIe GBE Family Controller #2', ip: '192.168.1.82'
# Drive mapping
#
# The following nginx.vm.synced_folder settings will map directories in your Vagrant
# virtual machine to directories on your local machine. Once these are mapped, any
# changes made to the files in these directories will affect both the local and virtual
# machine versions. Think of it as two different ways to access the same file. When the
# virtual machine is destroyed with `vagrant destroy`, your files will remain in your local
# environment.
# /srv/database/
#
# If a database directory exists in the same directory as your Vagrantfile,
# a mapped directory inside the VM will be created that contains these files.
# This directory is used to maintain default database scripts as well as backed
# up mysql dumps (SQL files) that are to be imported automatically on vagrant up
nginx.vm.synced_folder "database/", "/srv/database"
# If the mysql_upgrade_info file from a previous persistent database mapping is detected,
# we'll continue to map that directory as /var/lib/mysql inside the virtual machine. Once
# this file is changed or removed, this mapping will no longer occur. A db_backup command
# is now available inside the virtual machine to backup all databases for future use. This
# command is automatically issued on halt, suspend, and destroy if the vagrant-triggers
# plugin is installed.
if File.exists?(File.join(vagrant_dir,'database/data/mysql_upgrade_info')) then
if vagrant_version >= "1.3.0"
nginx.vm.synced_folder "database/data/", "/var/lib/mysql", :mount_options => [ "dmode=777", "fmode=777" ]
else
nginx.vm.synced_folder "database/data/", "/var/lib/mysql", :extra => 'dmode=777,fmode=777'
end
# The Parallels Provider does not understand "dmode"/"fmode" in the "mount_options" as
# those are specific to Virtualbox. The folder is therefore overridden with one that
# uses corresponding Parallels mount options.
nginx.vm.provider :parallels do |v, override|
override.vm.synced_folder "database/data/", "/var/lib/mysql", :mount_options => []
end
end
# /srv/config/
#
# If a server-conf directory exists in the same directory as your Vagrantfile,
# a mapped directory inside the VM will be created that contains these files.
# This directory is currently used to maintain various config files for php and
# nginx as well as any pre-existing database files.
nginx.vm.synced_folder "config/", "/srv/config"
# /srv/log/
#
# If a log directory exists in the same directory as your Vagrantfile, a mapped
# directory inside the VM will be created for some generated log files.
nginx.vm.synced_folder "log/", "/srv/log", :owner => "www-data"
# /srv/www/
#
# If a www directory exists in the same directory as your Vagrantfile, a mapped directory
# inside the VM will be created that acts as the default location for nginx sites. Put all
# of your project files here that you want to access through the web server
if vagrant_version >= "1.3.0"
nginx.vm.synced_folder "www/", "/srv/www/", :owner => "www-data", :mount_options => [ "dmode=775", "fmode=774" ]
else
nginx.vm.synced_folder "www/", "/srv/www/", :owner => "www-data", :extra => 'dmode=775,fmode=774'
end
# The Parallels Provider does not understand "dmode"/"fmode" in the "mount_options" as
# those are specific to Virtualbox. The folder is therefore overridden with one that
# uses corresponding Parallels mount options.
nginx.vm.provider :parallels do |v, override|
override.vm.synced_folder "www/", "/srv/www/", :owner => "www-data", :mount_options => []
end
# Customfile - POSSIBLY UNSTABLE
#
# Use this to insert your own (and possibly rewrite) Vagrant config lines. Helpful
# for mapping additional drives. If a file 'Customfile' exists in the same directory
# as this Vagrantfile, it will be evaluated as ruby inline as it loads.
#
# Note that if you find yourself using a Customfile for anything crazy or specifying
# different provisioning, then you may want to consider a new Vagrantfile entirely.
if File.exists?(File.join(vagrant_dir,'Customfile')) then
eval(IO.read(File.join(vagrant_dir,'Customfile')), binding)
end
# Provisioning
#
# Process one or more provisioning scripts depending on the existence of custom files.
#
# provison-pre.sh acts as a pre-hook to our default provisioning script. Anything that
# should run before the shell commands laid out in provision.sh (or your provision-custom.sh
# file) should go in this script. If it does not exist, no extra provisioning will run.
if File.exists?(File.join(vagrant_dir,'provision','provision-pre.sh')) then
nginx.vm.provision :shell, :path => File.join( "provision", "provision-pre.sh" )
end
# provision.sh or provision-custom.sh
#
# By default, Vagrantfile is set to use the provision.sh bash script located in the
# provision directory. If it is detected that a provision-custom.sh script has been
# created, that is run as a replacement. This is an opportunity to replace the entirety
# of the provisioning provided by default.
if File.exists?(File.join(vagrant_dir,'provision','provision-custom.sh')) then
nginx.vm.provision :shell, :path => File.join( "provision", "provision-custom.sh" )
else
nginx.vm.provision :shell, :path => File.join( "provision", "provision.sh" )
end
# provision-post.sh acts as a post-hook to the default provisioning. Anything that should
# run after the shell commands laid out in provision.sh or provision-custom.sh should be
# put into this file. This provides a good opportunity to install additional packages
# without having to replace the entire default provisioning script.
if File.exists?(File.join(vagrant_dir,'provision','provision-post.sh')) then
nginx.vm.provision :shell, :path => File.join( "provision", "provision-post.sh" )
end
# Vagrant Triggers
#
# If the vagrant-triggers plugin is installed, we can run various scripts on Vagrant
# state changes like `vagrant up`, `vagrant halt`, `vagrant suspend`, and `vagrant destroy`
#
# These scripts are run on the host machine, so we use `vagrant ssh` to tunnel back
# into the VM and execute things. By default, each of these scripts calls db_backup
# to create backups of all current databases. This can be overridden with custom
# scripting. See the individual files in config/homebin/ for details.
if defined? VagrantPlugins::Triggers
nginx.trigger.before :halt, :stdout => true do
run "vagrant ssh -c 'vagrant_halt' nginx"
end
nginx.trigger.before :suspend, :stdout => true do
run "vagrant ssh -c 'vagrant_suspend' nginx"
end
nginx.trigger.before :destroy, :stdout => true do
run "vagrant ssh -c 'vagrant_destroy' nginx"
end
end
# Always start MySQL on boot, even when not running the full provisioner
# (run: "always" support added in 1.6.0)
if vagrant_version >= "1.6.0"
nginx.vm.provision :shell, inline: "sudo service mysql restart", run: "always"
nginx.vm.provision :shell, inline: "sudo service nginx restart", run: "always"
end
end
config.vm.define "apache" do |apache|
# Store the current version of Vagrant for use in conditionals when dealing
# with possible backward compatible issues.
vagrant_version = Vagrant::VERSION.sub(/^v/, '')
# Configurations from 1.0.x can be placed in Vagrant 1.1.x specs like the following.
apache.vm.provider :virtualbox do |v|
v.customize ["modifyvm", :id, "--memory", 512]
end
# Forward Agent
#
# Enable agent forwarding on vagrant ssh commands. This allows you to use identities
# established on the host machine inside the guest. See the manual for ssh-add
apache.ssh.forward_agent = true
# Default Ubuntu Box
#
# This box is provided by Vagrant at vagrantup.com and is a nicely sized (290MB)
# box containing the Ubuntu 12.0.4 Precise 32 bit release. Once this box is downloaded
# to your host computer, it is cached for future use under the specified box name.
apache.vm.box = "precise32"
apache.vm.box_url = "http://files.vagrantup.com/precise32.box"
apache.vm.hostname = "vvv"
# Local Machine Hosts
#
# If the Vagrant plugin hostsupdater (https://github.com/cogitatio/vagrant-hostsupdater) is
# installed, the following will automatically configure your local machine's hosts file to
# be aware of the domains specified below. Watch the provisioning script as you may be
# required to enter a password for Vagrant to access your hosts file.
#
# By default, we'll include the domains setup by VVV through the vvv-hosts file
# located in the www/ directory.
#
# Other domains can be automatically added by including a vvv-hosts file containing
# individual domains separated by whitespace in subdirectories of www/.
if defined? VagrantPlugins::HostsUpdater
# Capture the paths to all vvv-hosts files under the www/ directory.
paths = []
Dir.glob(vagrant_dir + '/www/**/vvv-hosts').each do |path|
paths << path
end
# Parse through the vvv-hosts files in each of the found paths and put the hosts
# that are found into a single array.
hosts = []
paths.each do |path|
new_hosts = []
file_hosts = IO.read(path).split( "\n" )
file_hosts.each do |line|
if line[0..0] != "#"
new_hosts << line
end
end
hosts.concat new_hosts
end
# Pass the final hosts array to the hostsupdate plugin so it can perform magic.
apache.hostsupdater.aliases = hosts
end
# Default Box IP Address
#
# This is the IP address that your host will communicate to the guest through. In the
# case of the default `192.168.50.4` that we've provided, VirtualBox will setup another
# network adapter on your host machine with the IP `192.168.50.1` as a gateway.
#
# If you are already on a network using the 192.168.50.x subnet, this should be changed.
# If you are running more than one VM through VirtualBox, different subnets should be used
# for those as well. This includes other Vagrant boxes.
apache.vm.network :private_network, ip: "192.168.50.4"
# Drive mapping
#
# The following apache.vm.synced_folder settings will map directories in your Vagrant
# virtual machine to directories on your local machine. Once these are mapped, any
# changes made to the files in these directories will affect both the local and virtual
# machine versions. Think of it as two different ways to access the same file. When the
# virtual machine is destroyed with `vagrant destroy`, your files will remain in your local
# environment.
# /srv/database/
#
# If a database directory exists in the same directory as your Vagrantfile,
# a mapped directory inside the VM will be created that contains these files.
# This directory is used to maintain default database scripts as well as backed
# up mysql dumps (SQL files) that are to be imported automatically on vagrant up
apache.vm.synced_folder "database/", "/srv/database"
if vagrant_version >= "1.3.0"
apache.vm.synced_folder "database/data/", "/var/lib/mysql", :mount_options => [ "dmode=777", "fmode=777" ]
else
apache.vm.synced_folder "database/data/", "/var/lib/mysql", :extra => 'dmode=777,fmode=777'
end
# /srv/config/
#
# If a server-conf directory exists in the same directory as your Vagrantfile,
# a mapped directory inside the VM will be created that contains these files.
# This directory is currently used to maintain various config files for php and
# Apache as well as any pre-existing database files.
apache.vm.synced_folder "config/", "/srv/config"
# /srv/www/
#
# If a www directory exists in the same directory as your Vagrantfile, a mapped directory
# inside the VM will be created that acts as the default location for Apache sites. Put all
# of your project files here that you want to access through the web server
if vagrant_version >= "1.3.0"
apache.vm.synced_folder "www/", "/srv/www/", :owner => "www-data", :mount_options => [ "dmode=775", "fmode=774" ]
else
apache.vm.synced_folder "www/", "/srv/www/", :owner => "www-data", :extra => 'dmode=775,fmode=774'
end
# Customfile - POSSIBLY UNSTABLE
#
# Use this to insert your own (and possibly rewrite) Vagrant config lines. Helpful
# for mapping additional drives. If a file 'Customfile' exists in the same directory
# as this Vagrantfile, it will be evaluated as ruby inline as it loads.
#
# Note that if you find yourself using a Customfile for anything crazy or specifying
# different provisioning, then you may want to consider a new Vagrantfile entirely.
if File.exists?(File.join(vagrant_dir,'Customfile')) then
eval(IO.read(File.join(vagrant_dir,'Customfile')), binding)
end
# Provisioning
#
# Process one or more provisioning scripts depending on the existence of custom files.
#
# provison-pre.sh acts as a pre-hook to our default provisioning script. Anything that
# should run before the shell commands laid out in provision.sh (or your provision-custom.sh
# file) should go in this script. If it does not exist, no extra provisioning will run.
if File.exists?(File.join(vagrant_dir,'provision','provision-pre.sh')) then
apache.vm.provision :shell, :path => File.join( "provision", "provision-pre.sh" )
end
# provision.sh or provision-custom.sh
#
# By default, Vagrantfile is set to use the provision.sh bash script located in the
# provision directory. If it is detected that a provision-custom.sh script has been
# created, that is run as a replacement. This is an opportunity to replace the entirety
# of the provisioning provided by default.
if File.exists?(File.join(vagrant_dir,'provision','provision-custom.sh')) then
apache.vm.provision :shell, :path => File.join( "provision", "provision-custom.sh" )
else
apache.vm.provision :shell, :path => File.join( "provision", "provision.sh" )
end
# provision-post.sh acts as a post-hook to the default provisioning. Anything that should
# run after the shell commands laid out in provision.sh or provision-custom.sh should be
# put into this file. This provides a good opportunity to install additional packages
# without having to replace the entire default provisioning script.
if File.exists?(File.join(vagrant_dir,'provision','provision-post.sh')) then
apache.vm.provision :shell, :path => File.join( "provision", "provision-post.sh" )
end
end
end