-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathVagrantfile
225 lines (193 loc) · 7.84 KB
/
Vagrantfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
# -*- mode: ruby -*-
# vi: set ft=ruby :
#####################################################################
# Checks
keybase_root = nil
if File.directory?("/keybase/team")
keybase_root = "/keybase"
elsif File.directory?("k:/team")
keybase_root = "k:"
else
puts "WARNING: Required keybase.io VirtualFS is not present"
puts " On Linux and OSX, KeybaseFS would be mounted under /keybase"
puts " On Windows, KeybaseFS would be mounted under k:"
puts "This Vagrant automation as well as virtual machine configuration"
puts " depend on the secrets in keybase.io"
exit 1
end
#####################################################################
# Enviroment Configuration Settings
# These settings may be overriden via Environment Variables
KDK_VERSION = "v0.1.0"
KDK_NAME = "k8s-devkit-#{KDK_VERSION}"
def env(name)
# Returns string from enviroment first, otherwise the variable value
return ENV[name] || eval("#{name}")
end
#####################################################################
# Manage Plugins
# Install Vagrant plugins if they are NOT already installed.
install_plugins = %w( vagrant-disksize vagrant-proxyconf )
_retry = false
install_plugins.each do |plugin|
unless Vagrant.has_plugin? plugin
system "vagrant plugin install #{plugin}"
_retry=true
end
end
if (_retry)
exec "vagrant " + ARGV.join(' ')
end
# Remove Vagrant plugins if they ARE already installed.
# Force uninstall of vagrant-vbguest. On vbox 5.2.12 working on the bento
# centos7 image, it uninstalls the existing vbox-additions 5.2.6 and then
# fails to install vbox-additions 5.2.12 because it fails to install
# kernel-devel package most likely becuase of lack of yum update.
# Re-enable once re-tested in a few months.
remove_plugins = %w( vagrant-vbguest )
_retry = false
remove_plugins.each do |plugin|
if Vagrant.has_plugin? plugin
system "vagrant plugin uninstall #{plugin}"
_retry=true
end
end
if (_retry)
exec "vagrant " + ARGV.join(' ')
end
#####################################################################
# Configuration file
require 'yaml'
custom = nil
custom_configs = %w( config.yaml config.yaml.default ) # order matters
custom_configs.each { |filename|
filepath = File.dirname(File.expand_path(__FILE__)) + "/" + filename
if File.exist?(filepath)
custom = YAML.load_file(filepath)
break
end
}
if custom.nil?
puts "Unable to location configuration file. One of the following must exist"
puts custom_configs
exit 1
end
#####################################################################
# All Vagrant configuration is done below. The "2" in Vagrant.configure
# configures the configuration version (we support older styles for
# backwards compatibility). Please don't change it unless you know what
# you're doing.
Vagrant.configure("2") do |config|
# Set the hostname for this instance
# config.vm.hostname = "kdk"
# Network Configuration (setups up second interface to be bridged net, eth0 remains NAT)
if custom.key?('network') && custom['network']['type'] == "public"
config.vm.network "public_network",
bridge: [ custom['network']['bridge'] ],
ip: custom['network']['address'],
auto_config: false
config.vm.provision "shell", run: "always" do |shell|
shell.privileged = false
shell.env = {
"PUBLIC_NETWORK_GATEWAY" => custom['network']['gateway'],
"PUBLIC_NETWORK_INTERFACE" => custom['network']['interface']
}
shell.inline = <<-SHELL
sudo systemctl stop NetworkManager.service
sudo route add default gw $PUBLIC_NETWORK_GATEWAY $PUBLIC_NETWORK_INTERFACE
SHELL
end
else # network.type == "private"
# Only forward host ports to vagrant machine ports for private networks
# config.vm.network "forwarded_port", guest: 80, host: 10080
# config.vm.network "forwarded_port", guest: 443, host: 10443
# config.vm.network "forwarded_port", guest: 8080, host: 18080
end
# Set box disk size.
config.disksize.size = '64GB'
# The most common configuration options are documented and commented below.
# For a complete reference, please see the online documentation at
# https://docs.vagrantup.com.
# Every Vagrant development environment requires a box. You can search for
# boxes at https://vagrantcloud.com/search.
config.vm.box = "bento/centos-7.4"
# Create a forwarded port mapping which allows access to a specific port
# within the machine from a port on the host machine. In the example below,
# accessing "localhost:8080" will access port 80 on the guest machine.
# NOTE: This will enable public access to the opened port
# config.vm.network "forwarded_port", guest: 80, host: 8080
# Create a forwarded port mapping which allows access to a specific port
# within the machine from a port on the host machine and only allow access
# via 127.0.0.1 to disable public access
# config.vm.network "forwarded_port", guest: 80, host: 8080, host_ip: "127.0.0.1"
# Create a private network, which allows host-only access to the machine
# using a specific IP.
# config.vm.network "private_network", ip: "192.168.33.10"
# Create a public network, which generally matched to bridged network.
# Bridged networks make the machine appear as another physical device on
# your network.
# config.vm.network "public_network"
## Mount KeybaseFS directories
## ATTENTION: Requires Keybase client activation/sign-in on host OS.
require 'pathname'
keybase_dirs = [ "private", "public", "team" ]
keybase_dirs.each { |dir|
# realpath needed to resolve keybase symlinks
from_host = String(Pathname.new(keybase_root + "/" + dir).realpath)
to_guest = "/keybase/" + dir
if File.directory?(from_host)
# parent dirs to be auto-created by synced_folder mount
config.vm.synced_folder from_host, to_guest, mount_options: ["dmode=700,fmode=600"]
else
puts "WARNING: Failed to mount keybase.io VirtualFS"
puts " from_host: " + from_host
puts " to_guest: " + to_guest
end
}
# Mount user-defined directories if they exist
## Place to store your "Dev" stuff.
custom['shared_folder_mounts'].each { |mount|
from_host = File.expand_path(mount['from_host'])
to_guest = mount['to_guest']
if File.directory?(from_host)
# parent dirs to be auto-created by synced_folder mount
config.vm.synced_folder from_host, to_guest
else
puts "WARNING: Will skip mounting of non-existent optional host directory"
puts " from_host: " + from_host
puts " to_guest: " + to_guest
end
}
# Share an additional folder to the guest VM. The first argument is
# the path on the host to the actual folder. The second argument is
# the path on the guest to mount the folder. And the optional third
# argument is a set of non-required options.
# config.vm.synced_folder "../data", "/vagrant_data"
# Provider-specific configuration so you can fine-tune various
# backing providers for Vagrant. These expose provider-specific options.
config.vm.provider "virtualbox" do |vb|
vb.memory = 4000 # Megabytes
vb.cpus = 2 # CPU Cores
vb.customize ["modifyvm", :id, "--cableconnected1", "on"]
end
# Enable ssh-agent forwarding.
config.ssh.forward_agent = true
# Enable SSH X11 forwarding.
config.ssh.forward_x11 = true
# Run shell script to prepare Vagrant VM.
config.vm.provision "shell" do |shell|
shell.privileged = false
shell.path = "provision.sh"
shell.env = {
"KDK_NAME" => env('KDK_NAME'),
"KDK_VERSION" => env('KDK_VERSION'),
"SSH_AUTH_SOCK" => "${SSH_AUTH_SOCK}"
}
end
# If host OS has proxy variables set, configure guest accordingly.
if Vagrant.has_plugin?("vagrant-proxyconf")
config.proxy.http = ENV['HTTP_PROXY']
config.proxy.https = ENV['HTTPS_PROXY']
config.proxy.no_proxy = ENV['NO_PROXY']
end
end