GIT to manage cookbooks

Hi,

I am not that new to chef but I am new to git with chef. What I would like to do is manage all of the cookbooks using git and updating the chef server the same way bypassing knife. Is there a write up on how to do this? Is this even recommended?

Thanks!

1 Like

How were you managing them before?
I use 1 git repo per cookbook… so the cookbook itself is a git repo…

The chef server doesn’t even care what you use to manage and has no understanding of the git files really… chef cares about the metadata.rb for example as thats how information and specifically the version for a cookbook is read/stored from

there is no way to ‘bypass’ knife / berks / any other tool to upload to the chef server (this is just a small constraint your workflow must learn to exploit) as in… have your cookbooks be in git… have some kind of testing for those git repod cookbooks (use it in CI) let your CI decide things are ‘good’ and then push up to the chef server when your tests pass or something like that.

thats up to you to implement… but git itself wont do anything from the chef servers point of view. Your team and workflows need that.

Thanks, I am using GIT for the cookbooks themselves. I should have been a little more clear. I was just looking at adopting a workflow that would allow the chef server to be updated automagically by either pulling the repositories or getting the repositories pushed to it. It seems like the latter is what is being used currently. We are a smaller shop but I wanted to get this in place early in case we expand out. We also are using Jenkins so maybe have Jenkins push to Chef?

Managing cookbooks with git is as easy as managing any other code with git. The only question is whether you create one git repository for each cookbook, or a single monolithic one.

The general recommendation seems to be a separate git repo for each cookbook.

On using git to update the chef server: don’t. Use the right tool for the job. The chef server doesn’t simply store files in some directory, but also includes a database that needs to be updated for chef to work correctly. You could conceivably talk to Chef’s API over https.

knife isn’t the right tool for the job, either. The recommended tool for uploading and managing cookbooks is berkshelf.

What many people in your situation seem to be doing is use git hooks to trigger uploading cookbooks using the standard tools. I haven’t had that need yet, so I can’t tell exactly how it works.

Kevin Keane
Whom the IT Pros Call
The NetTech
http://www.4nettech.com
Our values: Privacy, Liberty, Justice
See https://www.4nettech.com/corp/the-nettech-values.html

There are two tools (one is a fork) that might do what you want:

github.com/facebook/grocery-delivery and
github.com/one-com/running_sushi

Those tools removes all the manual use of knife, berkshelf and makes git the authoritative source.

smuckers see this example here:

We use gitlab-ci. Every time a change is pushed to the master branch of a cookbook, gitlab-ci basically runs a berks install and a berks upload. To release a new cookbook, all we have to do is change the version inside the metadata.rb and merge to master.

This only works if you are able to use protected branches (which gitlab-ci supports).