Using Vagrant on cloud CI services

2020-07-03 04:17发布

问题:

Are there any cloud CI services that allow Vagrant VMs to run using VirtualBox as a provider?

Early investigation shows this seems not to be possible with Travis CI or Circle CI, although the vagrant-aws plugin allows for the use of AWS servers as a Vagrant provider. Is this correct?

回答1:

That's right.

There are still no CI services allowing to run Vagrant via LXC or Virtualbox (and that's sad).

  • You can't do it under Travis.
  • You can't under CodeShip
  • You can't under CircleCI
  • Don't know about other CI services, will investigate further.

I hope during 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.



回答2:

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