Using Github Webhooks for Deployment

Today i want to present a little tool, which allows you to track the status of github repositories. It allows you to call shell scripts on events on your github repos.

What does it exactly do?

Imagine you have a repository containing a library distributed over several remote machines. If you update your library you have to update all copies of your work as well. To automate this task you can use Github webhooks. For this purpose we created gohub. Gohub listens on a flexible port for Github webhooks calls and reacts by executing shell scripts. These shell scripts could be used to update your distributed library.

How to use it?

First you need to create a little config.json file. A simple example looks like this:


After this you need to secure your gohub. Github just uses 4 different ips for their calls. So you can secure the access by using iptables:

iptables -A INPUT -s -p tcp -m tcp --dport <PORT> -j ACCEPT
iptables -A INPUT -s -p tcp -m tcp --dport <PORT> -j ACCEPT
iptables -A INPUT -s -p tcp -m tcp --dport <PORT> -j ACCEPT
iptables -A INPUT -s -p tcp -m tcp --dport <PORT> -j ACCEPT

Of course you can also use the capabilities of your favorite proxy like nginx or haproxy.

Last thing you have to do before starting your gohub is to set up the Github webhook. You have to do this via the Github webinterface.

  • just navigate to your repository
  • go to settings
  • go to service hooks
  • go to webhook urls
  • add the address

Important: By convention your uri must look like that:


For example:

This is important, because gohub adds a request handler for every repository - branch combination you add to your config.json.

Do not forget to click update!

Now you are ready to start your gohub server

go run main.go --config /path/to/config.json --port 8392 --log ./gohub.log

You can test your webhook by clicking on “test webhook”. You should see gohub executing your commands.

Of course you can deploy this app like described here and here.

How to contribute?

Feel free to fork the project and add new features. Also any bug notifications and bug fixes would be appreciated.