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