Skip to content

Instantly share code, notes, and snippets.

@tknerr
Last active December 4, 2017 20:11
Show Gist options
  • Save tknerr/76b3761b53e70e01a811 to your computer and use it in GitHub Desktop.
Save tknerr/76b3761b53e70e01a811 to your computer and use it in GitHub Desktop.
Tricking kitchen-vagrant to use the vagrant/docker provider (why? for better caching via vagrant-cachier)
---
driver:
name: docker
driver_config:
provision_command:
- curl -L https://www.opscode.com/chef/install.sh | bash -s -- -v 12.3.0
- env GEM_HOME=/tmp/verifier/gems GEM_PATH=/tmp/verifier/gems GEM_CACHE=/tmp/verifier/gems/cache /opt/chef/embedded/bin/gem install thor busser busser-serverspec serverspec bundler && chown -R kitchen:kitchen /tmp/verifier
require_chef_omnibus: false
use_sudo: false
---
driver:
name: vagrant
provisioner:
name: chef_zero
require_chef_omnibus: 12.3.0
chef_omnibus_install_options: -d /tmp/vagrant-cache/vagrant_omnibus
platforms:
- name: ubuntu-14.04
suites:
- name: default
run_list:
- recipe[foo::default]

README

This shows how to use the exact same .kitchen.yml for both Vagrant/VirtualBox and Vagrant/Docker when using the kitchen-vagrant driver.

Why not plain Docker?

Why not simply using plain Docker with the kitchen-docker driver?

Well, there is a subtle difference: while plain kitchen-docker is more lightweight and starts up faster, kitchen-vagrant can cache downloaded files via vagrant-cachier, which can save you lots of traffic and idle time during the kitchenci run.

Using kitchen-vagrant with Vagrant/VirtualBox

This is pretty straightforward. VirtualBox is already the default provider, so you just run kitchenci:

$ kitchen test

Using kitchen-vagrant with Vagrant/Docker

This requires some trickery to make it work transparently without changing the .kitchen.yml:

  1. you need to provide a docker basebox that works via config.vm.box in the Vagrantfile
  2. you need to add this basebox under the "opscode-ubuntu-14.04" name / for the docker provider

So let's do the trickery first:

$ vagrant box add opscode-ubuntu-14.04 https://atlas.hashicorp.com/tknerr/boxes/baseimage-ubuntu-14.04/versions/1.0.0/providers/docker.box --provider=docker

Then we can simply set the VAGRANT_DEFAULT_PROVIDER to docker and run kitchenci:

$ set VAGRANT_DEFAULT_PROVIDER=docker
$ kitchen test

Using kitchen-docker with plain Docker

For the sake of completeness, lets show the plain kitchen-docker variant too. This uses a separate .kitchen.docker.yml file to override the vagrant driver with the docker driver (including some optimizations to cache the omnibus installer and verifier gems in a docker layer).

So you have to set the KITCHEN_LOCAL_YAML accordingly before running kitchenci:

$ set KITCHEN_LOCAL_YAML=.kitchen.docker.yml
$ kitchen test
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment