- Notifications
You must be signed in to change notification settings - Fork841
webhook is a lightweight incoming webhook server to run shell commands
License
adnanh/webhook
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
webhook 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 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 usewebhook 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 aims to do nothing more than it should do, and that is:
- receive the request,
- parse the headers, payload and query variables,
- check if the specified rules for the hook are satisfied,
- and finally, pass the specified arguments to the specified command viacommand line arguments or via environment variables.
Everything else is the responsibility of the command's author.
To get started, first make sure you've properly set up yourGo 1.21 or newer environment and then run
$ go build github.com/adnanh/webhook
to build the latest version of thewebhook.
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.
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) fromhttps://packages.debian.org/sid/webhook
If you are using FreeBSD, you can install webhook usingpkg install webhook
.
Prebuilt binaries for different architectures are available atGitHub Releases.
Next step is to define some hooks you wantwebhook to serve.webhook 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 thewebhook will serve. CheckHook 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 namedredeploy-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.
Ourhooks.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 equivalenthooks.yaml
file would be:
-id:redeploy-webhookexecute-command:"/var/scripts/redeploy.sh"command-working-directory:"/var/webhook"
You can now runwebhook 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
Checkwebhook parameters page to see how to override the ip, port and other settings such as hook hotreload, verbose output, etc, when starting thewebhook.
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 theHook rules page for detailed list of available rules and their usage.
webhook provides limited support the parsing of multipart form data.Multipart form data can contain two types of parts: values and files.All formvalues are automatically added to thepayload
scope.Use theparse-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-Type
header isapplication/json
. - The part is named in the
parse-parameters-as-json
setting.
In either case, the given file part will be parsed as JSON and added to thepayload
map.
webhook can parse the hooks configuration file as a Go template when given the-template
CLI parameter. See theTemplates page for more details on template usage.
webhook by default serves hooks using http. If you wantwebhook to serve secure content using https, you can use the-secure
flag while startingwebhook. 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
.
webhook may be run behind a "reverse proxy" - another web-facing server such asApache httpd orNginx that accepts requests from clients and forwards them on to [webhook][h]. You can havewebhook 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 towebhook.
Note that when running in this mode theip-whitelist
trigger rule will not work as expected, since it will be checking the address of theproxy, not theclient. Client IP restrictions will need to be enforced within the proxy, before it decides whether to forward the request towebhook.
If you want to set CORS headers, you can use the-header name=value
flag while startingwebhook to set the appropriate CORS headers that will be returned with each response.
On platforms that usesystemd,webhook supports thesocket activation mechanism. Ifwebhook detects that it has been launched from a systemd-managed socket it will automatically use that instead of opening its own listening port. Seethe systemd page for full details.
You can use one of the following Docker images, or create your own (please readthis discussion):
- almir/webhook
- roxedus/webhook
- thecatlady/webhook
- lwlook/webhook - This setup allows direct access to the Docker host, providing a streamlined and efficient way to manage webhooks.
Check outHook examples page for more complex examples of hooks.
- 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 byWill 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 byLinode
- Using Prometheus to Automatically Scale WebLogic Clusters on Kubernetes byMarina Kogan
- Github Pages and Jekyll - A New Platform for LACNIC Labs byCarlos Martínez Cagnazzo
- How to Deploy React Apps Using Webhooks and Integrating Slack on Ubuntu by Arslan Ud Din Shafiq
- Private webhooks byThomas
- Adventures in webhooks byDrake
- GitHub pro tips bySpencer Lyon
- XiaoMi Vacuum + Amazon Button = Dash Cleaning byc0mmensal
- Set up Automated Deployments From Github With Webhook byMaxim 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 byYes! Let's Learn Software Engineering
- Integrate automatic deployment in 20 minutes using webhooks + Nginx setup byAnksus
- Automatically redeploy your static blog with Gitea, Uberspace & Webhook byArran
- Automatically Updating My Zola Site Using a Webhook byÓscar Fernández
- ...
- Want to add your own? Open an Issue or create a PR :-)
See thewebhook-contrib repository for a collections of tools and helpers related towebhook that have been contributed by thewebhook community.
Check outexisting issues to see if someone else also had the same problem, oropen a new one.
DigitalOcean is a simple and robust cloud computing platform, designed for developers.
BrowserStack is a cloud-based cross-browser testing tool that enables developers to test their websites across various browsers on different operating systems and mobile devices, without requiring users to install virtual machines, devices or emulators.
Support this project by becoming a sponsor. Your logo will show up here with a link to your website.
This project exists thanks to all the people who contribute.Contribute!.
Thank you to all our backers!
The MIT License (MIT)
Copyright (c) 2015 Adnan Hajdarevicadnanh@gmail.com
Permission is hereby granted, free of charge, to any person obtaining a copyof this software and associated documentation files (the "Software"), to dealin the Software without restriction, including without limitation the rightsto use, copy, modify, merge, publish, distribute, sublicense, and/or sellcopies of the Software, and to permit persons to whom the Software isfurnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included inall copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS ORIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THEAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHERLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS INTHE SOFTWARE.
About
webhook is a lightweight incoming webhook server to run shell commands