GitLab CI runner and VirtualBox

Recently, I have been installing such configuration and discover that not a lot documentation exist in Internet. So, I write this post as summary. I think that this is also can be usefull for guys who want install GitLab runner and Virtualbox on headless server using Puppet and automate this provision as much as possible. There are some caveats that requires manual work but it is also can be easily automated.

Puppet

Modules

I used modules from Puppetforge so you can install it using usual process

puppet module install vshn-gitlab
puppet module install danzilio-virtualbox

If you are using r10k for management Puppet modules and code you need to add following modules to your Puppetfile:

mod 'vshn/gitlab', '1.8.0'
mod 'danzilio/virtualbox', '1.7.1'

Do not forget check dependencies:

mod 'puppetlabs/stdlib', '4.12.0'
mod 'puppet/archive', '1.0.0'

Configuration

Node definition in my case was like this:

node 'gitlab-runner' {
	include virtualbox
	virtualbox::extpack { 'Oracle_VM_VirtualBox_Extension_Pack':
	  ensure           => present,
	  source           => 'http://download.virtualbox.org/virtualbox/5.1.2/Oracle_VM_VirtualBox_Extension_Pack-5.1.2-108956.vbox-extpack',
	  checksum_string  => '7614ce90e17297f80d6a5822252c90d9',
	  follow_redirects => true,
	}

	class { '::gitlab::cirunner':
	    manage_docker => false,
	}

	$runners_hash = {
	    'runner_for_virtualbox' => {}
	}

	$default_config = {
	'url' => "https://gitlab.example.com/",
	'registration-token' => "your_agent_registration_token",
	'executor' => "virtualbox"
	}

	gitlab::runner { 'runner_for_virtualbox':
	    default_config => $default_config,
	    runners_hash   => $runners_hash,
	    require => [Class['Virtualbox'],Virtualbox::Extpack['Oracle_VM_VirtualBox_Extension_Pack']]
	}
}

Notes:

  • manage_docker should be false, otherwise you need to add docker module and other hustling around docker installation
  • hiera wasn’t used in this example but all modules support it

VirualBox

Extension Pack

Most critical remainder, VirtualBox must have Oracle VM VirtualBox extension pack installed otherwise gitlab build’s will fail in a strange ways. Such as timeouts, errors and so on.

Other notes:

  • node what you are trying to use as virtualbox base must have Vt-x enabled (or nested virtualization)
  • ensure that nothing blocks VirtualBox networks

Base image

  • vagrant unfortunately doesn’t supported by gitlab runner :( See: links. As gitlab runner doesn’t support vagrant and other types of provisioning VMs you need to

To be finished 8(