github.com/didip/deis@v1.4.1/Vagrantfile (about) 1 # -*- mode: ruby -*- 2 # # vi: set ft=ruby : 3 4 require 'fileutils' 5 6 Vagrant.require_version ">= 1.6.5" 7 8 unless Vagrant.has_plugin?("vagrant-triggers") 9 raise Vagrant::Errors::VagrantError.new, "Please install the vagrant-triggers plugin running 'vagrant plugin install vagrant-triggers'" 10 end 11 12 CLOUD_CONFIG_PATH = File.join(File.dirname(__FILE__), "contrib", "coreos", "user-data") 13 CONFIG = File.join(File.dirname(__FILE__), "config.rb") 14 15 # Defaults for config options defined in CONFIG 16 $num_instances = 1 17 $instance_name_prefix = "deis" 18 $update_channel = ENV["COREOS_CHANNEL"] || "stable" 19 $enable_serial_logging = false 20 $share_home = false 21 $vm_gui = false 22 $vm_memory = 2048 23 $vm_cpus = 1 24 25 # Attempt to apply the deprecated environment variable NUM_INSTANCES to 26 # $num_instances while allowing config.rb to override it 27 if ENV["NUM_INSTANCES"].to_i > 0 && ENV["NUM_INSTANCES"] 28 $num_instances = ENV["NUM_INSTANCES"].to_i 29 elsif ENV["DEIS_NUM_INSTANCES"].to_i > 0 && ENV["DEIS_NUM_INSTANCES"] 30 $num_instances = ENV["DEIS_NUM_INSTANCES"].to_i 31 else 32 $num_instances = 3 33 end 34 35 if File.exist?(CONFIG) 36 require CONFIG 37 end 38 39 # Use old vb_xxx config variables when set 40 def vm_gui 41 $vb_gui.nil? ? $vm_gui : $vb_gui 42 end 43 44 def vm_memory 45 $vb_memory.nil? ? $vm_memory : $vb_memory 46 end 47 48 def vm_cpus 49 $vb_cpus.nil? ? $vm_cpus : $vb_cpus 50 end 51 52 Vagrant.configure("2") do |config| 53 # always use Vagrants insecure key 54 config.ssh.insert_key = false 55 56 config.vm.box = "coreos-%s" % $update_channel 57 config.vm.box_version = ">= 557.2.0" 58 config.vm.box_url = "http://%s.release.core-os.net/amd64-usr/current/coreos_production_vagrant.json" % $update_channel 59 60 ["vmware_fusion", "vmware_workstation"].each do |vmware| 61 config.vm.provider vmware do |v, override| 62 override.vm.box_url = "http://%s.release.core-os.net/amd64-usr/current/coreos_production_vagrant_vmware_fusion.json" % $update_channel 63 end 64 end 65 66 config.vm.provider :virtualbox do |v| 67 # On VirtualBox, we don't have guest additions or a functional vboxsf 68 # in CoreOS, so tell Vagrant that so it can be smarter. 69 v.check_guest_additions = false 70 v.functional_vboxsf = false 71 end 72 73 # plugin conflict 74 if Vagrant.has_plugin?("vagrant-vbguest") then 75 config.vbguest.auto_update = false 76 end 77 78 config.trigger.before :up do 79 if !File.exists?(CLOUD_CONFIG_PATH) || File.readlines(CLOUD_CONFIG_PATH).grep(/#\s*discovery:/).any? 80 raise Vagrant::Errors::VagrantError.new, "Run 'make discovery-url' first to create user-data." 81 end 82 end 83 84 (1..$num_instances).each do |i| 85 config.vm.define vm_name = "%s-%02d" % [$instance_name_prefix, i] do |config| 86 config.vm.hostname = vm_name 87 88 if $enable_serial_logging 89 logdir = File.join(File.dirname(__FILE__), "log") 90 FileUtils.mkdir_p(logdir) 91 92 serialFile = File.join(logdir, "%s-serial.txt" % vm_name) 93 FileUtils.touch(serialFile) 94 95 ["vmware_fusion", "vmware_workstation"].each do |vmware| 96 config.vm.provider vmware do |v, override| 97 v.vmx["serial0.present"] = "TRUE" 98 v.vmx["serial0.fileType"] = "file" 99 v.vmx["serial0.fileName"] = serialFile 100 v.vmx["serial0.tryNoRxLoss"] = "FALSE" 101 end 102 end 103 104 config.vm.provider :virtualbox do |vb, override| 105 vb.customize ["modifyvm", :id, "--uart1", "0x3F8", "4"] 106 vb.customize ["modifyvm", :id, "--uartmode1", serialFile] 107 end 108 end 109 110 if $expose_docker_tcp 111 config.vm.network "forwarded_port", guest: 2375, host: ($expose_docker_tcp + i - 1), auto_correct: true 112 end 113 114 ["vmware_fusion", "vmware_workstation"].each do |vmware| 115 config.vm.provider vmware do |v| 116 v.gui = vm_gui 117 v.vmx['memsize'] = vm_memory 118 v.vmx['numvcpus'] = vm_cpus 119 end 120 end 121 122 config.vm.provider :virtualbox do |vb| 123 vb.gui = vm_gui 124 vb.memory = vm_memory 125 vb.cpus = vm_cpus 126 end 127 128 ip = "172.17.8.#{i+99}" 129 config.vm.network :private_network, ip: ip 130 131 # Uncomment below to enable NFS for sharing the host machine into the coreos-vagrant VM. 132 #config.vm.synced_folder ".", "/home/core/share", id: "core", :nfs => true, :mount_options => ['nolock,vers=3,udp'] 133 134 if $share_home 135 config.vm.synced_folder ENV['HOME'], ENV['HOME'], id: "home", :nfs => true, :mount_options => ['nolock,vers=3,udp'] 136 end 137 138 if File.exist?(CLOUD_CONFIG_PATH) 139 config.vm.provision :file, :source => "#{CLOUD_CONFIG_PATH}", :destination => "/tmp/vagrantfile-user-data" 140 # check that the CoreOS user-data file is valid 141 config.vm.provision :shell do |s| 142 s.path = File.join(File.dirname(__FILE__), "contrib", "util", "check-user-data.sh") 143 s.args = ["/tmp/vagrantfile-user-data", $num_instances] 144 end 145 config.vm.provision :shell, :inline => "mv /tmp/vagrantfile-user-data /var/lib/coreos-vagrant/", :privileged => true 146 else 147 config.vm.provision :shell do |s| 148 s.inline = "echo \"File not found: #{CLOUD_CONFIG_PATH}\" &&" + 149 "echo \"Run 'make discovery-url' first to create user-data.\" && exit 1" 150 end 151 end 152 153 end 154 end 155 end