Refactor Vagrant configuration.

This commit is contained in:
Marc CARRE committed 2017-02-08 14:15:59 +00:00
1 parent 17ada094f8
commit e5185e73ce
3 files changed
+31 -20

No files matched your search

Vendored
+6 -5
View File
@@ -1,5 +1,3 @@
VAGRANTFILE_API_VERSION = "2"
require File.expand_path(File.join(File.dirname(__FILE__), 'vagrant-common.rb'))
vm_ip = "172.16.0.3" # arbitrary private IP
@@ -19,17 +17,20 @@ pkgs = %w(
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.box = "ubuntu/wily64"
config.vm.box = VAGRANT_IMAGE
config.vm.network "private_network", ip: vm_ip
config.vm.provider :virtualbox do |vb|
vb.memory = 2048
vb.customize ["modifyvm", :id, "--natdnshostresolver1", "off"]
vb.customize ["modifyvm", :id, "--natdnsproxy1", "off"]
configure_nat_dns(vb)
end
# Disable default Vagrant shared folder, which we don't need:
config.vm.synced_folder ".", "/vagrant", disabled: true
# Keep Weave Net sources' in sync:
config.vm.synced_folder ".", "/home/vagrant/src/github.com/weaveworks/weave"
# Create a convenience symlink to $HOME/src/github.com/weaveworks/weave
config.vm.provision :shell, :inline => 'ln -sf ~vagrant/src/github.com/weaveworks/weave ~vagrant/'
# Set SSH keys up to be able to run smoke tests straightaway:
config.vm.provision "file", source: "~/.vagrant.d/insecure_private_key", destination: "/home/vagrant/src/github.com/weaveworks/weave/test/insecure_private_key"
+3 -5
View File
@@ -1,5 +1,3 @@
VAGRANTFILE_API_VERSION = "2"
# Necessary because the switch disabling unwanted insecure key
# replacement in Vagrant 1.7+ is not accepted by earlier versions
Vagrant.require_version ">= 1.7.0"
@@ -14,11 +12,12 @@ require File.expand_path(File.join(File.dirname(__FILE__), '..', 'vagrant-common
def configure_docker(host, hostname, ip)
pkgs = %w(docker-engine ethtool)
host.vm.box = "ubuntu/wily64"
host.vm.box = VAGRANT_IMAGE
host.vm.provision :shell, :inline => "hostnamectl set-hostname "+hostname
host.vm.network "private_network", ip: ip
# Disable default Vagrant shared folder, which we don't need:
host.vm.synced_folder ".", "/vagrant", disabled: true
host.vm.provision :shell, :inline => "sudo apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys 58118E89F3A912897C070ADBF76221572C52609D"
@@ -38,9 +37,8 @@ end
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.provider :virtualbox do |vb|
vb.customize ["modifyvm", :id, "--natdnshostresolver1", "off"]
vb.customize ["modifyvm", :id, "--natdnsproxy1", "off"]
vb.memory = 384
configure_nat_dns(vb)
end
# Disable Vagrant 1.7 per host insecure key replacement
+22 -10
View File
@@ -1,11 +1,23 @@
$go_regexp = /FROM golang:(\S*).*?/
$dockerfile_path = File.expand_path(File.join(File.dirname(__FILE__), 'build', 'Dockerfile'))
$go_version = File.readlines($dockerfile_path).first { |line| line.match($go_regexp) }.match($go_regexp).captures.first
if $go_version.nil?
raise ArgumentError.new("Failed to read Go version from Dockerfile.")
VAGRANT_IMAGE = 'ubuntu/wily64'
VAGRANTFILE_API_VERSION = '2'
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).first { |line| line.match(go_regexp) }.match(go_regexp).captures.first
if go_version.nil?
raise ArgumentError.new("Failed to read Go version from Dockerfile.")
end
go_version
end
$go_path = "/usr/local/go/bin"
GO_BINARY_PATH = '/usr/local/go/bin'
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 install_packages(vm, pkgs)
vm.provision :shell, :inline => <<SCRIPT
@@ -28,10 +40,10 @@ end
def install_go_toochain(vm)
vm.provision :shell, :inline => <<SCRIPT
curl -s https://storage.googleapis.com/golang/go#{$go_version}.linux-amd64.tar.gz \
curl -s https://storage.googleapis.com/golang/go#{GO_VERSION}.linux-amd64.tar.gz \
| tar xz -C /usr/local
#{$go_path}/go clean -i net
#{$go_path}/go install -tags netgo std
#{GO_BINARY_PATH}/go clean -i net
#{GO_BINARY_PATH}/go install -tags netgo std
SCRIPT
end
@@ -39,7 +51,7 @@ def tweak_user_env(vm)
script = <<SCRIPT
echo 'export GOPATH="${HOME}"' \
>> ~vagrant/.profile
echo 'export PATH="${HOME}/bin:#{$go_path}:${PATH}"' \
echo 'export PATH="${HOME}/bin:#{GO_BINARY_PATH}:${PATH}"' \
>> ~vagrant/.profile
ln -sf ~vagrant/src/github.com/weaveworks/weave ~vagrant/
sudo chown -R vagrant:vagrant ~vagrant/src