Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Load cookbooks from Berkshelf 3 berksfile #164

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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