forked from wikimedia/mediawiki-vagrant
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Vagrantfile
279 lines (231 loc) · 9.73 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
# -*- mode: ruby -*-
# vi: set ft=ruby :
#
# Vagrantfile for Mediawiki-Vagrant
# ---------------------------------
# http://www.mediawiki.org/wiki/Mediawiki-Vagrant
#
# This file contains the Vagrant configurations for provisioning a MediaWiki
# development instance. Vagrant file uses Ruby as a configuration language.
#
# The file's structure and content are described in the Vagrant docs:
# http://docs.vagrantup.com/v2/vagrantfile/index.html
#
# If you would like to customize the configuration of your Virtual Machine,
# rather than override the values defined in this file, simply create a file
# called 'Vagrantfile-extra.rb' in this folder and it will be automatically
# loaded. In case of conflict, values in the 'extra' file will superceded
# any values in this file. 'Vagrantfile-extra.rb' is ignored by git.
#
# Simple configuration changes can be made by running the setup script (see
# README.md for details).
#
# Please report bugs in this file on Wikimedia's Bugzilla:
# https://bugzilla.wikimedia.org/enter_bug.cgi?product=MediaWiki-Vagrant
#
# Patches and contributions are welcome!
# http://www.mediawiki.org/wiki/How_to_become_a_MediaWiki_hacker
#
# Ensure we're using the latest version of the plugin
require_relative 'lib/mediawiki-vagrant/version'
require 'fileutils'
require 'ipaddr'
# NOTE Use RubyGems over the Vagrant plugin manager as it's more reliable
gemspec = Gem::Specification.find { |s| s.name == 'mediawiki-vagrant' }
setup = Vagrant::Util::Platform.windows? ? 'setup.bat' : 'setup.sh'
if gemspec.nil?
raise "The mediawiki-vagrant plugin hasn't been installed yet. Please run `#{setup}`."
else
installed = gemspec.version
latest = Gem::Version.new(MediaWikiVagrant::VERSION)
requirement = Gem::Requirement.new("~> #{latest.segments.first(2).join('.')}")
raise "Your mediawiki-vagrant plugin isn't up-to-date. Please re-run `#{setup}`." unless requirement.satisfied_by?(installed)
end
require 'mediawiki-vagrant/settings/definitions'
mwv = MediaWikiVagrant::Environment.new(File.expand_path('..', __FILE__))
settings = mwv.load_settings
Vagrant.configure('2') do |config|
config.vm.hostname = 'mediawiki-vagrant.dev'
config.package.name = 'mediawiki.box'
config.ssh.forward_agent = settings[:forward_agent]
config.ssh.forward_x11 = settings[:forward_x11]
# Default VirtualBox provider
config.vm.provider :virtualbox do |_vb, override|
override.vm.box = 'trusty-cloud'
override.vm.box_url = 'https://cloud-images.ubuntu.com/vagrant/trusty/current/trusty-server-cloudimg-amd64-vagrant-disk1.box'
override.vm.box_download_insecure = true
override.vm.network :private_network, ip: settings[:static_ip]
end
# VMWare Fusion provider. Enable with `--provider=vmware_fusion`
config.vm.provider :vmware_fusion do |_vw, override|
override.vm.box = 'puppetlabs/ubuntu-14.04-64-puppet'
override.vm.network :private_network, ip: settings[:static_ip]
end
# Microsoft Hyper-V provider. Enable with `--provider=hyperv`
# Not quite in 'just works' shape yet.
#
# You must run vagrant from an administrator shell to interact
# with the Hyper-V virtual machines...
#
# Note you must configure networking manually in Hyper-V Manager!
# NAT and port redirection are not automatically set up for you.
#
config.vm.provider :hyperv do |_hyperv, override|
# Our default box doesn't have Hyper-V support...
override.vm.box = 'cirex/ubuntu-14.04'
override.vm.network :private_network, ip: settings[:static_ip]
end
# LXC provider. Enable wtih `--provider=lxc`
# Requires vagrant-lxc plugin and Vagrant 1.7+
config.vm.provider :lxc do |_lxc, override|
override.vm.box = 'Wikimedia/trusty64-puppet-lxc'
end
# Parallels provider. Enable with `--provider=parallels`
#
# Requires plugins:
# * Parallels provider - http://parallels.github.io/vagrant-parallels/
# $ vagrant plugin install vagrant-parallels
# * Puppet installer - https://github.com/petems/vagrant-puppet-install
# $ vagrant plugin install vagrant-puppet-install
#
# Note that port forwarding works via localhost but not via external interfaces
# of the host machine by default...
config.vm.provider :parallels do |_parallels, override|
override.vm.box = 'parallels/ubuntu-14.04'
# Pin to a 3.x version, current as of this config writing.
override.puppet_install.puppet_version = '3.7.4'
override.vm.network :private_network, ip: settings[:static_ip]
end
config.vm.network :forwarded_port,
guest: 80, host: settings[:http_port], host_ip: settings[:host_ip],
id: 'http'
config.vm.network :forwarded_port,
guest: 443, host: settings[:https_port], host_ip: settings[:host_ip],
id: 'https'
unless settings[:forward_ports].nil?
settings[:forward_ports].each do |guest_port, host_port|
config.vm.network :forwarded_port,
host: host_port, host_ip: settings[:host_ip],
guest: guest_port, auto_correct: true
end
end
root_share_options = { id: 'vagrant-root' }
if settings[:nfs_shares]
root_share_options[:type] = :nfs
root_share_options[:mount_options] = ['noatime', 'rsize=32767', 'wsize=32767', 'async']
root_share_options[:mount_options] << 'fsc' if settings[:nfs_cache]
config.nfs.map_uid = Process.uid
config.nfs.map_gid = Process.gid
else
root_share_options[:owner] = 'vagrant'
root_share_options[:group] = 'www-data'
end
config.vm.synced_folder '.', '/vagrant', root_share_options
unless settings[:nfs_shares]
# www-data needs to write to the logs, but doesn't need write
# access for all of /vagrant
#
# Users of NFS should not need this special export because of the
# global uid/gid map used for the NFS export. Attempts from within the
# VM to chmod files and folders to www-data:www-data will fail
# however, so avoid that in puppet code and account for it in shell
# scripts.
config.vm.synced_folder './logs', '/vagrant/logs',
id: 'vagrant-logs',
owner: 'www-data',
group: 'www-data'
end
config.vm.provider :virtualbox do |vb|
# See http://www.virtualbox.org/manual/ch08.html for additional options.
vb.customize ['modifyvm', :id, '--memory', settings[:vagrant_ram]]
vb.customize ['modifyvm', :id, '--cpus', settings[:vagrant_cores]]
vb.customize ['modifyvm', :id, '--ostype', 'Ubuntu_64']
vb.customize ['modifyvm', :id, '--ioapic', 'on'] # Bug 51473
# Speed up dns resolution in some cases
vb.customize ['modifyvm', :id, '--natdnshostresolver1', 'on']
vb.customize ['modifyvm', :id, '--natdnsproxy1', 'on']
# To boot the VM in graphical mode, uncomment the following line:
# vb.gui = true
end
config.vm.provider :vmware_fusion do |vw|
vw.vmx['memsize'] = settings[:vagrant_ram]
vw.vmx['numvcpus'] = settings[:vagrant_cores]
# To boot the VM in graphical mode, uncomment the following line:
# vw.gui = true
end
config.vm.provider :lxc do |lxc|
lxc.customize 'cgroup.memory.limit_in_bytes', "#{settings[:vagrant_ram]}M"
end
config.vm.provision :lsb_check do |lsb|
lsb.version = '14.04'
end
config.vm.provision :mediawiki_reload if mwv.reload?
config.vm.provision :puppet do |puppet|
# Use empty module path to avoid an extra mount.
# See --modulepath below
puppet.module_path = []
# Tell Vagrant that the manifests are already on the guest
puppet.manifests_path = [:guest, '/vagrant/puppet/manifests']
puppet.manifest_file = 'site.pp'
puppet.options = [
'--modulepath', '/vagrant/puppet/modules',
'--hiera_config', '/vagrant/puppet/hiera.yaml',
'--verbose',
'--config_version', '/vagrant/puppet/extra/config-version',
'--logdest', "/vagrant/logs/puppet/puppet.#{mwv.commit || 'unknown'}.log",
'--logdest', 'console',
'--write-catalog-summary',
'--detailed-exitcodes',
]
# For more output, uncomment the following line:
puppet.options << '--debug' if ENV.include?('PUPPET_DEBUG')
# Windows's Command Prompt has poor support for ANSI escape sequences.
puppet.options << '--color=false' if Vagrant::Util::Platform.windows?
puppet.facter = {
'fqdn' => config.vm.hostname,
'git_user' => settings[:git_user],
'forwarded_port' => settings[:http_port],
'forwarded_https_port' => settings[:https_port],
'shared_apt_cache' => '/vagrant/cache/apt/',
'environment' => ENV['MWV_ENVIRONMENT'] || 'vagrant',
}
if settings[:http_port] != 80
puppet.facter['port_fragment'] = ":#{settings[:http_port]}"
end
if settings[:nfs_shares]
puppet.facter['share_owner'] = Process.uid
puppet.facter['share_group'] = Process.gid
else
puppet.facter['share_owner'] = 'vagrant'
puppet.facter['share_group'] = 'www-data'
end
# Derive a host IP from the configured static IP by getting the first
# usable IP in the 8-bit network
if settings[:static_ip]
network = IPAddr.new("#{settings[:static_ip]}/24")
puppet.facter['host_ip'] = network.to_range.take(2).last.to_s
end
end
end
# Migrate {apt,composer}-cache to cache/{apt,composer}
['apt', 'composer'].each do |type|
src = mwv.path("#{type}-cache")
next unless src.directory?
dst = mwv.path('cache', type)
src.each_child do |src_file|
next if src_file.directory? || src_file.basename.fnmatch?('.*')
begin
src_file.rename(dst.join(src_file.basename))
rescue
end
end
end
# Load custom Vagrantfile overrides from 'Vagrantfile-extra.rb'
# See 'support/Vagrantfile-extra.rb' for an example but make sure to folow
# the instructions in that file. In particular it is important to copy it
# to the parent directory. Editing it without copying it will only cause
# sadness.
begin
require mwv.path('Vagrantfile-extra').to_s
rescue LoadError
end