adnanh webhook是一個很不錯的webhook 實現,方便靈活。
adnanh webhook 支持如下功能:git
參考git https://github.com/rongfengliang/adnanh-webhook-docker-composegithub
version: "3" services: webhook: image: almir/webhook command: ["-verbose", "-hooks=/etc/webhook/hooks.json","-hotreload"] volumes: - "./hooks.json:/etc/webhook/hooks.json" - "./shell/:/shells/" ports: - "9000:9000"
[ { "id": "simple-one", "execute-command": "/shells/app", "include-command-output-in-response":true, "include-command-output-in-response-on-error":true, "command-working-directory":"/shells", "pass-arguments-to-command": [ { "source": "payload", "name": "id" }, { "source": "url", "name": "token" } ], "trigger-rule": { "match": { "type": "value", "value": "42", "parameter": { "source": "url", "name": "token" } } } } ]
#!/bin/sh echo $@ , $1, $2
對於請求參數包含token=42 的纔會執行shell 命令,同時將url 參數token 以及payload(post請求)中的id,傳遞給shell
同時配置了將shell 結果輸出到響應,從運行模式來看就相似當前serverless框架的運行原理。web
curl -X POST \ 'http://localhost:9000/hooks/simple-one?token=44' \ -H 'cache-control: no-cache' \ -H 'content-type: application/json' \ -H 'postman-token: 85f3425b-a0a7-cf80-c49a-87299d905a6c' \ -d '{ "id":"dalongdemo" }' Hook rules were not satisfied
curl -X POST \ 'http://localhost:9000/hooks/simple-one?token=42' \ -H 'cache-control: no-cache' \ -H 'content-type: application/json' \ -H 'postman-token: 76d20d8d-a72e-9ae4-2570-115f57479116' \ -d '{ "id":"dalongdemo" }' dalongdemo 42 , dalongdemo, 42
https://github.com/rongfengliang/adnanh-webhook-docker-compose
https://github.com/adnanh/webhook/blob/master/docs/Referencing-Request-Values.mddocker