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://supermarket.chef.io"
# manage direct dependencies here in Berksfile
cookbook "apache2", "1.10.4"
# dependency on self
cookbook "my-app", path: "."
DEPENDENCIES
apache2 (= 1.10.4)
my-app
path: .
GRAPH
apache2 (1.10.4)
iptables (>= 0.0.0)
logrotate (>= 0.0.0)
pacman (>= 0.0.0)
iptables (0.14.1)
logrotate (1.7.0)
pacman (1.1.1)
my-app (0.1.0)
apache2 (= 1.10.4)
iptables (= 0.14.1)
logrotate (= 1.7.0)
pacman (= 1.1.1)
name 'my-app'
maintainer ''
maintainer_email ''
license ''
description 'Installs/Configures my-app'
long_description 'Installs/Configures my-app'
version '0.1.0'
# read resolved dependencies from Berksfile.lock, i.e. lock the complete dependency graph
locked_deps = IO.read('Berksfile.lock').lines.drop_while { |l| l != "GRAPH\n" }
locked_deps.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
@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