Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ No pull request template is provided on GitHub. The expected changes are often a

### 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:

* git
Expand Down
58 changes: 6 additions & 52 deletions Vagrantfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,12 @@ Vagrant.configure("2") do |config|
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|
push.script = "scripts/website_push_www.sh"
Expand All @@ -24,54 +29,3 @@ Vagrant.configure("2") do |config|
push.script = "scripts/website_push_docs.sh"
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 changes: 19 additions & 0 deletions scripts/install_rvm
Original file line number Diff line number Diff line change
@@ -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 changes: 49 additions & 0 deletions scripts/setup_tests
Original file line number Diff line number Diff line change
@@ -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