Skip to content

Commit

Permalink
Load cookbooks from Berkshelf 3 berksfile
Browse files Browse the repository at this point in the history
  • Loading branch information
Nikolay Murga committed Feb 4, 2015
1 parent 51417af commit 2b09b93
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions lib/knife-spork/runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def run_plugins(hook)

environments = [ @environments || @environment ].flatten.compact.collect{|environment| environment.is_a?(::Chef::Environment) ? environment : load_environment_from_file(environment)}.sort{|a,b| a.name.to_s <=> b.name.to_s}
environment_diffs = @environment_diffs

KnifeSpork::Plugins.run(
:config => spork_config,
:hook => hook.to_sym,
Expand All @@ -56,7 +56,7 @@ def run_plugins(hook)

def load_environments_and_cookbook
ensure_environment_and_cookbook_provided!

if @name_args.size == 2
environments = @name_args[0].split(",").map{ |env| load_specified_environment_group(env) }
[ environments.flatten, @name_args[1] ]
Expand Down Expand Up @@ -192,19 +192,24 @@ def load_from_chef(name)
def load_from_berkshelf(name)
return unless defined?(::Berkshelf)
return unless ::File.exist?(self.config[:berksfile])

berksfile = ::Berkshelf::Berksfile.from_file(self.config[:berksfile])
lockfile = ::Berkshelf::Lockfile.new(berksfile)
lockfile = ::Berkshelf::Lockfile.from_berksfile(berksfile)

resolver = ::Berkshelf::Resolver.new(
berksfile,
lockfile.find(name)
)
raise Berkshelf::BerkshelfError, "LockFileNotFound" unless File.exists?(lockfile.filepath)

cookbook = Berkshelf.ui.mute {
self.config[:skip_dependencies] ||= false
berksfile.resolve(lockfile.find(name), {skip_dependencies: self.config[:skip_dependencies]})[:solution].first
dependency = Berkshelf.ui.mute {
resolver.resolve.first
}

#convert Berkshelf::CachedCookbook to Chef::CookbookVersion
::Chef::CookbookLoader.new(File.dirname(cookbook.path))[name]

cookbook_loader = Chef::Cookbook::CookbookVersionLoader.new(dependency.cached_cookbook.path)
cookbook_loader.load_cookbooks
cookbook_version = cookbook_loader.cookbook_version
cookbook_version.name = cookbook_version.metadata.name #correct name
cookbook_version
end

# @todo #opensource
Expand Down

0 comments on commit 2b09b93

Please sign in to comment.