Chef issue 1526

A quick post to address this Chef issue. These issues (and more) can be resolved by using this fork of Bundler that targets the Chef use case. I’ll cover this in another post, but fro now note that this bundler fork is only intended for dealing with Chef Cookbook. Hopefully it’ll get to the point where the Bundler team accept (or provide) the requisite features.However, Bundler’s specs (and code base) make extending its behavior a nightmare – c.f Chef’s sweetness.

Anyway, the issues…

  • A Cookbook is installed only if dependencies are present in the Gemfile.
  • Installed dependencies are only updated if they have changed.
  • Only cookbooks specified in a gemfile are downloaded.
  • If you don’t specify dependencies, it gives LOTS of warning about that missing cookbook
  • Cookbooks are downloaded individually by branch, tag, or commit hash.
  • Cookbooks can be downloaded from any Git Repository (e.g. https://github.com/cookbooks )
  • Cookbooks can be downloaded using Git clone recognized URI’s

Outstanding:

  • Make pending specs pass (Bundler’s spec suite is a first class nightmare)
  • Make bundle update and bundle show change into a folder pointed to by --lockfile-path

The Gemfile

This where to list (just) the Cookbooks you want to download. You can think of a Gemfile as describing an application stack. Defining and is as simple as listing the Cookbooks repos in the Gemfile – to get the stack configured and running is Chef’s domain of expertise. You can download from just about any Git repository. Most git clone URI syntax should work (but not path/file names with spaces – i.e. it uses an unencoded file:// URI). The Gemfile corresponding to Opscode’s build-a-rails-stack example is shown in this gist.

Downloading the Cookbooks

The transript of downloading the build-a-rails-stack example’s cookbooks is here.
Use --gemfile to point at any file containing Gemfile data. Download the Chef Cookbooks to any folder pointed to by --install-path, if the folder does not exist it will be created. There will also be a lockfile created: Gemfile.lock

Update the Cookbooks

The transript of updating the build-a-rails-stack example’s cookbooks is here.
If there is no update nothing is downloaded, per the issue request. If you use Git commit hashes, then you can ensure your Cookbook(s) never change, e.g. when you are in production. Currently you need to change into the folder containing the lockfile (Gemfile.lock), created by bundle install ... in the folder the --gemfile ... option pointed to.

Show/List the Cookbooks and their Git hash.

The transript of the build-a-rails-stack example is here.
As with updating, you need to change into the lockfile folder.

Missing a Cookbook dependency

Remove the couchdb entry from the Gemfile. This is required by Chef. As we can see in this gist, show, update and install behave in ways that are not unreasonable for Chef users.