Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
44 changes: 44 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,50 @@ 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.
Kubernetes-generated `WEBHOOK_PORT=tcp://...` service-link values are ignored.

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)):
Expand Down
113 changes: 113 additions & 0 deletions docker-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
#!/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
verbose|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" "$@"
Comment thread
sourcery-ai[bot] marked this conversation as resolved.
Resolved
;;
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
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
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 "$@"