Using Vagrant on cloud CI services
Many CI services are not allowing to run Vagrant via LXC or Virtualbox as it will require nested virtualization (running VM in VM) or a pure bare metal server provisioned for you.
Current 2021 (updated) situation:
- Github Actions can do it.
- Travis was able to run Vagrant with some workarounds.
- AppVeyor allows running VirtualBox (non-free plans).
- You can't under CodeShip
- You can't under CircleCI
- Don't know about other CI services, will investigate further.
I hope during the time we'll see CI services allowing to run Vagrant with Virtualbox or LXC, but for now Docker (with its limitations) is the only option.
Personally, I would be happy to use it for integration tests against different platforms/linux distros via Test-Kitchen CI or similar.
Update January 2021: GitHub Actions also supports Vagrant - and Vagrant/VirtualBox are both installed out-of-the-box in the MacOS environment (not on Linux or Windows currently!). See the possible environments here. Therefore I created a fully comprehensible example project at: https://github.com/jonashackt/vagrant-github-actions
1.: Create a Vagrantfile (and you're not limited to libvirt as with Travis, you have a full VirtualBox environment with nested virtualization working on GitHub Actions!) like this:
Vagrant.configure("2") do |config|
config.vm.box = "generic/ubuntu1804"
config.vm.define 'ubuntu'
# Prevent SharedFoldersEnableSymlinksCreate errors
config.vm.synced_folder ".", "/vagrant", disabled: true
end
2.: Create a GitHub Actions workflow like this vagrant-up.yml inside the .github/workflows
directory in your repository:
name: vagrant-up
on: [push]
jobs:
vagrant-up:
runs-on: macos-10.15
steps:
- uses: actions/checkout@v2
- name: Run vagrant up
run: vagrant up
- name: ssh into box after boot
run: vagrant ssh -c "echo 'hello world!'"
You can even add caching for the Vagran boxes, this will safe you some seconds :)
Early 2020:
TravisCI is now able to run Vagrant finally! Thanks to this GitHub issue I learned about libvirt and KVM, which could be used together with the vagrant-libvirt Plugin to run Vagrant boxes on TravisCI.
An example TravisCI .travis.yml
should look somehow like that:
---
dist: bionic
language: python
install:
# Install libvrt & KVM
- sudo apt-get update && sudo apt-get install -y bridge-utils dnsmasq-base ebtables libvirt-bin libvirt-dev qemu-kvm qemu-utils ruby-dev
# Download Vagrant & Install Vagrant package
- sudo wget -nv https://releases.hashicorp.com/vagrant/2.2.7/vagrant_2.2.7_x86_64.deb
- sudo dpkg -i vagrant_2.2.7_x86_64.deb
# Vagrant correctly installed?
- vagrant --version
# Install vagrant-libvirt Vagrant plugin
- sudo vagrant plugin install vagrant-libvirt
script:
- sudo vagrant up --provider=libvirt
- sudo vagrant ssh -c "echo 'hello world!'"
With the help of the generic
Vagrant Box images from Vagrant Cloud you can also establish a workflow of using Vagrant + libvirt + KVM on Travis and Vagrant + VirtualBox on your local machine, if you like:
I created a fully working and 100% comprehensible example project here: https://github.com/jonashackt/vagrant-travisci-libvrt