chef / chef/chef-cli

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

Open
#191 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Ruby
Stars
18
Forks
23
Avg merge
5d 17h
Merged PRs (30d)
1

Description

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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by tracing how cookbook git and github sources are handled from Policyfile.rb, then compare that path with include_policy handling for nested repository paths. Inspect how source parameters are validated, including unsupported options. Done means cookbook sources can target a cookbook below the repository root and invalid parameters are reported appropriately.

Written by the indexing model from the issue text.

Assessment

Tech stack
git, github, ruby
Domain
cli
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.