webhook is a lightweight incoming webhook server to run shell commands
Last updated Jul 8, 2026
12.0k
Stars
868
Forks
119
Issues
+3
Stars/day
Attention Score
92
Topics
Language breakdown
Go 86.8%
Go Template 12.5%
Makefile 0.8%
▸ Files
click to expand
README
What is webhook? ![build-status][badge]
[webhook][w] is a lightweight configurable tool written in Go, that allows you to easily create HTTP endpoints (hooks) on your server, which you can use to execute configured commands. You can also pass data from the HTTP request (such as headers, payload or query variables) to your commands. [webhook][w] also allows you to specify rules which have to be satisfied in order for the hook to be triggered.
For example, if you're using Github or Bitbucket, you can use [webhook][w] to set up a hook that runs a redeploy script for your project on your staging server, whenever you push changes to the master branch of your project.
If you use Mattermost or Slack, you can set up an "Outgoing webhook integration" or "Slash command" to run various commands on your server, which can then report back directly to you or your channels using the "Incoming webhook integrations", or the appropriate response body.
[webhook][w] aims to do nothing more than it should do, and that is:
1. receive the request,
2. parse the headers, payload and query variables,
3. check if the specified rules for the hook are satisfied,
3. and finally, pass the specified arguments to the specified command via
command line arguments or via environment variables.
Everything else is the responsibility of the command's author.
Not what you're looking for?
|Getting started
Installation
Building from source
To get started, first make sure you've properly set up your Go 1.21 or newer environment and then run$ go build github.com/adnanh/webhook
to build the latest version of the [webhook][w].
Using package manager
Snap store
Ubuntu
If you are using Ubuntu linux (17.04 or later), you can install webhook usingsudo apt-get install webhook which will install community packaged version.
Debian
If you are using Debian linux ("stretch" or later), you can install webhook usingsudo apt-get install webhook which will install community packaged version (thanks @freeekanayaka) from https://packages.debian.org/sid/webhook
FreeBSD
If you are using FreeBSD, you can install webhook usingpkg install webhook.
Download prebuilt binaries
Prebuilt binaries for different architectures are available at GitHub Releases.Configuration
Next step is to define some hooks you want [webhook][w] to serve. [webhook][w] supports JSON or YAML configuration files, but we'll focus primarily on JSON in the following example. Begin by creating an empty file namedhooks.json. This file will contain an array of hooks the [webhook][w] will serve. Check Hook definition page to see the detailed description of what properties a hook can contain, and how to use them.
Let's define a simple hook named redeploy-webhook that will run a redeploy script located in /var/scripts/redeploy.sh. Make sure that your bash script has #!/bin/sh shebang on top.
Our hooks.json file will now look like this:
[
{
"id": "redeploy-webhook",
"execute-command": "/var/scripts/redeploy.sh",
"command-working-directory": "/var/webhook"
}
]
NOTE: If you prefer YAML, the equivalent hooks.yaml file would be:
- id: redeploy-webhook
execute-command: "/var/scripts/redeploy.sh"
command-working-directory: "/var/webhook"
You can now run [webhook][w] using
$ /path/to/webhook -hooks hooks.json -verbose
It will start up on default port 9000 and will provide you with one HTTP endpoint
http://yourserver:9000/hooks/redeploy-webhook
Check webhook parameters page to see how to override the ip, port and other settings such as hook hotreload, verbose output, etc, when starting the [webhook][w].
By performing a simple HTTP GET or POST request to that endpoint, your specified redeploy script would be executed. Neat!
However, hook defined like that could pose a security threat to your system, because anyone who knows your endpoint, can send a request and execute your command. To prevent that, you can use the "trigger-rule" property for your hook, to specify the exact circumstances under which the hook would be triggered. For example, you can use them to add a secret that you must supply as a parameter in order to successfully trigger the hook. Please check out the Hook rules page for detailed list of available rules and their usage.
Multipart Form Data
[webhook][w] provides limited support the parsing of multipart form data. Multipart form data can contain two types of parts: values and files. All form values are automatically added to thepayload scope.
Use the parse-parameters-as-json settings to parse a given value as JSON.
All files are ignored unless they match one of the following criteria:
- The
Content-Typeheader isapplication/json.
- The part is named in the
parse-parameters-as-jsonsetting.
payload map.
Templates
[webhook][w] can parse the hooks configuration file as a Go template when given the-template CLI parameter. See the Templates page for more details on template usage.
Using HTTPS
[webhook][w] by default serves hooks using http. If you want [webhook][w] to serve secure content using https, you can use the-secure flag while starting [webhook][w]. Files containing a certificate and matching private key for the server must be provided using the -cert /path/to/cert.pem and -key /path/to/key.pem flags. If the certificate is signed by a certificate authority, the cert file should be the concatenation of the server's certificate followed by the CA's certificate.
TLS version and cipher suite selection flags are available from the command line. To list available cipher suites, use the -list-cipher-suites flag. The -tls-min-version flag can be used with -list-cipher-suites.
Running behind a reverse proxy
[webhook][w] may be run behind a "reverse proxy" - another web-facing server such as Apache httpd or Nginx that accepts requests from clients and forwards them on to [webhook][h]. You can have [webhook][w] listen on a regular TCP port or on a Unix domain socket (with the-socket flag), then configure your proxy to send requests for a specific host name or sub-path over that port or socket to [webhook][w].
Note that when running in this mode the ip-whitelist trigger rule will not work as expected, since it will be checking the address of the proxy, not the client_. Client IP restrictions will need to be enforced within the proxy, before it decides whether to forward the request to [webhook][w].
CORS Headers
If you want to set CORS headers, you can use the-header name=value flag while starting [webhook][w] to set the appropriate CORS headers that will be returned with each response.
Running under systemd
On platforms that use systemd, [webhook][w] supports the socket activation mechanism. If [webhook][w] detects that it has been launched from a systemd-managed socket it will automatically use that instead of opening its own listening port. See the systemd page for full details.
Interested in running webhook inside of a Docker container?
You can use one of the following Docker images, or create your own (please read this discussion):- lwlook/webhook - This setup allows direct access to the Docker host, providing a streamlined and efficient way to manage webhooks.
Examples
Check out Hook examples page for more complex examples of hooks.Guides featuring webhook
- Plex 2 Telegram by @psyhomb - Webhook & JIRA by @perfecto25 - Trigger Ansible AWX job runs on SCM (e.g. git) commit by @jpmens - Deploy using GitHub webhooks by @awea - Setting up Automatic Deployment and Builds Using Webhooks by Will Browning - Auto deploy your Node.js app on push to GitHub in 3 simple steps by Karolis Rusenas - Automate Static Site Deployments with Salt, Git, and Webhooks by Linode - Using Prometheus to Automatically Scale WebLogic Clusters on Kubernetes by Marina Kogan - Github Pages and Jekyll - A New Platform for LACNIC Labs by Carlos Martínez Cagnazzo - How to Deploy React Apps Using Webhooks and Integrating Slack on Ubuntu by Arslan Ud Din Shafiq - Private webhooks by Thomas - Adventures in webhooks by Drake - GitHub pro tips by Spencer Lyon - XiaoMi Vacuum + Amazon Button = Dash Cleaning by c0mmensal - Set up Automated Deployments From Github With Webhook by Maxim Orlov - Kick Me Now with Webhooks By Dave Cottlehuber - VIDEO: Gitlab CI/CD configuration using Docker and adnanh/webhook to deploy on VPS - Tutorial #1 by Yes! Let's Learn Software Engineering - Integrate automatic deployment in 20 minutes using webhooks + Nginx setup by Anksus - Automatically redeploy your static blog with Gitea, Uberspace & Webhook by Arran - ... - Want to add your own? Open an Issue or create a PR :-)Community Contributions
See the [webhook-contrib][wc] repository for a collections of tools and helpers related to [webhook][w] that have been contributed by the [webhook][w] community.Need help?
Check out existing issues to see if someone else also had the same problem, or open a new one.Support active development
Sponsors
Support this project by becoming a sponsor. Your logo will show up here with a link to your website.
By contributing
This project exists thanks to all the people who contribute. Contribute!.By giving money
- OpenCollective Backer - OpenCollective Sponsor - PayPal - Patreon - Faircode - FlattrThank you to all our backers!
License
The MIT License (MIT) Copyright (c) 2015 Adnan Hajdarevic🔗 More in this category
