Chef Workflow Management With Spork

This is the eighth chapter in a series on the development of Chef Broiler Plate in which we go over setting up a robust, TED framework for Chef cookbook development.

In our last post, we add the ability to run knife cookbook test against our cookbooks both during local development and on the CI server. Before we get too crazy with this amazing build, let's rein it back in and talk about workflow. There are some best practices introduced by the "knife-spork" tool that will help in collaborative cookbook development. It will also help a solo developer keep things in order when it comes to bumping versions and what not.

To test this out, we will install knife-spork and do a small edit to our MOTD cookbook to use its features.

Update your Gemfile

Add the spork Gem to the Gemfile and update, and as this won't be needed by the CI server, we will put it under the development block:

group :development do
  gem "knife-spork", "~> 1.0.17"

Configure your Spork

Next, create a config/spork-config.yml file to put in the default configuration. I'm not wild about how there are lots of configurations in various places, but it's a minor issue, hopefully overtime these can be consolidated.

mkdir config
touch spork-config.yml

Below, are the only configurations I have not commented out:

  - development
  - staging
  - production
version_change_threshold: 2
environment_path: "environments"

Making an Example Change

To check this is all working, I'm going to make a very small change to the MOTD cookbook, and then bump the version number. All we will do is make the message in title case. In true test driven style, I'll update the line in the spec from this:

...nt('/etc/motd.tail', 'This server is property of Never Stop Building')...

To this:

...nt('/etc/motd.tail', 'This Server is the Property of Never Stop Building')...

Well I also made it sound better.

Make the Tests Pass

Running the rake build task reveals that our test has failed. It is just a matter of updating the template in this case. Once that is updated and the tests pass, we should bump the version number of the cookbook. In this case, I'll consider this a minor patch:

bundle exec knife spork bump motd patch

Upload the Updated Cookbook

And finally, I'll use the upload feature to upload it to the chef server, "freezing" it at the same time, should anyone else try to push changes:

bundle exec knife spork upload motd

Note, that you do not need to use the bundle exec part of the command if you have installed the Gem globally.

Another great feature of Spork, is the Spork Promote command, that let's you constrain a specific version of a cookbook to a specific environment. A use case might be:

  • Cookbook 2.0 is being verified on your development environment.
  • Cookbook 1.9 is in production environment.
  • When things look good, 2.0 can be rolled out to production.

Coming up…

In the next post, we will be adding the "Berkshelf" tool to our framework, preparing us for using community cookbooks.

If you enjoyed reading this or learned something, please consider sharing via , , or . Thanks!