forked from weaveworks/weave
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vagrant-common.rb
45 lines (39 loc) · 1.5 KB
/
vagrant-common.rb
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
VAGRANT_IMAGE = 'bento/ubuntu-16.04'
VAGRANTFILE_API_VERSION = '2'
def get_dependencies_version_from_file_and_env()
dependencies_file = File.join(File.dirname(__FILE__), 'DEPENDENCIES')
# Read default version from the DEPENDENCIES file:
versions = File.readlines(dependencies_file).map{|line| line.strip.split('=')}.to_h
# Override with environment variables if defined:
versions.each do |k,v|
versions[k] = ENV.key?(k) ? ENV[k] : v
end
end
def ansibleize(h)
h.map{|k,v| [k.downcase, v]}.to_h
end
def get_go_version_from_build_dockerfile()
go_regexp = /FROM golang:(\S*).*?/
dockerfile_path = File.expand_path(File.join(File.dirname(__FILE__), 'build', 'Dockerfile'))
go_version = File.readlines(dockerfile_path).select { |line| line.match(go_regexp) }.first.match(go_regexp).captures.first
if go_version.nil?
raise ArgumentError.new("Failed to read Go version from Dockerfile.")
end
go_version
end
GO_VERSION = get_go_version_from_build_dockerfile()
def configure_nat_dns(vb)
vb.customize ["modifyvm", :id, "--natdnshostresolver1", "off"]
vb.customize ["modifyvm", :id, "--natdnsproxy1", "off"]
end
def cleanup(vm)
vm.provision :shell, :inline => <<SCRIPT
export DEBIAN_FRONTEND=noninteractive
## Who the hell thinks official images have to have both of these?
[ ! -f /etc/init.d/chef-client ] || /etc/init.d/chef-client stop
[ ! -f /etc/init.d/puppet ] || /etc/init.d/puppet stop
apt-get -qq remove puppet chef
apt-get -qq autoremove
killall -9 chef-client 2>/dev/null || true
SCRIPT
end