Skip to content

Commit 241932c

Browse files
committed
ref(Vagrantfile): align with upstream coreos-vagrant
See "deis" fork at https://github.com/deis/coreos-vagrant
1 parent a3f9f2e commit 241932c

1 file changed

Lines changed: 91 additions & 25 deletions

File tree

Vagrantfile

Lines changed: 91 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,64 +1,130 @@
11
# -*- mode: ruby -*-
22
# # vi: set ft=ruby :
33

4-
DEIS_NUM_INSTANCES = (ENV['DEIS_NUM_INSTANCES'].to_i > 0 && ENV['DEIS_NUM_INSTANCES'].to_i) || 1
4+
require 'fileutils'
55

6-
if DEIS_NUM_INSTANCES == 1
7-
mem = 4096
8-
cpus = 2
6+
Vagrant.require_version ">= 1.6.0"
7+
8+
CLOUD_CONFIG_PATH = File.join(File.dirname(__FILE__), "contrib", "coreos", "user-data")
9+
CONFIG = File.join(File.dirname(__FILE__), "config.rb")
10+
11+
# Defaults for config options defined in CONFIG
12+
$num_instances = 1
13+
$update_channel = "alpha"
14+
$enable_serial_logging = false
15+
$vb_gui = false
16+
$vb_memory = 1024
17+
$vb_cpus = 1
18+
19+
# Attempt to apply the deprecated environment variable NUM_INSTANCES to
20+
# $num_instances while allowing config.rb to override it
21+
if ENV["NUM_INSTANCES"].to_i > 0 && ENV["NUM_INSTANCES"]
22+
$num_instances = ENV["NUM_INSTANCES"].to_i
23+
elsif ENV["DEIS_NUM_INSTANCES"].to_i > 0 && ENV["DEIS_NUM_INSTANCES"]
24+
$num_instances = ENV["DEIS_NUM_INSTANCES"].to_i
25+
else
26+
$num_instances = 3
27+
end
28+
29+
# VM sizing for Deis
30+
if $num_instances == 1
31+
$vb_memory = 4096
32+
$vb_cpus = 2
933
else
10-
mem = 2048
11-
cpus = 1
34+
$vb_memory = 2048
35+
$vb_cpus = 1
1236
end
1337

1438
COREOS_VERSION = "444.0.0"
1539

40+
if File.exist?(CONFIG)
41+
require CONFIG
42+
end
43+
1644
Vagrant.configure("2") do |config|
45+
# config.vm.box = "coreos-%s" % $update_channel
46+
# config.vm.box_version = ">= 308.0.1"
47+
# config.vm.box_url = "http://%s.release.core-os.net/amd64-usr/current/coreos_production_vagrant.json" % $update_channel
1748
config.vm.box = "coreos-#{COREOS_VERSION}"
1849
config.vm.box_url = "http://storage.core-os.net/coreos/amd64-usr/#{COREOS_VERSION}/coreos_production_vagrant.box"
1950

2051
config.vm.provider :vmware_fusion do |vb, override|
52+
# override.vm.box_url = "http://%s.release.core-os.net/amd64-usr/current/coreos_production_vagrant_vmware_fusion.json" % $update_channel
2153
override.vm.box_url = "http://storage.core-os.net/coreos/amd64-usr/#{COREOS_VERSION}/coreos_production_vagrant_vmware_fusion.box"
2254
end
2355

2456
config.vm.provider :virtualbox do |vb, override|
57+
# Use AMD Lance nic which seems less problematic than Intel
2558
vb.customize ["modifyvm", :id, "--nictype1", "Am79C973"]
2659
vb.customize ["modifyvm", :id, "--nictype2", "Am79C973"]
27-
# Fix docker not being able to resolve private registry in VirtualBox
28-
vb.customize ["modifyvm", :id, "--natdnshostresolver1", "on"]
29-
vb.customize ["modifyvm", :id, "--natdnsproxy1", "on"]
60+
end
61+
62+
config.vm.provider :virtualbox do |v|
63+
# On VirtualBox, we don't have guest additions or a functional vboxsf
64+
# in CoreOS, so tell Vagrant that so it can be smarter.
65+
v.check_guest_additions = false
66+
v.functional_vboxsf = false
3067
end
3168

3269
# plugin conflict
3370
if Vagrant.has_plugin?("vagrant-vbguest") then
3471
config.vbguest.auto_update = false
3572
end
36-
#plugin conflict
37-
if Vagrant.has_plugin?("vagrant-cachier") then
38-
config.cache.disable!
39-
end
4073

41-
(1..DEIS_NUM_INSTANCES).each do |i|
42-
config.vm.define vm_name = "deis-#{i}" do |config|
74+
(1..$num_instances).each do |i|
75+
config.vm.define vm_name = "deis-%d" % i do |config|
4376
config.vm.hostname = vm_name
4477

78+
if $enable_serial_logging
79+
logdir = File.join(File.dirname(__FILE__), "log")
80+
FileUtils.mkdir_p(logdir)
81+
82+
serialFile = File.join(logdir, "%s-serial.txt" % vm_name)
83+
FileUtils.touch(serialFile)
84+
85+
config.vm.provider :vmware_fusion do |v, override|
86+
v.vmx["serial0.present"] = "TRUE"
87+
v.vmx["serial0.fileType"] = "file"
88+
v.vmx["serial0.fileName"] = serialFile
89+
v.vmx["serial0.tryNoRxLoss"] = "FALSE"
90+
end
91+
92+
config.vm.provider :virtualbox do |vb, override|
93+
vb.customize ["modifyvm", :id, "--uart1", "0x3F8", "4"]
94+
vb.customize ["modifyvm", :id, "--uartmode1", serialFile]
95+
end
96+
end
97+
98+
if $expose_docker_tcp
99+
config.vm.network "forwarded_port", guest: 2375, host: ($expose_docker_tcp + i - 1), auto_correct: true
100+
end
101+
102+
config.vm.provider :vmware_fusion do |vb|
103+
vb.gui = $vb_gui
104+
end
105+
45106
config.vm.provider :virtualbox do |vb|
46-
vb.memory = mem
47-
vb.cpus = cpus
107+
vb.gui = $vb_gui
108+
vb.memory = $vb_memory
109+
vb.cpus = $vb_cpus
48110
end
49111

50112
ip = "172.17.8.#{i+99}"
51113
config.vm.network :private_network, ip: ip
52114

53-
# user-data bootstrapping
54-
config.vm.provision :file, :source => "contrib/coreos/user-data", :destination => "/tmp/vagrantfile-user-data"
55-
# check that the CoreOS user-data file is valid
56-
config.vm.provision :shell do |s|
57-
s.path = "contrib/util/check-user-data.sh"
58-
s.args = ["/tmp/vagrantfile-user-data", "#{DEIS_NUM_INSTANCES}"]
115+
# Uncomment below to enable NFS for sharing the host machine into the coreos-vagrant VM.
116+
#config.vm.synced_folder ".", "/home/core/share", id: "core", :nfs => true, :mount_options => ['nolock,vers=3,udp']
117+
118+
if File.exist?(CLOUD_CONFIG_PATH)
119+
config.vm.provision :file, :source => "#{CLOUD_CONFIG_PATH}", :destination => "/tmp/vagrantfile-user-data"
120+
# check that the CoreOS user-data file is valid
121+
config.vm.provision :shell do |s|
122+
s.path = File.join(File.dirname(__FILE__), "contrib", "util", "check-user-data.sh")
123+
s.args = ["/tmp/vagrantfile-user-data", $num_instances]
124+
end
125+
config.vm.provision :shell, :inline => "mv /tmp/vagrantfile-user-data /var/lib/coreos-vagrant/", :privileged => true
59126
end
60-
config.vm.provision :shell, :inline => "mv /tmp/vagrantfile-user-data /var/lib/coreos-vagrant/", :privileged => true
127+
61128
end
62129
end
63-
64130
end

0 commit comments

Comments
 (0)