Last active
February 6, 2017 15:19
-
-
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)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
source "https://supermarket.chef.io" | |
# manage direct dependencies here in Berksfile | |
cookbook "apache2", "1.10.4" | |
# dependency on self | |
cookbook "my-app", path: "." |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Full example here:
https://github.com/tknerr/sample-toplevel-cookbook
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
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
this needs to be cleaned up a bit, e.g.:
berks update
anomaly