1

i am managing my cookbooks with berkshelf. i would like to play a little bit with the cookbook dependency graph. for instance:

  • given a cookbook, get its dependencies (the same as the resolver does it)
  • given a cookbook, get depended cookbooks (same as berks contingent)

i tried

require 'berkshelf'
Berkshelf::Lockfile.new(file_path: './Berksfile.lock')

but it did not work.

how can berkshelf be invoked programmatically under ruby and achieve the above?

Community
  • 1
  • 1
Mr.
  • 9,429
  • 13
  • 58
  • 82

2 Answers2

1

This is not supported, or anything even in the same area code as supported. We have no public Ruby APIs for this data, sorry. You can look at the Solve gem, but it's not really used outside of our own use cases.

coderanger
  • 52,400
  • 4
  • 52
  • 75
  • 1
    thank you for the reply. i just cannot believe what i am hearing -- do i need to develop a new code for parsing the berksfile lock to analyze the dependency tree? ohhh i wish there was a way to reuse berkshelf code... – Mr. Apr 29 '18 at 09:40
  • This is rapidly becoming out of scope for SO comments, but it depends entirely on what you are trying to accomplish. – coderanger Apr 29 '18 at 21:17
0

If you have Berksfile, It might be helpful for you.


require 'berkshelf'

# initializing berksfile
s = Berkshelf::Berksfile.from_file('./find_versions/Berksfile')

#install dependencies to create Berksfile.lock 
s.install()

# parse lockfile
s.lockfile().parse()

# find dependencies
puts s.find('cookbook_name').locked_version

rathourarv
  • 126
  • 1
  • 7
  • the `find()` returns nil for cookbook dependencies although there is a lock file – Mr. Feb 16 '20 at 11:43
  • According to this doc, find will return nil if dependency not found in berksfile.lock. https://www.rubydoc.info/gems/berkshelf/Berkshelf/Berksfile#find-instance_method – rathourarv Feb 16 '20 at 19:09