From 7e14cc3bbf3fd2d8d3ae8e58d9d10f1fc66a2fe7 Mon Sep 17 00:00:00 2001 From: Serhiy Bobrov Date: Thu, 26 Nov 2026 17:15:24 +0200 Subject: [PATCH 1/3] feat(docker): support WEBHOOK environment variables Map Docker environment variables to webhook flags and document the full mapping. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- Dockerfile | 3 +- README.md | 43 +++++++++++++++++++++++++++ docker-entrypoint.sh | 70 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 115 insertions(+), 1 deletion(-) create mode 100644 docker-entrypoint.sh diff --git a/Dockerfile b/Dockerfile index 7b2dd78c..00d914f1 100644 --- a/Dockerfile +++ b/Dockerfile @@ -16,5 +16,6 @@ FROM alpine:3.24@sha256:f59abe656b692d901e184be3445e084786602108599d2a51d229c0f5 RUN apk add --no-cache ca-certificates WORKDIR /etc/webhook COPY --from=build /webhook /usr/local/bin/webhook +COPY docker-entrypoint.sh /usr/local/bin/docker-entrypoint.sh EXPOSE 9000 -ENTRYPOINT ["webhook"] +ENTRYPOINT ["/bin/sh", "/usr/local/bin/docker-entrypoint.sh"] diff --git a/README.md b/README.md index 445790f3..e8b4398a 100644 --- a/README.md +++ b/README.md @@ -129,6 +129,49 @@ docker run --rm -p 9000:9000 \ ghcr.io/baragoon/webhook:latest -hooks /etc/webhook/hooks.json -verbose ``` +Docker environment variables are available for all command-line flags. Use the `WEBHOOK_` prefix, uppercase flag names, and replace hyphens with underscores: + +| Environment variable | Flag | +| --- | --- | +| `WEBHOOK_IP` | `-ip` | +| `WEBHOOK_PORT` | `-port` | +| `WEBHOOK_VERBOSE` | `-verbose` | +| `WEBHOOK_LOGFILE` | `-logfile` | +| `WEBHOOK_DEBUG` | `-debug` | +| `WEBHOOK_NOPANIC` | `-nopanic` | +| `WEBHOOK_HOTRELOAD` | `-hotreload` | +| `WEBHOOK_URLPREFIX` | `-urlprefix` | +| `WEBHOOK_SECURE` | `-secure` | +| `WEBHOOK_TEMPLATE` | `-template` | +| `WEBHOOK_CERT` | `-cert` | +| `WEBHOOK_KEY` | `-key` | +| `WEBHOOK_VERSION` | `-version` | +| `WEBHOOK_LIST_CIPHER_SUITES` | `-list-cipher-suites` | +| `WEBHOOK_TLS_MIN_VERSION` | `-tls-min-version` | +| `WEBHOOK_CIPHER_SUITES` | `-cipher-suites` | +| `WEBHOOK_X_REQUEST_ID` | `-x-request-id` | +| `WEBHOOK_X_REQUEST_ID_LIMIT` | `-x-request-id-limit` | +| `WEBHOOK_MAX_MULTIPART_MEM` | `-max-multipart-mem` | +| `WEBHOOK_HTTP_METHODS` | `-http-methods` | +| `WEBHOOK_PIDFILE` | `-pidfile` | +| `WEBHOOK_HOOKS` | `-hooks` | +| `WEBHOOK_HEADER` | `-header` | +| `WEBHOOK_SOCKET` | `-socket` | +| `WEBHOOK_SETGID` | `-setgid` | +| `WEBHOOK_SETUID` | `-setuid` | + +Boolean variables accept `true`/`false` or `1`/`0`. `WEBHOOK_HOOKS` and `WEBHOOK_HEADER` accept newline-separated values, prepended in listed order before command-line arguments (including any `--` terminator). Environment variables provide defaults for scalar options, so explicit command-line arguments take precedence. + +For example: + +```bash +docker run --rm -p 9000:9000 \ + -e WEBHOOK_HOOKS=/etc/webhook/hooks.json \ + -e WEBHOOK_VERBOSE=true \ + -v "$PWD/hooks.json:/etc/webhook/hooks.json:ro" \ + ghcr.io/baragoon/webhook:latest +``` + Mount any scripts used by your hooks into the container. The image includes Alpine's shell and CA certificates; commands requiring other tools need a custom image. You can use one of the following Docker images, or create your own (please read [this discussion](https://github.com/baragoon/webhook/issues/63)): diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh new file mode 100644 index 00000000..59292bb2 --- /dev/null +++ b/docker-entrypoint.sh @@ -0,0 +1,70 @@ +#!/bin/sh +set -eu + +while IFS=' ' read -r flag env_name kind; do + [ -n "$flag" ] || continue + if value="$(printenv "$env_name" 2>/dev/null)"; then + case "$kind" in + value) + set -- "-$flag" "$value" "$@" + ;; + bool) + case "$value" in + true|1) + set -- "-$flag" "$@" + ;; + false|0) + set -- "-$flag=false" "$@" + ;; + *) + printf 'error: %s must be true, false, 1, or 0\n' "$env_name" >&2 + exit 2 + ;; + esac + ;; + list) + # Reverse before prepending so list values retain their original order. + reversed_value="$(printf '%s\n' "$value" | awk '{ values[NR] = $0 } END { for (i = NR; i > 0; i--) print values[i] }')" + old_ifs=$IFS + IFS=' +' + set -f + for item in $reversed_value; do + [ -n "$item" ] || continue + set -- "-$flag" "$item" "$@" + done + set +f + IFS=$old_ifs + ;; + esac + fi +done <<'ENV_FLAGS' +ip WEBHOOK_IP value +port WEBHOOK_PORT value +verbose WEBHOOK_VERBOSE bool +logfile WEBHOOK_LOGFILE value +debug WEBHOOK_DEBUG bool +nopanic WEBHOOK_NOPANIC bool +hotreload WEBHOOK_HOTRELOAD bool +urlprefix WEBHOOK_URLPREFIX value +secure WEBHOOK_SECURE bool +template WEBHOOK_TEMPLATE bool +cert WEBHOOK_CERT value +key WEBHOOK_KEY value +version WEBHOOK_VERSION bool +list-cipher-suites WEBHOOK_LIST_CIPHER_SUITES bool +tls-min-version WEBHOOK_TLS_MIN_VERSION value +cipher-suites WEBHOOK_CIPHER_SUITES value +x-request-id WEBHOOK_X_REQUEST_ID bool +x-request-id-limit WEBHOOK_X_REQUEST_ID_LIMIT value +max-multipart-mem WEBHOOK_MAX_MULTIPART_MEM value +http-methods WEBHOOK_HTTP_METHODS value +pidfile WEBHOOK_PIDFILE value +hooks WEBHOOK_HOOKS list +header WEBHOOK_HEADER list +socket WEBHOOK_SOCKET value +setgid WEBHOOK_SETGID value +setuid WEBHOOK_SETUID value +ENV_FLAGS + +exec /usr/local/bin/webhook "$@" From 2afbe70c74aa70405b25dcc55ddc8cee70058f77 Mon Sep 17 00:00:00 2001 From: Serhiy Bobrov Date: Thu, 26 Nov 2026 17:48:07 +0200 Subject: [PATCH 2/3] fix(docker): honor CLI overrides for env vars Ignore Kubernetes service-link URIs for WEBHOOK_PORT and omit overridden environment defaults before flag parsing. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- README.md | 1 + docker-entrypoint.sh | 43 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+) diff --git a/README.md b/README.md index e8b4398a..ee571b27 100644 --- a/README.md +++ b/README.md @@ -161,6 +161,7 @@ Docker environment variables are available for all command-line flags. Use the ` | `WEBHOOK_SETUID` | `-setuid` | Boolean variables accept `true`/`false` or `1`/`0`. `WEBHOOK_HOOKS` and `WEBHOOK_HEADER` accept newline-separated values, prepended in listed order before command-line arguments (including any `--` terminator). Environment variables provide defaults for scalar options, so explicit command-line arguments take precedence. +Kubernetes-generated `WEBHOOK_PORT=tcp://...` service-link values are ignored. For example: diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh index 59292bb2..962c177f 100644 --- a/docker-entrypoint.sh +++ b/docker-entrypoint.sh @@ -1,9 +1,52 @@ #!/bin/sh set -eu +collect_cli_flags() { + _cli_flags='|' + while [ "$#" -gt 0 ]; do + _cli_arg=$1 + shift + case "$_cli_arg" in + --) break ;; + -?*) ;; + *) break ;; + esac + _cli_name=${_cli_arg#-} + _cli_name=${_cli_name#-} + case "$_cli_name" in + *=*) + _cli_name=${_cli_name%%=*} + _cli_has_value=true + ;; + *) + _cli_has_value=false + ;; + esac + _cli_flags="${_cli_flags}${_cli_name}|" + case "$_cli_name" in + debug|nopanic|hotreload|secure|template|version|list-cipher-suites|x-request-id) + ;; + *) + if [ "$_cli_has_value" = false ] && [ "$#" -gt 0 ]; then + shift + fi + ;; + esac + done + printf '%s' "$_cli_flags" +} + +cli_flags="$(collect_cli_flags "$@")" + while IFS=' ' read -r flag env_name kind; do [ -n "$flag" ] || continue + case "$cli_flags" in *"|$flag|"*) [ "$kind" = list ] || continue ;; esac if value="$(printenv "$env_name" 2>/dev/null)"; then + if [ "$flag" = port ]; then + case "$value" in + tcp://*) continue ;; + esac + fi case "$kind" in value) set -- "-$flag" "$value" "$@" From 2f460608d11637c688aad6f17836ada5e0ef9e38 Mon Sep 17 00:00:00 2001 From: Serhiy Bobrov Date: Thu, 26 Nov 2026 17:51:37 +0200 Subject: [PATCH 3/3] fix(docker): parse verbose as a boolean flag Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- docker-entrypoint.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh index 962c177f..2afd0f17 100644 --- a/docker-entrypoint.sh +++ b/docker-entrypoint.sh @@ -24,7 +24,7 @@ collect_cli_flags() { esac _cli_flags="${_cli_flags}${_cli_name}|" case "$_cli_name" in - debug|nopanic|hotreload|secure|template|version|list-cipher-suites|x-request-id) + verbose|debug|nopanic|hotreload|secure|template|version|list-cipher-suites|x-request-id) ;; *) if [ "$_cli_has_value" = false ] && [ "$#" -gt 0 ]; then