Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Launching a Vagrant VM inside Travis-CI

How do you launch a Virtualbox VM using Vagrant inside Travis-CI?

I know launching a VM inside a VM is sometimes not supported, but there have been reported successes with this specific configuration.

I'm trying to setup a continuous integration server to run unittests for my sysadmin tool, to test it across different operating systems and Python versions. It uses Tox to handle initializing the various Python virtual environments and Pytest to run the tests and wrap Vagrant to setup and teardown the Virtualbox VM. It runs fine on my Ubuntu 14 localhost, but in Travis, Vagrant times out trying to boot a Virtualbox VM:

==> default: Importing base box 'ubuntu/trusty64'...
==> default: Matching MAC address for NAT networking...
==> default: Checking if box 'ubuntu/trusty64' is up to date...
==> default: Setting the name of the VM: functional_tests_default_1463515960654_71459
==> default: Clearing any previously set forwarded ports...
==> default: Clearing any previously set network interfaces...
==> default: Preparing network interfaces based on configuration...
    default: Adapter 1: nat
==> default: Forwarding ports...
    default: 22 => 2222 (adapter 1)
==> default: Running 'pre-boot' VM customizations...
==> default: Booting VM...
==> default: Waiting for machine to boot. This may take a few minutes...
    default: SSH address: 127.0.0.1:2222
    default: SSH username: vagrant
    default: SSH auth method: private key
    default: Warning: Connection timeout. Retrying...
    default: Warning: Connection timeout. Retrying...
    default: Warning: Connection timeout. Retrying...
    default: Warning: Connection timeout. Retrying...
    default: Warning: Connection timeout. Retrying...
    default: Warning: Connection timeout. Retrying...
    default: Warning: Connection timeout. Retrying...
    ...
    The job exceeded the maximum time limit for jobs, and has been terminated.

Since it's not giving me any details, I'm not sure how to diagnose the problem. I tried to enable more output with export VAGRANT_LOG=DEBUG; but that didn't show anything useful and exceeded Travis's maximum log size. I also tried increasing the timeout, and the memory allocation to 1GB, but neither helped.

The only odd thing I've noticed, that I've not been able to explain, is this message from sudo apt-get -y install -q virtualbox-ose-dkms virtualbox --fix-missing:

Module build for the currently running kernel was skipped since the
kernel source for this kernel does not seem to be installed.

However, immediately before this, the command to install kernel source succeeds:

sudo apt-get -y --force-yes install linux-headers-`uname -r`

How do you launch a Vagrant/Virtualbox VM inside Travis-CI?

like image 599
Cerin Avatar asked May 18 '16 18:05

Cerin


2 Answers

Sadly this is not supported by Travis-CI and there's no plan to do it in the near future. Check the following ticket: https://github.com/travis-ci/travis-ci/issues/6060

Since Travis is running your build in a virtualized container (OpenVZ) you could try with a 32-bit VM. That could work, but I haven't tested.

like image 78
ruiznato Avatar answered Oct 17 '22 11:10

ruiznato


From the end of 2019 it is possible to run Vagrant on TravisCI! All you have to do, is to switch to libvirt & KVM provider instead of virtualbox on Travis - see this so answer for a complete HowTo and this fully comprehensible example project on GitHub: https://github.com/jonashackt/vagrant-travisci-libvrt

See this TravisCI build for example:

successful vagrant installation and execution on Travis

If you don't want to use the libvirt provider locally, you can simply use one of the generic Vagrant Box images from Vagrant Cloud, since they support both virtualbox (locally) and libvirt (on TravisCI).

like image 40
jonashackt Avatar answered Oct 17 '22 12:10

jonashackt