Knife upload cookbook dependencies?

Hi,
I’m aware that many people just upload everything, all of their
cookbooks. However in my case theres simply far too many of them.
So…

Any reason we cant have a ‘-d’ flag for uploading cookbooks?

It seems knife site vendor already knows how to iterate over the
cookbook dependencies. Im thinking perhaps that can be leveraged for
the cookbook uploading too.

For example

knife cookbook site vendor COOKBOOK -d
knife cookbook site vendor COOKBOOK --dependencies

Would become

knife cookbook upload vendor COOKBOOK -d
knife cookbook upload COOKBOOK --dependencies

I’d be happy to have a crack at it.

dreamcat4
dreamcat4@gmail.com

Well heres what a patch looks like (minus the tests)

diff --git a/chef/lib/chef/knife/cookbook_upload.rb
b/chef/lib/chef/knife/cookbook_upload.rb
index 52162fa..4ccab2b 100644
--- a/chef/lib/chef/knife/cookbook_upload.rb
+++ b/chef/lib/chef/knife/cookbook_upload.rb
@@ -20,6 +20,7 @@
require 'chef/knife'
require 'chef/cookbook_loader'
require 'chef/cookbook_uploader'
+require 'chef/cookbook/metadata'

class Chef
class Knife
@@ -28,6 +29,12 @@ class Chef

   banner "knife cookbook upload [COOKBOOKS...] (options)"
  •  option :deps,
    
  •   :short => "-d",
    
  •   :long => "--dependencies",
    
  •   :boolean => true,
    
  •   :description => "Upload dependencies automatically"
    
  •  option :cookbook_path,
       :short => "-o PATH:PATH",
       :long => "--cookbook-path PATH:PATH",
    

@@ -46,6 +53,15 @@ class Chef
config[:cookbook_path] = Chef::Config[:cookbook_path]
end

  •    # Check to ensure we have a valid source of cookbooks before continuing
    
  •    unless File.directory?(config[:cookbook_path].first)
    
  •      Chef::Log.error( File.join(config[:cookbook_path].first, "
    

doesn't exist!. Make sure you have cookbook_path configured
correctly"))

  •      exit 1
    
  •    end
    
  •    vendor_path = File.expand_path(File.join(config[:cookbook_path].first))
    
  •    cookbook_path = File.join(vendor_path, name_args[0])
    
  •    Chef::Cookbook::FileVendor.on_create { |manifest|
    

Chef::Cookbook::FileSystemFileVendor.new(manifest) }

     cl = Chef::CookbookLoader.new

@@ -71,6 +87,18 @@ class Chef
end
end
end
+

  •    if config[:deps]
    
  •      md = Chef::Cookbook::Metadata.new
    
  •      md.from_file(File.join(cookbook_path, "metadata.rb"))
    
  •      md.dependencies.each do |cookbook, version_list|
    
  •        # Doesn't do versions.. yet
    
  •        nv = Chef::Knife::CookbookUpload.new
    
  •        nv.config = config
    
  •        nv.name_args = [ cookbook ]
    
  •        nv.run
    
  •      end
    
  •    end
     end
    
     private
    

==============================================

On Sun, Nov 7, 2010 at 1:37 PM, Dreamcat4 dreamcat4@gmail.com wrote:

Hi,
I'm aware that many people just upload everything, all of their
cookbooks. However in my case theres simply far too many of them.
So...

Any reason we cant have a '-d' flag for uploading cookbooks?

It seems knife site vendor already knows how to iterate over the
cookbook dependencies. Im thinking perhaps that can be leveraged for
the cookbook uploading too.

For example

knife cookbook site vendor COOKBOOK -d
knife cookbook site vendor COOKBOOK --dependencies

Would become

knife cookbook upload vendor COOKBOOK -d
knife cookbook upload COOKBOOK --dependencies

I'd be happy to have a crack at it.

dreamcat4
dreamcat4@gmail.com

On Sun, Nov 7, 2010 at 12:02 PM, Dreamcat4 dreamcat4@gmail.com wrote:

Well heres what a patch looks like (minus the tests)

That's a great start Dreamcat. Do you think you put it in a git branch
and add some tests?

There's a bug filed for this here: http://tickets.opscode.com/browse/CHEF-1588

Bryan

On Wed, Nov 10, 2010 at 4:01 PM, Bryan McLellan btm@loftninjas.org wrote:

On Sun, Nov 7, 2010 at 12:02 PM, Dreamcat4 dreamcat4@gmail.com wrote:

Well heres what a patch looks like (minus the tests)

That's a great start Dreamcat. Do you think you put it in a git branch
and add some tests?

I wish for that too Byan. However as things stand both these knife
subcommands dont have any tests written for them. If either had tests
then I could probably fill in the missing gaps and add the required
tests. But with nothing to start from...

Dreamcat finds its too hard :frowning:

There's a bug filed for this here: http://tickets.opscode.com/browse/CHEF-1588

Bryan