Skip to content

Instantly share code, notes, and snippets.

@bangpound
Created May 10, 2017 01:58
Show Gist options
  • Save bangpound/078d02bc86f0e8d1e4b83ec6b85a20aa to your computer and use it in GitHub Desktop.
Save bangpound/078d02bc86f0e8d1e4b83ec6b85a20aa to your computer and use it in GitHub Desktop.
# vim: set ft=ruby:
# port on VM => port on host machine
port_mapping = {
80 => 8080,
443 => 4343,
1004 => 8081,
9200 => 9201,
}
Vagrant.configure("2") do |config|
config.vm.box = "bento/centos-7.2"
config.vm.box_url = "bento/centos-7.2"
port_mapping.each do |guest_port, host_port|
config.vm.network :forwarded_port, {
:guest => guest_port,
:host => host_port,
}
end
config.vm.provision "chef_solo", run: "always" do |chef|
chef.channel = 'stable'
chef.version = '12.9.41'
chef.cookbooks_path = "dev/provision/cookbooks"
chef.json = {
:memcache_host => "localhost",
:sessions_host => "localhost",
:mysql_prod_user => "root",
:mysql_prod_pass => '',
:mysql_core_host => "localhost",
:mysql_core_user => "root",
:mysql_core_pass => "",
:php_version => "5.6w",
:redis_host => "localhost",
:skip_archive_app => true
}
chef.add_recipe "localdev"
end
config.vm.provision "ansible" do |ansible|
ansible.playbook = "playbook.yml"
end
config.vm.provider :vmware_fusion do |v|
v.gui = false
v.customize ["modifyvm", :id, "--natdnshostresolver1", "on"]
v.customize ["modifyvm", :id, "--natdnsproxy1", "on"]
v.vmx["memsize"] = ram
v.vmx["numvcpus"] = cpus
end
config.vm.provider :virtualbox do |v|
v.gui = false
v.memory = ram
v.cpus = cpus
end
config.vm.network :private_network, ip: "10.11.12.13"
config.vm.synced_folder ".", "/vagrant", {
:nfs => {:mount_options => ['dmode=777,fmode=666']},
}
config.ssh.forward_agent = true
# Enable port forwarding on startup
config.trigger.after [:provision, :up, :reload] do
system(
'echo "
rdr pass on lo0 inet proto tcp from any to 127.0.0.1 port 80 -> 127.0.0.1 port 8080
rdr pass on lo0 inet proto tcp from any to 127.0.0.1 port 443 -> 127.0.0.1 port 4343
" | sudo pfctl -ef - > /dev/null 2>&1; echo "==> Fowarding Ports: 80 -> 8080, 443 -> 4343 & Enabling pf"'
)
end
# Disable port forwarding on shutdown
config.trigger.after [:halt, :destroy] do
system("sudo pfctl -df /etc/pf.conf > /dev/null 2>&1; echo '==> Removing Port Forwarding & Disabling pf'")
end
end
def cpus
`sysctl -n hw.ncpu`.to_i / 2 # 1/2 of your laptop's total cores
end
def ram
cpus * 2 * 1024 # 2G per VCPU
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment