Skip to content

Commit 5c2686b

Browse files
authored
Retrieve latest vagrant version if not specified (#36)
Identify the latest vagrant version available without needing vagrant installed by querying hashicorp's provided remote API for the current version the tool available.
1 parent 681ffcd commit 5c2686b

File tree

4 files changed

+14
-27
lines changed

4 files changed

+14
-27
lines changed

.github/workflows/distro-install.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ jobs:
4040
echo "QA_VAGRANT_LIBVIRT_VERSION=git-$(git submodule status -- vagrant-libvirt | cut -d' ' -f2)" >> ${GITHUB_ENV}
4141
- name: Set up libvirt
4242
run: |
43-
./scripts/install.bash --vagrant-only -- 2.2.19
43+
./scripts/install.bash --vagrant-only
4444
- uses: actions/[email protected]
4545
with:
4646
path: ~/.vagrant.d/boxes

Vagrantfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ require_relative './boxes.rb'
77

88
def add_test_provisions(vm)
99
# Workarond for Vagrant bug
10-
if Gem::Version.new(QA_VAGRANT_VERSION) < Gem::Version.new('1.9.1')
10+
if Gem::Version.new(Vagrant::VERSION) < Gem::Version.new('1.9.1')
1111
vm.provision :shell, :inline => <<-EOC
1212
for i in /opt/vagrant/embedded/gems/gems/vagrant-*/plugins/guests/tinycore/guest.rb
1313
do

boxes.rb

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,5 @@
11
#!/usr/bin/ruby
22
#
3-
# Allow for passing test versions with env vars
4-
if ENV['QA_VAGRANT_VERSION'].nil? || ENV['QA_VAGRANT_VERSION'] == "latest"
5-
# If not specified, fetch the latest version using built-in 'version' plugin
6-
#
7-
# NOTE: we 'cd /tmp' to avoid invoking Vagrant against this very Vagrantfile but
8-
# that may not always work. There is probably a better way by leveraging
9-
# VagrantPlugins::CommandVersion::Command and using 'version-latest'
10-
#
11-
latest = `cd /tmp; vagrant version | grep Latest | awk '{ print $3 }'`
12-
QA_VAGRANT_VERSION = latest.strip
13-
else
14-
QA_VAGRANT_VERSION = ENV['QA_VAGRANT_VERSION']
15-
end
163

174
APT_ENV_VARS = {
185
'DEBIAN_FRONTEND': 'noninteractive',
@@ -83,7 +70,7 @@
8370
}
8471

8572
DEFAULT_PROVISION = [
86-
{:name => 'install script', :privileged => false, :path => './scripts/install.bash', :args => "--vagrant-version #{QA_VAGRANT_VERSION}", :env => INSTALL_ENV_VARS},
73+
{:name => 'install script', :privileged => false, :path => './scripts/install.bash', :args => ENV['QA_VAGRANT_VERSION'].nil? ? "" : "--vagrant-version #{ENV['QA_VAGRANT_VERSION']}", :env => INSTALL_ENV_VARS},
8774
{:name => 'setup group', :reset => true, :inline => 'usermod -a -G libvirt vagrant'},
8875
{:name => 'debug system capabilities', :privileged => false, :inline => 'virsh --connect qemu:///system capabilities'},
8976
{:name => 'debug uri', :privileged => false, :inline => 'virsh uri'},

scripts/install.bash

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ function setup_arch() {
4747
pkg-config \
4848
qemu \
4949
ruby \
50+
wget \
5051
;
5152
sudo systemctl enable --now libvirtd
5253
}
@@ -332,6 +333,8 @@ function install_vagrant() {
332333
local distro=${2}
333334
local distro_version=${3:-}
334335

336+
echo "Installing vagrant version '${version}'"
337+
335338
eval install_vagrant_${distro} ${version}
336339

337340
if [[ -n "${distro_version}" ]] && [[ $(type -t patch_vagrant_${distro}_${distro_version} 2>/dev/null) == 'function' ]]
@@ -409,24 +412,21 @@ while true; do
409412
esac
410413
done
411414

412-
if [[ -z ${VAGRANT_VERSION+x} ]]
413-
then
414-
if [[ $# -ne 1 ]]
415-
then
416-
echo "$0: must specify the version of vagrant to install."
417-
exit 4
418-
fi
419-
420-
VAGRANT_VERSION=$1
421-
fi
422-
423415
echo "Starting vagrant-libvirt installation script"
424416

425417
DISTRO=${DISTRO:-$(awk -F= '/^ID=/{print $2}' /etc/os-release | tr -d '"' | tr '[A-Z]' '[a-z]')}
426418
DISTRO_VERSION=${DISTRO_VERSION:-$(awk -F= '/^VERSION_ID/{print $2}' /etc/os-release | tr -d '"' | tr '[A-Z]' '[a-z]' | tr -d '.')}
427419

428420
[[ ${VAGRANT_ONLY} -eq 0 ]] && setup_distro ${DISTRO} ${DISTRO_VERSION}
429421

422+
if [[ -z ${VAGRANT_VERSION+x} ]]
423+
then
424+
VAGRANT_VERSION="$(
425+
wget -qO - https://checkpoint-api.hashicorp.com/v1/check/vagrant 2>/dev/null | \
426+
tr ',' '\n' | grep current_version | cut -d: -f2 | tr -d '"'
427+
)"
428+
fi
429+
430430
install_vagrant ${VAGRANT_VERSION} ${DISTRO} ${DISTRO_VERSION}
431431

432432
[[ ${VAGRANT_ONLY} -eq 0 ]] && install_vagrant_libvirt ${DISTRO}

0 commit comments

Comments
 (0)