From e5185e73ce3b3df4b1ac55bcebfa49d7c3a6fe8c Mon Sep 17 00:00:00 2001 From: Marc CARRE Date: Tue, 17 Jan 2017 17:16:08 +0000 Subject: [PATCH] Refactor Vagrant configuration. --- Vagrantfile | 11 ++++++----- test/Vagrantfile | 8 +++----- vagrant-common.rb | 32 ++++++++++++++++++++++---------- 3 files changed, 31 insertions(+), 20 deletions(-) diff --git a/Vagrantfile b/Vagrantfile index 24871afd..a7077293 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -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" diff --git a/test/Vagrantfile b/test/Vagrantfile index 691c5075..281785f7 100644 --- a/test/Vagrantfile +++ b/test/Vagrantfile @@ -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 diff --git a/vagrant-common.rb b/vagrant-common.rb index 125abeea..001dc8ea 100644 --- a/vagrant-common.rb +++ b/vagrant-common.rb @@ -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 => <