Vagrantfile 4.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. # -*- mode: ruby -*-
  2. # vi: set ft=ruby :
  3. BOX_NAME = ENV['BOX_NAME'] || "ubuntu"
  4. BOX_URI = ENV['BOX_URI'] || "http://files.vagrantup.com/precise64.box"
  5. VF_BOX_URI = ENV['BOX_URI'] || "http://files.vagrantup.com/precise64_vmware_fusion.box"
  6. AWS_REGION = ENV['AWS_REGION'] || "us-east-1"
  7. AWS_AMI = ENV['AWS_AMI'] || "ami-d0f89fb9"
  8. FORWARD_DOCKER_PORTS = ENV['FORWARD_DOCKER_PORTS']
  9. Vagrant::Config.run do |config|
  10. # Setup virtual machine box. This VM configuration code is always executed.
  11. config.vm.box = BOX_NAME
  12. config.vm.box_url = BOX_URI
  13. config.ssh.forward_agent = true
  14. # Provision docker and new kernel if deployment was not done.
  15. # It is assumed Vagrant can successfully launch the provider instance.
  16. if Dir.glob("#{File.dirname(__FILE__)}/.vagrant/machines/default/*/id").empty?
  17. # Add lxc-docker package
  18. pkg_cmd = "wget -q -O - https://get.docker.io/gpg | apt-key add -;" \
  19. "echo deb http://get.docker.io/ubuntu docker main > /etc/apt/sources.list.d/docker.list;" \
  20. "apt-get update -qq; apt-get install -q -y --force-yes lxc-docker; "
  21. # Add Ubuntu raring backported kernel
  22. pkg_cmd << "apt-get update -qq; apt-get install -q -y linux-image-generic-lts-raring; "
  23. # Add guest additions if local vbox VM. As virtualbox is the default provider,
  24. # it is assumed it won't be explicitly stated.
  25. if ENV["VAGRANT_DEFAULT_PROVIDER"].nil? && ARGV.none? { |arg| arg.downcase.start_with?("--provider") }
  26. pkg_cmd << "apt-get install -q -y linux-headers-generic-lts-raring dkms; " \
  27. "echo 'Downloading VBox Guest Additions...'; " \
  28. "wget -q http://dlc.sun.com.edgesuite.net/virtualbox/4.2.12/VBoxGuestAdditions_4.2.12.iso; "
  29. # Prepare the VM to add guest additions after reboot
  30. pkg_cmd << "echo -e 'mount -o loop,ro /home/vagrant/VBoxGuestAdditions_4.2.12.iso /mnt\n" \
  31. "echo yes | /mnt/VBoxLinuxAdditions.run\numount /mnt\n" \
  32. "rm /root/guest_additions.sh; ' > /root/guest_additions.sh; " \
  33. "chmod 700 /root/guest_additions.sh; " \
  34. "sed -i -E 's#^exit 0#[ -x /root/guest_additions.sh ] \\&\\& /root/guest_additions.sh#' /etc/rc.local; " \
  35. "echo 'Installation of VBox Guest Additions is proceeding in the background.'; " \
  36. "echo '\"vagrant reload\" can be used in about 2 minutes to activate the new guest additions.'; "
  37. end
  38. # Add vagrant user to the docker group
  39. pkg_cmd << "usermod -a -G docker vagrant; "
  40. # Activate new kernel
  41. pkg_cmd << "shutdown -r +1; "
  42. config.vm.provision :shell, :inline => pkg_cmd
  43. end
  44. end
  45. # Providers were added on Vagrant >= 1.1.0
  46. Vagrant::VERSION >= "1.1.0" and Vagrant.configure("2") do |config|
  47. config.vm.provider :aws do |aws, override|
  48. aws.access_key_id = ENV["AWS_ACCESS_KEY_ID"]
  49. aws.secret_access_key = ENV["AWS_SECRET_ACCESS_KEY"]
  50. aws.keypair_name = ENV["AWS_KEYPAIR_NAME"]
  51. override.ssh.private_key_path = ENV["AWS_SSH_PRIVKEY"]
  52. override.ssh.username = "ubuntu"
  53. aws.region = AWS_REGION
  54. aws.ami = AWS_AMI
  55. aws.instance_type = "t1.micro"
  56. end
  57. config.vm.provider :rackspace do |rs|
  58. config.ssh.private_key_path = ENV["RS_PRIVATE_KEY"]
  59. rs.username = ENV["RS_USERNAME"]
  60. rs.api_key = ENV["RS_API_KEY"]
  61. rs.public_key_path = ENV["RS_PUBLIC_KEY"]
  62. rs.flavor = /512MB/
  63. rs.image = /Ubuntu/
  64. end
  65. config.vm.provider :vmware_fusion do |f, override|
  66. override.vm.box = BOX_NAME
  67. override.vm.box_url = VF_BOX_URI
  68. override.vm.synced_folder ".", "/vagrant", disabled: true
  69. f.vmx["displayName"] = "docker"
  70. end
  71. config.vm.provider :virtualbox do |vb|
  72. config.vm.box = BOX_NAME
  73. config.vm.box_url = BOX_URI
  74. end
  75. end
  76. if !FORWARD_DOCKER_PORTS.nil?
  77. Vagrant::VERSION < "1.1.0" and Vagrant::Config.run do |config|
  78. (49000..49900).each do |port|
  79. config.vm.forward_port port, port
  80. end
  81. end
  82. Vagrant::VERSION >= "1.1.0" and Vagrant.configure("2") do |config|
  83. (49000..49900).each do |port|
  84. config.vm.network :forwarded_port, :host => port, :guest => port
  85. end
  86. end
  87. end