Home

Awesome

What is Travis Sous Chef

Travis Sous Chef is a repository that makes development and testing of Chef cookbooks (for Travis CI but not just) easy. It brings practices that the Travis Development Team uses to develop new and test modified cookbooks for Travis CI to the masses.

Sous Chef intentionally focuses on automating away as many distractions as possible so you can focus on developing your Chef cookbooks. It does just one thing but does it well.

How it works

With Sous Chef, you use Vagrant and a locally running VirtualBox VM to develop and test your cookbooks. Sous Chef can use any collection of cookbooks: those we use for travis-ci.org, cookbooks you are using for commercial projects, cookbooks from the official OpsCode repository or anything else.

With Sous Chef, you provision a locally running virtual machine managed by Vagrant in just one command. The process is set up to shorten the feedback loop:

Once you are done with your cookbooks, just push them to a source control repository or rsync them to your server. Then destroy VM environment you were using in one command. Or just power off the VM and come back to work with it later.

Dependencies

Sous Chef uses Vagrant and thus relies on Virtual Box being installed. Note that you do not need to have Chef installed locally. It will only be run in a virtual machine.

Getting started with Sous Chef

First install VirtualBox 4.1.x:

Then install Vagrant.

Copy sample Vagrant file:

cp Vagrantfile.sample Vagrantfile

Create a cookbooks directory or clone an existing collection of cookbooks like Travis CI cookbooks:

mkdir cookbooks
# or
git clone git://github.com/travis-ci/travis-cookbooks.git cookbooks

To allow provisioning with chef you need to uncomment the following line (including its associated end statement)

  config.vm.provision :chef_solo do |chef|

After that point Vagrant at the cookbooks location by editing Vagrantfile. For Travis CI cookbooks, you just need to uncomment

# this assumes you have travis-ci/travis-cookbooks cloned at ./cookbooks
chef.cookbooks_path = ["cookbooks/ci_environment"]

for other cookbook collections, provide a local path (or several) like so

chef.cookbooks_path = ["cookbooks"]

You can use multiple cookbook locations if necessary. For example, to develop both shared OSS cookbooks and your private product/company-specific ones:

chef.cookbooks_path = ["cookbooks/ci_environment", "megacorp/cookbooks"]

Next choose some cookbooks to provision. In the case of Travis CI cookbooks, build-essential is a good one to start with, so uncomment

# chef.add_recipe     "build-essential" 

Your Vagrantfile then will look like this:

Vagrant::Config.run do |config|
  config.vm.box     = "precise64_base"
  config.vm.box_url = "http://files.vagrantup.com/precise64.box"

  config.vm.provision :chef_solo do |chef|
    # point Vagrant at the location of cookbooks you are going to use,
    # for example, a clone of your fork of github.com/travis-ci/travis-cookbooks
     chef.cookbooks_path = ["cookbooks/ci_environment"]

    # Turn on verbose Chef logging if necessary
    # chef.log_level      = :debug

    # List the recipies you are going to work on/need.
    chef.add_recipe     "build-essential"    
    # chef.add_recipe     "networking_basic"    
    # chef.add_recipe     "kerl"

    # chef.json.merge!({
    #   :kerl => {
    #     :user     => "vagrant",
    #     :group    => "vagrant"
    #   }
    # })
  end
end

Create an Ubuntu virtual machine you will be developing cookbooks in:

vagrant up 

To provision the VM ("provisioning" means running chef-solo to converge the VM to the state you want using Chef recipes you'd chosen to use):

vagrant provision

Running chef-solo may take from several seconds to several minutes, dependeing on what selected recipes do. Building 13 Ruby versions/implementations for travis-ci.org, for example, takes over 50 minutes but most of recipes run in under 30 seconds.

Once provisioning finishes, ssh into the VM to check what the environment looks like:

vagrant ssh

When you are done with your work on the cookbook you can either power off the VM to use it later with

vagrant halt

or destroy it completely with

vagrant destroy

Developing a new cookbook with Sous Chef

TBD

Copyright

Michael S. Klishin & Travis CI Development Team, 2011-2014

License

The MIT license. See LICENSE file in the repository root.

Bitdeli Badge