chef-cli icon indicating copy to clipboard operation
chef-cli copied to clipboard

Support path in git and github sources for cookbook in Policyfile.rb

Open nrgetik opened this issue 4 years ago • 0 comments

Describe the Enhancement:

I have a cookbook in a git repository that resides in a subfolder hierarchy below the top level of the repository. I want to refer to this location in a cookbook source line in Policyfile.rb, similarly to how a Policyfile.lock.json can be targeted in an include_policy source. This is not supported right now.

Describe the Need:

Anyone who is storing cookbook content in git which doesn't reside at the top level of a repository.

Current Alternative

Clone the repository locally, provide a local path. This is easy enough in most cases, but in some it may be less preferable.

Et cetera

In Policyfile.rb, include_policy can do something like this:

include_policy 'base_cookbook', git: 'https://github.com/chef-cft/chef-examples.git', branch: 'tg-include-policy', path: 'examples/include-policy/base_cookbook/Policyfile.lock.json'

But cookbook can't:

cookbook 'base_cookbook', git: 'https://github.com/chef-cft/chef-examples.git', branch: 'tg-include-policy', path: 'examples/include-policy/base_cookbook'
---- Begin output of /usr/local/bin/chef-cli update /Users/tom/gh/chef-examples/examples/include-policy/dependendent_cookbook/Policyfile.rb ----
STDOUT: Building policy dependendent_cookbook
Expanded run list: recipe[base_cookbook::default], recipe[dependendent_cookbook::default]
Caching Cookbooks...
Installing dependendent_cookbook >= 0.0.0 from path
Installing base_cookbook         >= 0.0.0 from git
STDERR: Error: Failed to generate Policyfile.lock
Reason: (CookbookOmnifetch::NotACookbook) The resource at '/var/folders/lr/_nvzwc7x3hjb9_09bh0wnpdm0000gn/T/d20210902-28012-13wmwb' does not appear to be a valid cookbook. Does it have a metadata.rb?
---- End output of /usr/local/bin/chef-cli update /Users/tom/gh/chef-examples/examples/include-policy/dependendent_cookbook/Policyfile.rb ----

Also, as an aside, parameters that are specified for either of these don't seem to get validated at all. path: isn't supported for cookbook, but why don't we see an error about this at some point prior? I can add anything: 'whatever' to this line, and I don't see any complaints/warnings.

nrgetik avatar Sep 03 '21 17:09 nrgetik