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

Fix Berkshelf integration #74

Merged
merged 9 commits into from
Aug 6, 2013
Merged

Fix Berkshelf integration #74

merged 9 commits into from
Aug 6, 2013

Conversation

sethvargo
Copy link
Contributor

@sethvargo
Copy link
Contributor Author

I lied - I think this might fix #73, but I don't have a reliable test case. Can someone point their Gemfile at this and try it:

gem 'knife-spork', github: 'sethvargo/knife-spork', branch: 'promote_berksfie'

@bobziuchkovski
Copy link

This is still broken, but works after patching runner.rb:104 (pass cookbook_name) and runner.rb:128 (cookbook_name as param):

cookbook = load_from_chef(cookbook_name) || load_from_berkshelf(cookbook_name) || load_from_librarian(cookbook_name)

and

def load_from_librarian(name)

@sethvargo
Copy link
Contributor Author

@ziuchkovski yea... that would definitely be a bug. Updated

@bobziuchkovski
Copy link

Confirmed, your 4e15d59 commit works as expected. Thanks!

@scalp42
Copy link

scalp42 commented Jun 13, 2013

@ziuchkovski you think you could provide me some feedback. I must be doing something wrong but I can't get it to work

cc @sethvargo

#73

@jonlives
Copy link
Owner

@sethvargo what's the status on this one? Looks like @scalp42 is still having issues per #73

@sethvargo
Copy link
Contributor Author

@jonlives I'm not sure. For some reason, the berksfile arg is just coming in as a boolean instead of the stringed value. I have no idea why.

@jonlives
Copy link
Owner

Huh. will keep this one open then!

@sethvargo
Copy link
Contributor Author

yea. I haven't had time to dig into it yet

@RSO
Copy link
Contributor

RSO commented Jul 12, 2013

I am not quite sure if this is the correct place to post this, since I encounter errors in both the master branch as in your promote_berksfile branch. In your branch, when I run:

bundle exec knife spork promote debug bla-cookbook --remote -VV

I get:

DEBUG: No chefignore file found at ~/Projects/factlink/chef-repo/cookbooks/chefignore no files will be ignored
DEBUG: No chefignore file found at ~/Projects/factlink/chef-repo/site-cookbooks/chefignore no files will be ignored
~/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/bundler/gems/knife-spork-4e15d592d100/lib/knife-spork/plugins/git.rb:30:in `block in before_promote': undefined method `root_dir' for #<Berkshelf::CachedCookbook:0x007f942e4a4fb0> (NoMethodError)
  from ~/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/bundler/gems/knife-spork-4e15d592d100/lib/knife-spork/plugins/git.rb:29:in `each'
  from ~/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/bundler/gems/knife-spork-4e15d592d100/lib/knife-spork/plugins/git.rb:29:in `before_promote'
  from ~/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/bundler/gems/knife-spork-4e15d592d100/lib/knife-spork/plugins.rb:11:in `block in run'
  from ~/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/bundler/gems/knife-spork-4e15d592d100/lib/knife-spork/plugins.rb:9:in `each'
  from ~/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/bundler/gems/knife-spork-4e15d592d100/lib/knife-spork/plugins.rb:9:in `run'
  from ~/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/bundler/gems/knife-spork-4e15d592d100/lib/knife-spork/runner.rb:32:in `run_plugins'
  from ~/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/bundler/gems/knife-spork-4e15d592d100/lib/chef/knife/spork-promote.rb:46:in `run'
  from ~/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/chef-11.4.4/lib/chef/knife.rb:460:in `run_with_pretty_exceptions'
  from ~/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/chef-11.4.4/lib/chef/knife.rb:173:in `run'
  from ~/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/chef-11.4.4/lib/chef/application/knife.rb:123:in `run'
  from ~/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/chef-11.4.4/bin/knife:25:in `<top (required)>'
  from ~/.rbenv/versions/1.9.3-p327/bin/knife:23:in `load'
  from ~/.rbenv/versions/1.9.3-p327/bin/knife:23:in `<main>'

Any idea what's going wrong here? As you can see I do not use the -b Berksfile option, since the Berksfile is in my working directory. When I use:

bundle exec knife spork promote debug bla-cookbook --remote -VV -b Berksfile

I get:

~/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/chef-11.4.4/lib/chef/cookbook_loader.rb:103:in `[]': undefined method `to_sym' for nil:NilClass (NoMethodError)
  from ~/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/bundler/gems/knife-spork-4e15d592d100/lib/knife-spork/runner.rb:111:in `load_from_chef'
  from ~/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/bundler/gems/knife-spork-4e15d592d100/lib/knife-spork/runner.rb:104:in `load_cookbook'
  from ~/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/bundler/gems/knife-spork-4e15d592d100/lib/chef/knife/spork-promote.rb:157:in `check_cookbook_uploaded'
  from ~/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/bundler/gems/knife-spork-4e15d592d100/lib/chef/knife/spork-promote.rb:51:in `run'
  from ~/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/chef-11.4.4/lib/chef/knife.rb:460:in `run_with_pretty_exceptions'
  from ~/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/chef-11.4.4/lib/chef/knife.rb:173:in `run'
  from ~/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/chef-11.4.4/lib/chef/application/knife.rb:123:in `run'
  from ~/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/chef-11.4.4/bin/knife:25:in `<top (required)>'
  from ~/.rbenv/versions/1.9.3-p327/bin/knife:23:in `load'
  from ~/.rbenv/versions/1.9.3-p327/bin/knife:23:in `<main>'

I hope this helps you with finding a fix for this. I have no time left, but will see if I can put some more effort in finding this bug this weekend.

@RSO
Copy link
Contributor

RSO commented Jul 15, 2013

I found out that the bugs I encountered were caused by the git plugin. Disabling this plugin solved the problem for me. It would be nice to fix the git plugin before merging this.

I needed to promote a cookbook that was not part of the immediate Berksfile, but was in the Berksfile.lock as it was a dependency of a cookbook.
@RSO
Copy link
Contributor

RSO commented Jul 18, 2013

I added a pull request to this branch on sethvargo/knife-spork#1 which resolves the cookbooks from the Berksfile.lock instead of the Berksfile

RSO and others added 2 commits July 18, 2013 18:57
@sethvargo should we keep track somewhere that this can be solved
differently in master?
Allow loading cookbooks from the Berksfile.lock file
@sethvargo
Copy link
Contributor Author

@jonlives could you take a peek at this please?

@jonlives
Copy link
Owner

Awesome, will try and get this out for y'all early next week :)

@jonlives
Copy link
Owner

@RSO, @sethvargo could one of you please write a quick comment with what this has changed in the way Berkshelf is used? I don't use berkshelf locally to test - I assume this has now resolved the original issues?

@RSO
Copy link
Contributor

RSO commented Jul 22, 2013

This PR added support for Berkshelf in knife-spork promote. What this means is that when a cookbook is not found locally, knife-spork will check if the file can be found in the Berksfile.lock file. I think it might be best to add some text to the README, since there are some gotcha's, for instance: the git option in knife-spork config isn't supported.

I could see if I can find some time this week to update this PR, or maybe create another one for the git issue.

@jonlives
Copy link
Owner

Thanks @RSO :) If you have a mo to look at the git issue, that would be awesome :)

@jonlives
Copy link
Owner

jonlives commented Aug 1, 2013

@sethvargo, @RSO it looks like the issues with the git plugin lie in the Berkshelf::CachedCookbook object not having a root_dir method.

There are a couple of ways we could tackle this.

  • Don't try to git pull for objects of that type
  • Fix the logic to work with objects of that type.
  • Something else

Do either of you have any thoughts on this? I'm not a Berkshelf user so I'm hesitant to decree the fix :p

@sethvargo
Copy link
Contributor Author

@jonlives there should be methods on CachedCookbook to do what you need. What exactly are you trying to do?

@jonlives
Copy link
Owner

jonlives commented Aug 1, 2013

This part of the plugin starts with the root_dir of the cookbook object and figures out if it's a subdir of a git repo. If it is, it traverses the FS tree to find the repo root, and runs a git pull there. Same for if it's a submodule. For CachedCookbook, I basically need a method for determining where the cookbook lives :)

@sethvargo
Copy link
Contributor Author

Does .path or .cookbook_path not work?

@jonlives
Copy link
Owner

jonlives commented Aug 1, 2013

I haven't got berkshelf set up locally yet to test with - gives me a place to start looking though :)

@RSO
Copy link
Contributor

RSO commented Aug 5, 2013

I tried changing the root_dir to both cookbook_path and path, and this is what I got:

$ knife spork promote ENVIRONMENT COOKBOOK --remote -VV
Called 'load_file' without the :safe option -- defaulting to safe mode.
/Users/remon/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/bundler/gems/knife-spork-be417242c929/lib/knife-spork/plugins/git.rb:30:in `block in before_promote': undefined method `cookbook_path' for #<Berkshelf::CachedCookbook:0x007fef7aff3130> (NoMethodError)
    from /Users/remon/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/bundler/gems/knife-spork-be417242c929/lib/knife-spork/plugins/git.rb:29:in `each'
    from /Users/remon/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/bundler/gems/knife-spork-be417242c929/lib/knife-spork/plugins/git.rb:29:in `before_promote'
    from /Users/remon/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/bundler/gems/knife-spork-be417242c929/lib/knife-spork/plugins.rb:11:in `block in run'
    from /Users/remon/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/bundler/gems/knife-spork-be417242c929/lib/knife-spork/plugins.rb:9:in `each'
    from /Users/remon/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/bundler/gems/knife-spork-be417242c929/lib/knife-spork/plugins.rb:9:in `run'
    from /Users/remon/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/bundler/gems/knife-spork-be417242c929/lib/knife-spork/runner.rb:32:in `run_plugins'
    from /Users/remon/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/bundler/gems/knife-spork-be417242c929/lib/chef/knife/spork-promote.rb:46:in `run'
    from /Users/remon/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/chef-11.4.4/lib/chef/knife.rb:460:in `run_with_pretty_exceptions'
    from /Users/remon/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/chef-11.4.4/lib/chef/knife.rb:173:in `run'
    from /Users/remon/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/chef-11.4.4/lib/chef/application/knife.rb:123:in `run'
    from /Users/remon/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/chef-11.4.4/bin/knife:25:in `<top (required)>'
    from /Users/remon/.rbenv/versions/2.0.0-p247/bin/knife:23:in `load'
    from /Users/remon/.rbenv/versions/2.0.0-p247/bin/knife:23:in `<main>'

And:

$ knife spork promote ENVIRONMENT COOKBOOK --remote -VV
Called 'load_file' without the :safe option -- defaulting to safe mode.
DEBUG: No chefignore file found at /var/chef/cookbooks/chefignore no files will be ignored
DEBUG: No chefignore file found at /var/chef/site-cookbooks/chefignore no files will be ignored
/Users/remon/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/bundler/gems/knife-spork-be417242c929/lib/knife-spork/plugins/git.rb:30:in `block in before_promote': undefined method `include?' for #<Pathname:0x007fa735923130> (NoMethodError)
    from /Users/remon/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/bundler/gems/knife-spork-be417242c929/lib/knife-spork/plugins/git.rb:29:in `each'
    from /Users/remon/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/bundler/gems/knife-spork-be417242c929/lib/knife-spork/plugins/git.rb:29:in `before_promote'
    from /Users/remon/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/bundler/gems/knife-spork-be417242c929/lib/knife-spork/plugins.rb:11:in `block in run'
    from /Users/remon/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/bundler/gems/knife-spork-be417242c929/lib/knife-spork/plugins.rb:9:in `each'
    from /Users/remon/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/bundler/gems/knife-spork-be417242c929/lib/knife-spork/plugins.rb:9:in `run'
    from /Users/remon/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/bundler/gems/knife-spork-be417242c929/lib/knife-spork/runner.rb:32:in `run_plugins'
    from /Users/remon/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/bundler/gems/knife-spork-be417242c929/lib/chef/knife/spork-promote.rb:46:in `run'
    from /Users/remon/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/chef-11.4.4/lib/chef/knife.rb:460:in `run_with_pretty_exceptions'
    from /Users/remon/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/chef-11.4.4/lib/chef/knife.rb:173:in `run'
    from /Users/remon/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/chef-11.4.4/lib/chef/application/knife.rb:123:in `run'
    from /Users/remon/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/chef-11.4.4/bin/knife:25:in `<top (required)>'
    from /Users/remon/.rbenv/versions/2.0.0-p247/bin/knife:23:in `load'
    from /Users/remon/.rbenv/versions/2.0.0-p247/bin/knife:23:in `<main>'

@jonlives
Copy link
Owner

jonlives commented Aug 6, 2013

@RSO that looks like"path" will work then, but it's returning you a Pathname object, which doesn't have an include? method.

I think what would work here is testing if the cookbook is a Berkshelf::CachedCookbook, and if it is then using cookbook.path.to_s. Converting it back to a string will allow us to use the include? method as normal. You able to have a look at this? If not, I can try and get Berkshelf set up locally to do some messing around.

@RSO
Copy link
Contributor

RSO commented Aug 6, 2013

I'm on it

@jonlives
Copy link
Owner

jonlives commented Aug 6, 2013

Awesome thanks :)

@RSO
Copy link
Contributor

RSO commented Aug 6, 2013

Commit submitted in sethvargo/knife-spork#2

@jonlives
Copy link
Owner

jonlives commented Aug 6, 2013

Thanks @RSO - @sethvargo, if you could merge this into your branch and update this PR please, I'll get this tested at my end and into the new version.

Use cookbook.path.to_s when the cookbook is a CachedCookbook
@sethvargo
Copy link
Contributor Author

@jonlives done

@jonlives
Copy link
Owner

jonlives commented Aug 6, 2013

Lovely stuff, thanks!

@jonlives
Copy link
Owner

jonlives commented Aug 6, 2013

@sethvargo does this fix the original #73 referenced in this ticket? It fixes the git plugin issues, but do we still have the issue with the Berksfile coming in as a boolean?

@RSO
Copy link
Contributor

RSO commented Aug 6, 2013

Ah damn, forgot about that one, I tried and #73 still bugs. Will look in to that

@jonlives
Copy link
Owner

jonlives commented Aug 6, 2013

@RSO thanks, would be awesome if we can FIX ALL THE THINGS :p

@RSO
Copy link
Contributor

RSO commented Aug 6, 2013

Fixed in sethvargo/knife-spork#3

@sethvargo
Copy link
Contributor Author

@RSO merged

@jonlives
Copy link
Owner

jonlives commented Aug 6, 2013

You two are awesome! Thanks - will get this merged into the new release branch. Watch this space for 1.3.0 :p

jonlives added a commit that referenced this pull request Aug 6, 2013
@jonlives jonlives merged commit e964f76 into jonlives:master Aug 6, 2013
@jonlives
Copy link
Owner

knife-spork-1.3.0 released, containing this feature :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

knife spork promote with Berksfile
5 participants