From 1b45e8662e210b15de9811269ec7cbd4b509ae94 Mon Sep 17 00:00:00 2001 From: Marc CARRE Date: Mon, 13 Feb 2017 19:42:41 +0000 Subject: [PATCH] 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'))