1
0
mirror of https://github.com/vimagick/dockerfiles.git synced 2024-12-16 11:37:32 +02:00
dockerfiles/webhook/README.md

94 lines
2.4 KiB
Markdown
Raw Normal View History

2015-11-05 05:32:10 +02:00
webhook
=======
2015-11-05 06:31:44 +02:00
![](https://badge.imagelayers.io/vimagick/webhook:latest.svg)
2015-11-05 05:32:10 +02:00
[webhook][1] 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.
2016-01-25 18:48:50 +02:00
## Build Binary
To build a docker image from scratch, we need to build static linked binary.
```bash
$ go get -d github.com/adnanh/webhook
$ CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -installsuffix cgo -ldflags '-s -extld ld -extldflags -static' -a -x -o webhook github.com/adnanh/webhook
$ file webhook
```
2015-11-05 06:20:42 +02:00
## Directory Tree
```
~/fig/webhook/
├── docker-compose.yml
└── scripts/
├── hooks.json
2015-11-05 06:31:44 +02:00
└── test.sh* (executable)
2015-11-05 06:20:42 +02:00
```
docker-compose.yml
```
webhook:
image: vimagick/webhook
command: -hooks hooks.json -verbose
ports:
- "9000:9000"
volumes:
- "./scripts:/scripts"
2015-11-05 06:31:44 +02:00
restart: always
2015-11-05 06:20:42 +02:00
```
hooks.json
```
[
{
"id": "test",
"execute-command": "/scripts/test.sh",
"command-working-directory": "/scripts"
}
]
```
test.sh
```
#!/bin/bash
echo 'hello world'
```
## Up and Running
```
2015-11-05 06:31:44 +02:00
$ cd ~/fig/webhook/
2016-01-25 12:16:08 +02:00
$ chmod +x scripts/test.sh
2015-11-05 06:20:42 +02:00
$ docker-compose up -d
2015-11-05 06:31:44 +02:00
Creating webhook_webhook_1...
$ curl http://localhost:9000/hooks/test
2015-11-05 06:20:42 +02:00
$ docker-compose logs
2015-11-05 06:31:44 +02:00
Attaching to webhook_webhook_1
webhook_1 | [webhook] 2015/11/05 04:26:52 version 2.3.5 starting
webhook_1 | [webhook] 2015/11/05 04:26:52 setting up os signal watcher
webhook_1 | [webhook] 2015/11/05 04:26:52 attempting to load hooks from hooks.json
webhook_1 | [webhook] 2015/11/05 04:26:52 loaded 1 hook(s) from file
webhook_1 | [webhook] 2015/11/05 04:26:52 > test
webhook_1 | [webhook] 2015/11/05 04:26:52 starting insecure (http) webhook on :9000
webhook_1 | [webhook] 2015/11/05 04:26:52 os signal watcher ready
webhook_1 | [webhook] 2015/11/05 04:27:11 Started GET /hooks/test
webhook_1 | [webhook] 2015/11/05 04:27:11 Completed 200 OK in 390.207µs
webhook_1 | [webhook] 2015/11/05 04:27:11 test got matched (1 time(s))
webhook_1 | [webhook] 2015/11/05 04:27:11 test hook triggered successfully
webhook_1 | [webhook] 2015/11/05 04:27:11 executing /scripts/test.sh (/scripts/test.sh) with arguments [/scripts/test.sh] using /scripts as cwd
webhook_1 | [webhook] 2015/11/05 04:27:11 command output: hello world
webhook_1 |
webhook_1 | [webhook] 2015/11/05 04:27:11 finished handling test
2015-11-05 06:20:42 +02:00
```
2015-11-05 05:32:10 +02:00
[1]: https://github.com/adnanh/webhook