From a8a528b6b443ddd6fd07044080cf12021e01230d Mon Sep 17 00:00:00 2001 From: kev Date: Tue, 20 Feb 2024 18:27:53 +0800 Subject: [PATCH] update webhook --- webhook/Dockerfile | 28 ++++++++-------- webhook/README.md | 67 ++++++++++++++++---------------------- webhook/data/hooks.json | 1 - webhook/data/hooks.yaml | 13 ++++++++ webhook/data/test.sh | 2 -- webhook/docker-compose.yml | 16 +++++---- 6 files changed, 65 insertions(+), 62 deletions(-) delete mode 100644 webhook/data/hooks.json create mode 100644 webhook/data/hooks.yaml diff --git a/webhook/Dockerfile b/webhook/Dockerfile index b0d25f5..7b8f46f 100644 --- a/webhook/Dockerfile +++ b/webhook/Dockerfile @@ -2,23 +2,25 @@ # Dockerfile for webhook # -FROM golang:alpine AS build -ENV CGO_ENABLED=0 -ENV GOOS=linux -ENV GOARCH=amd64 -ENV GO111MODULE=off -WORKDIR /go/bin -RUN apk add --no-cache git -RUN go get -d -v github.com/adnanh/webhook -RUN go build --ldflags '-s -extldflags "-static"' -i -o webhook github.com/adnanh/webhook - FROM alpine:3 MAINTAINER EasyPi Software Foundation -RUN apk add --no-cache bash coreutils curl jq -COPY --from=build /go/bin/webhook /usr/local/bin/ + +ARG WEBHOOK_VERSION=2.8.1 +ARG WEBHOOK_OS=linux +ARG WEBHOOK_ARCH=amd64 +ARG WEBHOOK_FILE=webhook-$WEBHOOK_OS-$WEBHOOK_ARCH.tar.gz +ARG WEBHOOK_URL=https://github.com/adnanh/webhook/releases/download/$WEBHOOK_VERSION/$WEBHOOK_FILE + +RUN set -xe \ + && apk add --no-cache bash coreutils curl gcompat jq \ + && curl -sSL $WEBHOOK_URL | tar xz -C /usr/local/bin ${WEBHOOK_FILE%.tar.gz}/webhook --strip 1 \ + && webhook --version + WORKDIR /etc/webhook VOLUME /etc/webhook + EXPOSE 9000 + ENTRYPOINT ["webhook"] -# Doc: https://github.com/adnanh/webhook/blob/master/docs/Webhook-Parameters.md +# See: https://github.com/adnanh/webhook/blob/master/docs/Webhook-Parameters.md CMD ["-hooks", "hooks.json", "-hooks", "hooks.yaml", "-hotreload", "-template", "-verbose"] diff --git a/webhook/README.md b/webhook/README.md index d28e5f0..6e34494 100644 --- a/webhook/README.md +++ b/webhook/README.md @@ -9,7 +9,7 @@ execute configured commands. ## Directory Tree -``` +```bash ~/fig/webhook/ ├── docker-compose.yml └── data/ @@ -17,36 +17,24 @@ execute configured commands. └── test.sh* (executable) ``` -docker-compose.yml +File: data/hooks.yaml ```yaml -webhook: - image: vimagick/webhook - ports: - - "9000:9000" - volumes: - - "./data:/etc/webhook" - restart: always +- id: test + execute-command: /etc/webhook/test.sh + pass-file-to-command: + - source: entire-payload + envname: HOOK_PAYLOAD + command-working-directory: /etc/webhook + include-command-output-in-response: true ``` -hooks.json - -```json -[ - { - "id": "test", - "execute-command": "/etc/webhook/test.sh", - "command-working-directory": "/etc/webhook", - "include-command-output-in-response": true - } -] -``` - -test.sh +File: data/test.sh ```bash #!/bin/bash echo 'hello world' +cat $HOOK_PAYLOAD ``` ## Up and Running @@ -59,26 +47,27 @@ $ chmod +x data/test.sh $ docker-compose up -d Creating webhook_webhook_1... -$ curl http://localhost:9000/hooks/test +$ curl http://localhost:9000/hooks/test -d hello=world hello world +{"hello":"world"} $ docker-compose logs 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 +webhook_1 | [webhook] 2024/02/20 04:26:52 version 2.8.1 starting +webhook_1 | [webhook] 2024/02/20 04:26:52 setting up os signal watcher +webhook_1 | [webhook] 2024/02/20 04:26:52 attempting to load hooks from hooks.json +webhook_1 | [webhook] 2024/02/20 04:26:52 loaded 1 hook(s) from file +webhook_1 | [webhook] 2024/02/20 04:26:52 > test +webhook_1 | [webhook] 2024/02/20 04:26:52 starting insecure (http) webhook on :9000 +webhook_1 | [webhook] 2024/02/20 04:26:52 os signal watcher ready +webhook_1 | [webhook] 2024/02/20 04:27:11 Started GET /hooks/test +webhook_1 | [webhook] 2024/02/20 04:27:11 Completed 200 OK in 390.207µs +webhook_1 | [webhook] 2024/02/20 04:27:11 test got matched (1 time(s)) +webhook_1 | [webhook] 2024/02/20 04:27:11 test hook triggered successfully +webhook_1 | [webhook] 2024/02/20 04:27:11 executing /scripts/test.sh (/scripts/test.sh) with arguments ["/etc/webhook/test.sh"] and environment [HOOK_PAYLOAD=/etc/webhook/HOOK_PAYLOAD967569167] using /etc/webhook as cwd +webhook_1 | [webhook] 2024/02/20 04:27:11 command output: hello world +webhook_1 | {"hello":"world"} +webhook_1 | [webhook] 2024/02/20 04:27:11 finished handling test ``` [1]: https://github.com/adnanh/webhook diff --git a/webhook/data/hooks.json b/webhook/data/hooks.json deleted file mode 100644 index fe51488..0000000 --- a/webhook/data/hooks.json +++ /dev/null @@ -1 +0,0 @@ -[] diff --git a/webhook/data/hooks.yaml b/webhook/data/hooks.yaml new file mode 100644 index 0000000..dbdf07b --- /dev/null +++ b/webhook/data/hooks.yaml @@ -0,0 +1,13 @@ +- id: test + execute-command: /etc/webhook/test.sh + pass-file-to-command: + - source: entire-payload + envname: HOOK_PAYLOAD + command-working-directory: /etc/webhook + include-command-output-in-response: true + +- id: osmand + execute-command: '/bin/echo' + pass-arguments-to-command: + - source: entire-query + response-message: "OK\n" diff --git a/webhook/data/test.sh b/webhook/data/test.sh index cb34193..92dac8e 100755 --- a/webhook/data/test.sh +++ b/webhook/data/test.sh @@ -1,5 +1,3 @@ #!/bin/bash - echo 'hello world' - cat $HOOK_PAYLOAD diff --git a/webhook/docker-compose.yml b/webhook/docker-compose.yml index 6a34fa5..3f3de86 100644 --- a/webhook/docker-compose.yml +++ b/webhook/docker-compose.yml @@ -1,7 +1,9 @@ -webhook: - image: vimagick/webhook - ports: - - "9000:9000" - volumes: - - "./data:/etc/webhook" - restart: always +version: "3.8" +services: + webhook: + image: vimagick/webhook + ports: + - "9000:9000" + volumes: + - "./data:/etc/webhook" + restart: unless-stopped