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

Add support for Berkshelf #2

Merged
merged 3 commits into from
May 27, 2016
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
3 changes: 2 additions & 1 deletion chefdepartie.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -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']
Expand Down
2 changes: 2 additions & 0 deletions lib/chefdepartie.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@
require 'chefdepartie/cookbook'
require 'chefdepartie/databag'
require 'chefdepartie/cache'

Chefdepartie.run(background: true, config: 'config.rb', cache: nil)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

was this done for testing? I don't think we want this hardcoded here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes it was done for testing. Also was following the README, which doesn't work without this line... i.e. bundle exec ruby lib/chefdepartie.rb simply returns without it.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good to merge once this is removed, I'll update the readme

29 changes: 22 additions & 7 deletions lib/chefdepartie/cookbook.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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/*']
Expand All @@ -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))
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess this is because it might erroneously try to upload a single file as a cookbook? Should we make this 'next unless File.dir?'?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

next if File.file? is the same as next unless File.directory?, isn't it?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there are conceivably edge cases, for special files (maybe for instance, symlinks, where it might respond to File.file? with true, as well as File.directory? with true, if the target is a directory - unsure of this).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

http://ruby-doc.org/core-2.2.0/File.html#method-c-file-3F

Returns true if the named file exists and is a regular file.

file can be an IO object.

If the file argument is a symbolic link, it will resolve the symbolic link and use the file referenced by the link.

puts "Will upload #{name}"
cookbook = loader.load_cookbook(name)
c = Chef::Cookbook::SyntaxCheck.for_cookbook(name, path)
Expand Down Expand Up @@ -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
Expand Down