Vagrantfile: Fix setup for tests

This commit is contained in:
Tim Visher 2021-04-11 20:15:01 -04:00
parent 9933fec019
commit 0f603e3363
4 changed files with 76 additions and 52 deletions

View File

@ -34,6 +34,8 @@ No pull request template is provided on GitHub. The expected changes are often a
### Setup a development installation of Vagrant ### Setup a development installation of Vagrant
*A Vagrantfile is provided that should take care setting up a VM for running the rspec tests.* If you only need to run those tests and don't also want to run a development version of Vagrant from a host machine then it's recommended to use that.
There are a few prerequisites for setting up a development environment with Vagrant. Ensure you have the following installed on your machine: There are a few prerequisites for setting up a development environment with Vagrant. Ensure you have the following installed on your machine:
* git * git

58
Vagrantfile vendored
View File

@ -14,7 +14,12 @@ Vagrant.configure("2") do |config|
end end
end end
config.vm.provision "shell", inline: $shell # We split apart `install_rvm` from `setup_tests` because rvm says to
# logout and log back in just after installing RVM.
# https://github.com/rvm/ubuntu_rvm#3-reboot
config.vm.provision "shell", path: "scripts/install_rvm"
config.vm.provision "shell", path: "scripts/setup_tests"
config.push.define "www", strategy: "local-exec" do |push| config.push.define "www", strategy: "local-exec" do |push|
push.script = "scripts/website_push_www.sh" push.script = "scripts/website_push_www.sh"
@ -24,54 +29,3 @@ Vagrant.configure("2") do |config|
push.script = "scripts/website_push_docs.sh" push.script = "scripts/website_push_docs.sh"
end end
end end
$shell = <<-'CONTENTS'
export DEBIAN_FRONTEND=noninteractive
MARKER_FILE="/usr/local/etc/vagrant_provision_marker"
RUBY_VER_REQ=$(awk '$1 == "s.required_ruby_version" { print $4 }' /vagrant/vagrant.gemspec | tr -d '"')
# Only provision once
if [ -f "${MARKER_FILE}" ]; then
exit 0
fi
# Add ubuntu_rvm repo
apt-add-repository -y ppa:rael-gc/rvm
# Update apt
apt-get update --quiet
# Add vagrant user to sudo group:
# ubuntu_rvm only adds users in group sudo to group rvm
usermod -a -G sudo vagrant
# Install basic dependencies and RVM
apt-get install -qy build-essential bsdtar rvm
# Import the mpapis public key to verify downloaded releases
su -l -c 'gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3' vagrant
# Install next-to-last Ruby that complies with Vagrant's version constraint
RUBY_VER=$(su -l -c 'rvm list known' vagrant | tr '[]-' ' ' | awk "/^ ruby ${RUBY_VER_REQ:0:1}\./ { print \$2 }" | sort -r | sed -n '2p')
su -l -c "rvm install ${RUBY_VER}" vagrant
su -l -c "rvm --default use ${RUBY_VER}" vagrant
# Output the Ruby version (for sanity)
su -l -c 'ruby --version' vagrant
# Install Git
apt-get install -qy git
# Upgrade Rubygems
su -l -c "rvm ${RUBY_VER} do gem update --system" vagrant
# Prepare to run unit tests
su -l -c 'cd /vagrant; bundle install' vagrant
# Automatically move into the shared folder, but only add the command
# if it's not already there.
grep -q 'cd /vagrant' /home/vagrant/.bash_profile 2>/dev/null || echo 'cd /vagrant' >> /home/vagrant/.bash_profile
# Touch the marker file so we don't do this again
touch ${MARKER_FILE}
CONTENTS

19
scripts/install_rvm Normal file
View File

@ -0,0 +1,19 @@
#!/usr/bin/env bash
export DEBIAN_FRONTEND=noninteractive
if ! rvm --version
then
# https://github.com/rvm/ubuntu_rvm#install
apt-add-repository -y ppa:rael-gc/rvm &&
apt-get update -y &&
apt-get install -y rvm || {
echo 'Failed to install rvm' >&2
exit 1
}
fi
usermod -a -G rvm vagrant || {
echo 'Failed to add vagrant to the rvm group' >&2
exit 1
}

49
scripts/setup_tests Normal file
View File

@ -0,0 +1,49 @@
#!/usr/bin/env bash
rvm --version || {
echo 'rvm not installed' >&2
exit 1
}
# bsdtar is required for a small subset of the tests
if ! bsdtar --version
then
apt-get install -y bsdtar &&
bsdtar --version || {
echo 'Failed to install bsdtar' >&2
exit 1
}
fi
# Install next-to-last Ruby that complies with Vagrant's version
# constraint
RUBY_VER_REQ=$(
awk '
$1 == "s.required_ruby_version" { print $4 }
' /vagrant/vagrant.gemspec |
tr -d '"')
RUBY_VER=$(sudo -u vagrant -i rvm list known |
tr '[]-' ' ' |
awk "/^ ruby ${RUBY_VER_REQ:0:1}\./ { print \$2 }" |
sort -r |
sed -n '2p')
sudo -u vagrant -i rvm install "${RUBY_VER}"
sudo -u vagrant -i rvm --default use "${RUBY_VER}"
# Output the Ruby version (for sanity)
sudo -u vagrant -i ruby --version
# Upgrade Rubygems
sudo -u vagrant -i rvm "${RUBY_VER}" do gem update --system
# Prepare to run unit tests
sudo -u vagrant -i bash -c 'cd /vagrant; bundle install'
# Automatically move into the shared folder, but only add the command if
# it's not already there.
if ! grep -q 'cd /vagrant' /home/vagrant/.bash_profile
then
cat <<EOF >> /home/vagrant/.bash_profile
cd /vagrant
EOF
fi