webhookd/README.md

152 lines
3.2 KiB
Markdown
Raw Normal View History

2015-04-20 17:26:44 +00:00
# webhookd
2014-09-19 18:46:04 +00:00
2015-12-11 13:58:57 +00:00
[![Image size](https://img.shields.io/imagelayers/image-size/ncarlier/webhookd/latest.svg)](https://hub.docker.com/r/ncarlier/webhookd/)
2015-12-11 14:00:41 +00:00
[![Docker pulls](https://img.shields.io/docker/pulls/ncarlier/webhookd.svg)](https://hub.docker.com/r/ncarlier/webhookd/)
2015-12-11 13:58:57 +00:00
2014-09-21 20:00:55 +00:00
A very simple webhook server to launch shell scripts.
2015-04-20 17:26:44 +00:00
## Installation
2014-09-21 20:00:55 +00:00
2018-01-02 16:57:27 +00:00
Run the following command:
2015-03-24 20:41:05 +00:00
2018-01-02 16:57:27 +00:00
```bash
$ go get -v github.com/ncarlier/webhookd/webhookd
```
2014-09-21 20:00:55 +00:00
2018-01-02 16:57:27 +00:00
**Or** download the binary regarding your architecture:
2014-09-21 20:00:55 +00:00
2018-01-02 16:57:27 +00:00
```bash
$ sudo curl -s https://raw.githubusercontent.com/ncarlier/webhookd/master/install.sh | sh
2015-04-20 17:26:44 +00:00
```
2014-09-21 20:00:55 +00:00
2018-01-02 16:57:27 +00:00
**Or** use Docker:
2015-03-24 20:41:05 +00:00
2018-01-02 16:57:27 +00:00
```bash
2015-04-20 17:26:44 +00:00
$ docker run -d --name=webhookd \
--env-file .env \
2015-04-20 17:26:44 +00:00
-v ${PWD}/scripts:/var/opt/webhookd/scripts \
-p 8080:8080 \
ncarlier/webhookd
2015-04-20 17:26:44 +00:00
```
2015-03-24 20:41:05 +00:00
Check the provided environment file [.env](.env) for details.
> Note that this image extends `docker:dind` Docker image. Therefore you are
> able to interact with a Docker daemon with yours shell scripts.
2015-03-24 20:41:05 +00:00
2015-04-20 17:26:44 +00:00
## Usage
2014-09-21 20:00:55 +00:00
### Directory structure
Webhooks are simple scripts dispatched into a directory structure.
2014-09-21 20:00:55 +00:00
By default inside the `./scripts` directory.
You can override the default using the `APP_SCRIPTS_DIR` environment variable.
*Example:*
2014-09-21 20:00:55 +00:00
2015-04-20 17:26:44 +00:00
```
/scripts
|--> /github
|--> /build.sh
|--> /deploy.sh
|--> /ping.sh
|--> ...
2015-04-20 17:26:44 +00:00
```
2014-09-21 20:00:55 +00:00
### Webhook URL
2015-03-24 20:41:05 +00:00
The directory structure define the webhook URL.
The Webhook can only be call with HTTP POST verb.
If the script exists, the HTTP response will be a `text/event-stream` content
type (Server-sent events).
*Example:*
The script: `./scripts/foo/bar.sh`
```bash
#!/bin/bash
echo "foo foo foo"
echo "bar bar bar"
2015-04-20 17:26:44 +00:00
```
2015-03-24 20:41:05 +00:00
```bash
$ curl -XPOST http://localhost/foo/bar
data: Hook work request "foo/bar" queued...
data: Running foo/bar script...
data: foo foo foo
data: bar bar bar
2015-03-24 20:41:05 +00:00
data: done
```
2014-09-21 20:00:55 +00:00
### Webhook parameters
2014-09-21 20:00:55 +00:00
You can add query parameters to the webhook URL.
Those parameters will be available as environment variables into the shell
script.
You can also send a payload (text/plain or application/json) as request body.
This payload will be transmit to the shell script as first parameter.
2014-09-21 20:00:55 +00:00
*Example:*
2014-09-21 20:00:55 +00:00
The script:
2014-09-21 20:00:55 +00:00
```bash
#!/bin/bash
2014-09-21 20:00:55 +00:00
echo "Environment parameters: foo=$foo"
echo "Script parameters: $1"
2015-04-20 17:26:44 +00:00
```
```bash
$ curl --data @test.json http://localhost/echo?foo=bar
data: Hook work request "echo" queued...
data: Running echo script...
data: Environment parameters: foo=bar
data: Script parameters: {"foo": "bar"}
data: done
2015-04-20 17:26:44 +00:00
```
2014-09-21 20:00:55 +00:00
### Notifications
2014-09-21 20:00:55 +00:00
The script's output is collected and stored into a log file (configured by the
`APP_WORKING_DIR` environment variable).
Once the script executed, you can send the result and this log file to a
notification channel. Currently only two channels are supported: Email and HTTP.
#### HTTP notification
HTTP notification configuration:
2014-09-21 20:00:55 +00:00
- **APP_NOTIFIER**=http
- **APP_NOTIFIER_FROM**=webhookd <noreply@nunux.org>
- **APP_NOTIFIER_TO**=hostmaster@nunux.org
- **APP_HTTP_NOTIFIER_URL**=http://requestb.in/v9b229v9
> Note that the HTTP notification is compatible with
[Mailgun](https://mailgun.com) API.
2014-09-21 20:00:55 +00:00
#### Email notification
SMTP notification configuration:
2014-09-21 20:00:55 +00:00
- **APP_NOTIFIER**=smtp
- **APP_SMTP_NOTIFIER_HOST**=localhost:25
The log file will be sent as an GZIP attachment.
---
2014-09-19 18:46:04 +00:00