-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVagrantfile
57 lines (44 loc) · 1.56 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
# -*- mode: ruby -*-
# vi: set ft=ruby :
# 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|
# base box
config.vm.box = "ubuntu/trusty64"
# provisioning script
config.vm.provision :shell, :path => "bootstrap.sh"
# ssh forwarding
config.ssh.forward_agent = true
# port forwarding
config.vm.network :forwarded_port, guest: 4000, host: 8080
# allocate system CPUs and RAM
config.vm.provider :virtualbox do |vb|
host = RbConfig::CONFIG['host_os']
# give VM access to all cpu cores on host
if host =~ /darwin/
cpus = `sysctl -n hw.ncpu`.to_i
elsif host =~ /linux/
cpus = `nproc`.to_i
else
cpus = 2
end
mem = 1024
vb.customize ["modifyvm", :id, "--memory", mem]
vb.customize ["modifyvm", :id, "--cpus", cpus]
vb.name = "ittybitty"
end
# restart services on up
config.trigger.after [:up], :stdout => true do
system('vagrant ssh -c "sudo service postgresql restart"')
end
# enable port forwarding on up, reload & provision
config.trigger.after [:up, :reload, :provision], :stdout => true do
system('echo "
rdr pass inet proto tcp from any to any port 80 -> 127.0.0.1 port 8080
" | sudo pfctl -ef - >/dev/null 2>&1; echo "Add Port Forwarding (80 => 8080)"')
end
# disable port forwarding on halt & destroy
config.trigger.after [:halt, :destroy], :stdout => true do
system("sudo pfctl -f /etc/pf.conf > /dev/null 2>&1; echo '==> Removing Port Forwarding'")
end
end