Problems with using non-community cookbooks with berkshelf

2.8k views Asked by At

I'm trying to create a cookbook that will install nginx + php-fpm with some good default options that can then be used by my application cookbooks.

But the Opscode PHP cookbook doesn't seem to support php-fpm but I noticed this one does: https://github.com/priestjim/chef-php which I checked out into a cookbook folder called "chef-php"

In the Berksfile for my nginx+php cookbook I've added:

cookbook 'chef-php', path: "../chef-php"

site :opscode

metadata 

If I run berks install inside that cookbook then I see

 Using chef-php (1.2.0) at '../chef-php'

included in the output suggesting everything is ok.

So if I then head over to my application cookbook which has the following Berksfile:

cookbook 'pogo-nginx-php', path: "../pogo-nginx-php"

site :opscode

metadata 

and run berks install I get the following error:

Cookbook 'chef-php' not found in any of the default locations

I've read that when resolving the dependencies of a dependency Berkshelf uses metadata.rb instead of Berksfile, if that's true then what's the correct way to approach this kind of problem? Or have I just made some stupid error (entirely possible!)

thanks.

2

There are 2 answers

1
Eric On BEST ANSWER

Berkshelf does not currently support nested Berksfiles.

I think you're correct that the metadata.rb file is used to resolve dependencies for child cookbooks. This means that you won't be able to specify a source since metadata.rb doesn't include anything beyond the name of the cookbook and the version constraints

There's an interesting discussion on a pull request in the Berkshelf repository about the reasoning for avoiding nested Berksfiles (how to resolve conflicting paths to cookbooks among other concerns).

I am using Chef in way similar to you and ran into the same problems. The workaround I'm using is to have a single "application" Berksfile. This file includes all of the dependencies for the entire application. A call to berks upload on this file uploads all of your dependencies to the Chef server.

A workaround proposed in the pull request discussion is using chef_api :config before site :opscode in your Berksfile. This will look at your private Chef server before looking at the opscode community site for recipes. Onc of the effects of this is that you'll need to upload your custom cookbooks prior to attempting to upload your cookbook that requires it.

2
Mark O'Connor On

The following Berksfile:

site :opscode

cookbook "chef-php", github: "priestjim/chef-php"

Downloads the following cookbooks:

$ berks install
Installing chef-php (1.2.0) from git: 'git://github.com/priestjim/chef-php.git' with branch: 'master' at ref: '19a5474e14ae2d9d05fc670aeb0cf122c3859acb'
Installing build-essential (1.4.2) from site: 'http://cookbooks.opscode.com/api/v1/cookbooks'
Installing xml (1.2.0) from site: 'http://cookbooks.opscode.com/api/v1/cookbooks'
Installing yumrepo (2.0.0) from site: 'http://cookbooks.opscode.com/api/v1/cookbooks'
Installing yum (2.4.4) from site: 'http://cookbooks.opscode.com/api/v1/cookbooks'