From 21491f8d0c75ec0cbfbbdf1b0e50b7fec2cca688 Mon Sep 17 00:00:00 2001 From: Yauhen Artsiukhou Date: Tue, 15 Sep 2015 18:44:46 +0300 Subject: [PATCH] Add ability to use lockfile directly It gives good possibility to update environment from CI server. Method load_berksfile_lock skips all validations and uses lock file directly. For example CI server always requires to do `berks install` because, some of cookbooks might be not present on CI server. Also this works much faster. --- lib/chef-berksfile-env.rb | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/lib/chef-berksfile-env.rb b/lib/chef-berksfile-env.rb index 362557a..97050fc 100644 --- a/lib/chef-berksfile-env.rb +++ b/lib/chef-berksfile-env.rb @@ -6,6 +6,17 @@ class Chef class Environment + # @param path path to lock file + # @raise Berkshelf::LockfileNotFound exception + def load_berksfile_lock(path=nil) + lockfile = ::Berkshelf::Lockfile.from_file(path) + raise ::Berkshelf::LockfileNotFound, "Berks lock file is not present: #{path}" unless lockfile.present? + + lockfile.locks.each_pair do |_, dependency| + cookbook dependency.name, "= #{dependency.locked_version.to_s}" + end + end + def load_berksfile(path=nil) raise "You must define the environment name before doing load_berksfile" if path.nil? && name.empty?