Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Vagrant on cloud CI services

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?

like image 391
Sam Burns Avatar asked Aug 05 '15 09:08

Sam Burns


People also ask

Can I use vagrant with AWS?

Vagrant will launch an AWS instance through the AWS AMI provided in the configuration using the credentials provided in the Vagrantfile. You can view the newly created instance in the AWS console panel. You can now SSH into your AWS instance or perform other Vagrant operations.

What is vagrant cloud used for?

Vagrant Cloud is a hosted service for finding boxes, sharing boxes, managing Vagrant Shares (reverse proxy to any port on your vagrant boxes).

What is vagrant AWS?

Vagrant is an open source tool for building and distributing virtual development environments. It provides framework to manage and create complete portable development environments. Vagrant machines are provisioned on the top of VirtualBox, VMware, AWS, or any other provider supported by vagrant.

Is vagrant used for production?

Users of Vagrant for years have wanted a way to deploy their Vagrant environments to production. Unfortunately, the Vagrantfile doesn't contain enough information to build a proper production environment with industry best practices. An Appfile is made to encode this knowledge, and deployment is a single command away.


2 Answers

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:

enter image description here

I created a fully working and 100% comprehensible example project here: https://github.com/jonashackt/vagrant-travisci-libvrt

like image 145
jonashackt Avatar answered Sep 29 '22 16:09

jonashackt


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.

like image 32
armab Avatar answered Sep 29 '22 15:09

armab