Search code examples
chef-infraknifegit-post-receive

rsync style knife upload of Chef Cookbooks in Git post-receive hook


I would like to knife upload in a post-receive hook of a cookbook repository. However, we have too many cookbooks to simply upload all of them anytime a change is made.

Is there a way to knife upload only changed cookbooks?


Solution

  • Sounds like you have all your cookbooks in the same repo. You can use git diff to determine the changes between HEAD and the previous commit and knife upload those results.

    git diff --name-only HEAD HEAD~1 | awk -F '/' '{ print $1 }' | sort | uniq | xargs -I % knife cookbook upload %