Search code examples
chef-infragithookschef-recipe

Manage a set of server side git hooks across multiple repositories using chef


So here are the requirements:

  1. Enable / Disable server side hooks using chef
  2. Install all/some hooks to one, or more repositories

I found various hook managers in github, but they all had limitations, or did not have integration with chef. or were client side only. Here are some hook managers i found:

  1. https://github.com/brigade/overcommit
  2. https://github.com/MatthieuBizien/git-hook-manager

or there were git hooks for chef, like:

  1. https://github.com/mattpep/santoku

so using chef, if i can setup a cookbook, which deploys files across git repos while creating links and changing permissions/ownership, that would do it too.

GitLab Community Edition (CE) is being used for remote repositories


Solution

  • Managing hook scripts is pretty much just writing or linking scripts into each git repository on the server side. http://doc.gitlab.com/ce/hooks/custom_hooks.html shows where to find the repos on your GitLab server, and then use a template or link resource to add/remove the hook on each repo. Will probably end up looking something like this:

    Dir["/var/opt/gitlab/git-data/repositories/*/*.git"].each do |repo_path|
      directory File.join(repo_path, "custom_hooks") do
        owner "gitlab" # Maybe? Check what the existing permissions look like.
        mode "755"
      end
    
      template File.join(repo_path, "custom_hooks", "pre-receive") do
        source "pre-receive.erb"
        owner "gitlab" # Like above.
        mode "755"
      end
    end