Vagrantfile 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. # -*- mode: ruby -*-
  2. # vi: set ft=ruby :
  3. #
  4. LINUX_BASE_BOX = "bento/ubuntu-16.04"
  5. Vagrant.configure(2) do |config|
  6. config.vm.define "linux", autostart: true, primary: true do |vmCfg|
  7. vmCfg.vm.box = LINUX_BASE_BOX
  8. vmCfg.vm.hostname = "linux"
  9. vmCfg = configureProviders vmCfg,
  10. cpus: suggestedCPUCores()
  11. vmCfg = configureLinuxProvisioners(vmCfg)
  12. vmCfg.vm.synced_folder '.',
  13. '/opt/gopath/src/github.com/hashicorp/consul'
  14. vmCfg.vm.network "forwarded_port", guest: 8500, host: 8500, auto_correct: true
  15. end
  16. end
  17. def configureLinuxProvisioners(vmCfg)
  18. vmCfg.vm.provision "shell",
  19. privileged: true,
  20. inline: 'rm -f /home/vagrant/linux.iso'
  21. vmCfg.vm.provision "shell",
  22. privileged: true,
  23. path: './scripts/vagrant-linux-priv-go.sh'
  24. return vmCfg
  25. end
  26. def configureProviders(vmCfg, cpus: "2", memory: "2048")
  27. vmCfg.vm.provider "virtualbox" do |v|
  28. v.memory = memory
  29. v.cpus = cpus
  30. end
  31. ["vmware_fusion", "vmware_workstation"].each do |p|
  32. vmCfg.vm.provider p do |v|
  33. v.enable_vmrun_ip_lookup = false
  34. v.vmx["memsize"] = memory
  35. v.vmx["numvcpus"] = cpus
  36. end
  37. end
  38. vmCfg.vm.provider "virtualbox" do |v|
  39. v.memory = memory
  40. v.cpus = cpus
  41. end
  42. return vmCfg
  43. end
  44. def suggestedCPUCores()
  45. case RbConfig::CONFIG['host_os']
  46. when /darwin/
  47. Integer(`sysctl -n hw.ncpu`) / 2
  48. when /linux/
  49. Integer(`cat /proc/cpuinfo | grep processor | wc -l`) / 2
  50. else
  51. 2
  52. end
  53. end