Skip to content

Instantly share code, notes, and snippets.

@tknerr
Last active February 6, 2017 15:19
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tknerr/4e3236d00ceba917abea to your computer and use it in GitHub Desktop.
Save tknerr/4e3236d00ceba917abea to your computer and use it in GitHub Desktop.
Sample metadata.rb which reads its dependencies from Berksfile.lock. This is meant for use in "top-level cookbooks" only (~= "environment cookbook" pattern but using metadata rather than environments for locking deps)
source "https://api.berkshelf.com"
metadata
name 'test'
maintainer ''
maintainer_email ''
license ''
description 'Installs/Configures test'
long_description 'Installs/Configures test'
version '0.1.0'
if not File.exist? 'Berksfile.lock'
# state direct dependencies. need to remove Berksfile.lock when updating these.
depends "apache2", "1.10.4"
else
# read resolved dependencies from Berksfile.lock, i.e. lock the complete dependency graph
IO.read('Berksfile.lock').lines.keep_if { |line| line.match(/^\s{2}\w+\s\(.*\)/)}.each do |entry|
dep_name, dep_version = entry.strip.match(/^(\w+)\s\((.*)\)/).captures
depends(dep_name, dep_version) unless dep_name.eql? name
end
end
@tknerr
Copy link
Author

tknerr commented Jan 5, 2015

this needs to be cleaned up a bit, e.g.:

  • forward to "GRAPH" part in Berksfile.lock
  • add self-reference to Berksfile
  • check if this works with chef-client too
  • fix the berks update anomaly

@tknerr
Copy link
Author

tknerr commented Jan 5, 2015

@tknerr
Copy link
Author

tknerr commented Feb 16, 2015

FYI - in the current state it breaks berks update -- you would have to remove the Berksfile.lock first in order to have berks update succeed

@StephenKing
Copy link

berks list -F json might be an easier to consume output, right? But interesting stuff :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment