-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVagrantfile
47 lines (36 loc) · 1.52 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
# Plugins needed:
# vagrant plugin install vagrant-vbguest
# vagrant plugin install vagrant-librarian-chef-nochef
# Enable forwarding agent on your host machine, edit/create ~/.ssh/config and paste in:
# Host *
# ForwardAgent yes
Vagrant.configure("2") do |config|
config.vm.box = "ubuntu/trusty64"
config.ssh.forward_agent = true
# Configurate the virtual machine to use 2GB of RAM
config.vm.provider :virtualbox do |vb|
host = RbConfig::CONFIG['host_os']
if host =~ /darwin/ # MACOS
cpus = `sysctl -n hw.ncpu`.to_i
mem = `sysctl -n hw.memsize`.to_i / 1024 / 1024 / 4
elsif host =~ /linux/
cpus = `nproc`.to_i
mem = `grep 'MemTotal' /proc/meminfo | sed -e 's/MemTotal://' -e 's/ kB//'`.to_i / 1024 / 4
else # static values for Windows
cpus = 2
mem = 2048
end
vb.customize ["modifyvm", :id, "--memory", mem]
vb.customize ["modifyvm", :id, "--cpus", cpus]
end
# NFS is reported to improve performance like 10 times
# it may ask you to provide sudo password to edit /etc/exports
config.vm.network :private_network, ip: "192.168.255.225" # need to enable NFS
public_key = File.open("public_key.pub", "r").read if File.exists?("public_key.pub")
setup_script = <<-SCRIPT
ssh-keyscan localhost >> ~/.ssh/known_hosts
ssh-keyscan 127.0.0.1 >> ~/.ssh/known_hosts
SCRIPT
setup_script << "echo '#{public_key}' > ~/.ssh/authorized_keys" if public_key
config.vm.provision "shell", inline: setup_script, privileged: false
end