diff --git a/chefdepartie.gemspec b/chefdepartie.gemspec index e6f4b25..bd54da4 100644 --- a/chefdepartie.gemspec +++ b/chefdepartie.gemspec @@ -16,7 +16,8 @@ Gem::Specification.new do |s| s.add_runtime_dependency 'chef', ['=12.9.38'] s.add_runtime_dependency 'chef-zero', '~> 4.2', '>= 4.2.2' s.add_runtime_dependency 'librarian-chef', '~> 0.0.4' - s.add_runtime_dependency 'cityhash', '~> 0.8.1' + s.add_runtime_dependency 'berkshelf', '~> 4.3.0' + s.add_runtime_dependency 'cityhash', '~> 0.6.0' s.add_development_dependency 'rake', ['=10.4.2'] s.add_development_dependency 'simplecov', ['=0.10.0'] s.add_development_dependency 'rspec', ['=3.4.0'] diff --git a/lib/chefdepartie/cookbook.rb b/lib/chefdepartie/cookbook.rb index cc8600d..2761e03 100644 --- a/lib/chefdepartie/cookbook.rb +++ b/lib/chefdepartie/cookbook.rb @@ -12,8 +12,13 @@ module Cookbooks def self.upload_all cookbooks = File.dirname(Chef::Config[:cookbook_path]) Dir.chdir(cookbooks) do - puts 'Uploading librarian cookbooks' - upload_cheffile + puts 'Uploading dependency cookbooks' + + if File.exist?('Berksfile') + upload_berksfile + elsif File.exist?('Cheffile') + upload_cheffile + end puts 'Uploading site cookbooks' books = Dir['cookbooks/*'] @@ -28,6 +33,7 @@ def self.upload_cookbooks(path, books) books = books.collect do |name| next if Cache.cache(File.join(path, name)) + next if File.file?(File.join(path, name)) puts "Will upload #{name}" cookbook = loader.load_cookbook(name) c = Chef::Cookbook::SyntaxCheck.for_cookbook(name, path) @@ -62,12 +68,21 @@ def self.upload_site_cookbooks(books) paths.values.flatten.uniq.sort end + def self.upload_berksfile + return if ENV['NO_BERKSHELF'] + + FileUtils.mkdir_p('tmp/berkshelf/cookbooks') + system('berks vendor tmp/berkshelf/cookbooks') + cookbooks = Dir.entries('tmp/berkshelf/cookbooks') - %w(. ..) + upload_cookbooks('tmp/berkshelf/cookbooks', cookbooks) + end + def self.upload_cheffile - unless ENV['NO_LIBRARIAN'] - FileUtils.mkdir_p('tmp/librarian/cookbooks') - system('librarian-chef install --quiet --path tmp/librarian/cookbooks') - upload_cookbooks('tmp/librarian/cookbooks', cheffile_cookbooks.map(&:name)) - end + return if ENV['NO_LIBRARIAN'] + + FileUtils.mkdir_p('tmp/librarian/cookbooks') + system('librarian-chef install --quiet --path tmp/librarian/cookbooks') + upload_cookbooks('tmp/librarian/cookbooks', cheffile_cookbooks.map(&:name)) end def self.cheffile_cookbooks diff --git a/spec/lib/chef_spec.rb b/spec/lib/chef_spec.rb index 55820b5..24b87fb 100644 --- a/spec/lib/chef_spec.rb +++ b/spec/lib/chef_spec.rb @@ -9,7 +9,7 @@ it 'can cache uploads' do cache = Dir.mktmpdir expect{Chefdepartie.run(background: true, config: chef_config, cache: cache)}.to output(/Ready/).to_stdout - expect{Chefdepartie.run(background: true, config: chef_config, cache: cache)}.to output("Uploading roles\nUploading databags\nUploading librarian cookbooks\nUploading site cookbooks\nReady\n").to_stdout + expect{Chefdepartie.run(background: true, config: chef_config, cache: cache)}.to output("Uploading roles\nUploading databags\nUploading dependency cookbooks\nUploading site cookbooks\nReady\n").to_stdout end end end