From 3ce8aec0393323576e85a5b07cf6881df0565e5f Mon Sep 17 00:00:00 2001 From: Marc CARRE Date: Mon, 13 Feb 2017 19:26:41 +0000 Subject: [PATCH 1/3] Removed unecessary trailing whitespaces. Noise on git diff if/when text editors remove them automatically, so might as well proactively remove them. --- Vagrantfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Vagrantfile b/Vagrantfile index 51682774..ae1da136 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -9,7 +9,7 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| config.vm.network "private_network", ip: vm_ip config.vm.provider :virtualbox do |vb| vb.memory = 2048 - configure_nat_dns(vb) + configure_nat_dns(vb) end # Disable default Vagrant shared folder, which we don't need: From 1b45e8662e210b15de9811269ec7cbd4b509ae94 Mon Sep 17 00:00:00 2001 From: Marc CARRE Date: Mon, 13 Feb 2017 19:42:41 +0000 Subject: [PATCH 2/3] Add DEPENDENCIES file and source Vagrant and tests versions from it. - One unique file to list all dependencies and dependencies' versions (except Go, currently defined in `build/Dockerfile`). - Custom versions can now be injected into Vagrant VMs. - Vagrant dev VMs, Vagrant test VMs, and `run-integration-tests.sh` all source from `DEPENDENCIES`, to keep things 'DRY'. - Vagrant versions can be overriden using environment variables, like it was possible in `run-integration-tests.sh`. --- DEPENDENCIES | 3 +++ Vagrantfile | 2 +- test/Vagrantfile | 1 + test/run-integration-tests.sh | 6 +++--- vagrant-common.rb | 14 ++++++++++++++ 5 files changed, 22 insertions(+), 4 deletions(-) create mode 100644 DEPENDENCIES diff --git a/DEPENDENCIES b/DEPENDENCIES new file mode 100644 index 00000000..c7fa49ee --- /dev/null +++ b/DEPENDENCIES @@ -0,0 +1,3 @@ +DOCKER_VERSION=1.11.2 +KUBERNETES_VERSION=1.5.2 +KUBERNETES_CNI_VERSION=0.3.0.1 \ No newline at end of file diff --git a/Vagrantfile b/Vagrantfile index ae1da136..d35b128d 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -29,7 +29,7 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| ansible.playbook = 'tools/config_management/setup_weave-net_dev.yml' ansible.extra_vars = { go_version: GO_VERSION - } + }.merge(ansibleize(get_dependencies_version_from_file_and_env())) end end diff --git a/test/Vagrantfile b/test/Vagrantfile index cae35134..dc9b3171 100644 --- a/test/Vagrantfile +++ b/test/Vagrantfile @@ -55,6 +55,7 @@ END host.vm.provision 'ansible' do |ansible| ansible.limit = 'all' # Disable default limit to connect to all the machines ansible.playbook = '../tools/config_management/setup_weave-net_test.yml' + ansible.extra_vars = ansibleize(get_dependencies_version_from_file_and_env()) end end end diff --git a/test/run-integration-tests.sh b/test/run-integration-tests.sh index 178dcd9a..1e22480d 100755 --- a/test/run-integration-tests.sh +++ b/test/run-integration-tests.sh @@ -29,9 +29,9 @@ PLAYBOOK=${PLAYBOOK:-setup_weave-net_test.yml} TESTS=${TESTS:-} RUNNER_ARGS=${RUNNER_ARGS:-""} # Dependencies' versions: -DOCKER_VERSION=${DOCKER_VERSION:-1.11.2} -KUBERNETES_VERSION=${KUBERNETES_VERSION:-1.5.2} -KUBERNETES_CNI_VERSION=${KUBERNETES_CNI_VERSION:-0.3.0.1} +DOCKER_VERSION=${DOCKER_VERSION:-"$(grep -oP "(?<=DOCKER_VERSION=).*" "$DIR/../DEPENDENCIES")"} +KUBERNETES_VERSION=${KUBERNETES_VERSION:-"$(grep -oP "(?<=KUBERNETES_VERSION=).*" "$DIR/../DEPENDENCIES")"} +KUBERNETES_CNI_VERSION=${KUBERNETES_CNI_VERSION:-"$(grep -oP "(?<=KUBERNETES_CNI_VERSION=).*" "$DIR/../DEPENDENCIES")"} # Google Cloud Platform image's name & usage (only used when PROVIDER is gcp): IMAGE_NAME=${IMAGE_NAME:-"$(echo "$APP-docker$DOCKER_VERSION-k8s$KUBERNETES_VERSION-k8scni$KUBERNETES_CNI_VERSION" | sed -e 's/[\.\_]*//g')"} DISK_NAME_PREFIX=${DISK_NAME_PREFIX:-$NAME} diff --git a/vagrant-common.rb b/vagrant-common.rb index 81afa1a1..1967052e 100644 --- a/vagrant-common.rb +++ b/vagrant-common.rb @@ -1,6 +1,20 @@ 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')) From 62c9522bf6fff1abcba84c35c97fa409d6d37f11 Mon Sep 17 00:00:00 2001 From: Marc CARRE Date: Mon, 13 Feb 2017 19:53:27 +0000 Subject: [PATCH 3/3] Fix bug in get_go_version_from_build_dockerfile. Previously, the first line of the Dockerfile would have been selected, regardless of its value. What we want is to actually select the first line matching the regex, and then extract the group corresponding to the Go version out of it. --- vagrant-common.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vagrant-common.rb b/vagrant-common.rb index 1967052e..27cfb716 100644 --- a/vagrant-common.rb +++ b/vagrant-common.rb @@ -18,7 +18,7 @@ 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).first { |line| line.match(go_regexp) }.match(go_regexp).captures.first + 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