-
Notifications
You must be signed in to change notification settings - Fork 316
/
Vagrantfile
100 lines (80 loc) · 3.44 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
# -*- mode: ruby -*-
# vi: set ft=ruby :
# Load in custom vagrant settings
raise <<-EOF unless File.exists?("vagrant.yml")
Hi! Before getting started with Vagrant and Coderwall
you'll need to setup the `vagrant.yml`. There should
be a file `vagrant.yml.example` that you can use as
a base reference. Copy the `vagrant.yml.example` to
`vagrant.yml` to get started.
EOF
require 'yaml'
custom_settings = File.file?('vagrant.yml') ? YAML.load_file('vagrant.yml') : {}
if ENV['VAGRANT_DEBUG']
puts '== Using Custom Vagrant Settings =='
puts custom_settings.inspect
end
VAGRANTFILE_API_VERSION = "2"
$box = 'coderwall_v3'
$box_url = 'https://s3.amazonaws.com/coderwall-assets-0/vagrant/coderwall_v3.box' # The box is 1.4GB.
$provision = 'vagrant/bootstrap.sh'
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.box = $box
config.vm.box_url = $box_url
config.vm.provision :shell do |s|
s.path = $provision
end
config.ssh.keep_alive = true
config.ssh.forward_agent = true
config.vm.network :private_network, ip: '192.168.237.95' # 192.168.cdr.wl
set_port_mapping_for(config, 'elasticsearch', 9200, custom_settings)
set_port_mapping_for(config, 'postgres', 5432, custom_settings)
set_port_mapping_for(config, 'redis', 6379, custom_settings)
set_port_mapping_for(config, 'rails', 3000, custom_settings, true)
config.vm.synced_folder '.', '/home/vagrant/web', nfs: custom_settings['use_nfs']
config.vm.provider :virtualbox do |vb|
# Use custom settings unless they don't exist
if virtualbox_settings = custom_settings['virtualbox']
vb.customize ['modifyvm', :id, '--cpus', "#{virtualbox_settings['cpus'] || 2}"]
vb.customize ['modifyvm', :id, '--memory', "#{virtualbox_settings['memory'] || 2048}"]
else
vb.customize ['modifyvm', :id, '--cpus', '2']
vb.customize ['modifyvm', :id, '--memory', '2048']
end
vb.customize ['modifyvm', :id, '--ioapic', 'on']
# https://github.com/mitchellh/vagrant/issues/1807
# whatupdave: my VM was super slow until I added these:
vb.customize ["modifyvm", :id, "--natdnshostresolver1", "on"]
vb.customize ["modifyvm", :id, "--natdnsproxy1", "on"]
# seems to be safe to run: https://github.com/griff/docker/commit/e5239b98598ece4287c1088e95a2eaed585d2da4
end
if Vagrant.has_plugin?('vagrant-vbguest')
config.vbguest.auto_update = true
config.vbguest.no_remote = false
else
puts "Please install the 'vagrant-vbguest' plugin"
end
if Vagrant.has_plugin?('vagrant-cachier')
config.cache.scope = :box
else
puts "Please install the 'vagrant-cachier' plugin"
end
end
def set_port_mapping_for(config, service, guest_port, settings, force = false)
if settings['network'] && settings['network']['port_mappings'] && settings['network']['port_mappings'][service]
host_port = settings['network']['port_mappings'][service]
if ENV['VAGRANT_DEBUG']
puts " !! Setting up port mapping rule for #{service} host:#{host_port} => guest:#{guest_port}"
end
config.vm.network(:forwarded_port, guest: guest_port, host: host_port)
else
# no host port mapping was defined
if force
# but we want to force a mapping for the default ports
if ENV['VAGRANT_DEBUG']
puts " !! Setting up port mapping rule for #{service} host:#{guest_port} => guest:#{guest_port}"
end
config.vm.network(:forwarded_port, guest: guest_port, host: guest_port)
end
end
end