From 4998e2ee76ab60a23075d5590485dedc66591546 Mon Sep 17 00:00:00 2001 From: Arthur Bodera Date: Wed, 19 Jun 2024 10:08:59 +1000 Subject: [PATCH 1/6] Add support for granular webhooks in 00-webhook --- hooks/00-webhook | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/hooks/00-webhook b/hooks/00-webhook index 869adab..f6a9b33 100755 --- a/hooks/00-webhook +++ b/hooks/00-webhook @@ -32,3 +32,45 @@ if [ "${WEBHOOK_URL}" != "**None**" ]; then ;; esac fi + +case "${ACTION}" in + "error") + if [ "${WEBHOOK_ERROR_URL}" != "**None**" ]; then + echo "Execute error webhook call to ${WEBHOOK_ERROR_URL}" + curl --request POST \ + --url "${WEBHOOK_ERROR_URL}" \ + --header 'Content-Type: application/json' \ + --data '{"status": "error"}' \ + --max-time 10 \ + --retry 5 \ + ${WEBHOOK_EXTRA_ARGS} + fi + ;; + + "pre-backup") + if [ "${WEBHOOK_PRE_BACKUP_URL}" != "**None**" ]; then + echo "Execute pre-backup webhook call to ${WEBHOOK_PRE_BACKUP_URL}" + curl --request POST \ + --url "${WEBHOOK_PRE_BACKUP_URL}" \ + --header 'Content-Type: application/json' \ + --data '{"status": "error"}' \ + --max-time 10 \ + --retry 5 \ + ${WEBHOOK_EXTRA_ARGS} + fi + ;; + + "post-backup") + if [ "${WEBHOOK_POST_BACKUP_URL}" != "**None**" ]; then + echo "Execute post-backup webhook call to ${WEBHOOK_POST_BACKUP_URL}" + curl --request POST \ + --url "${WEBHOOK_POST_BACKUP_URL}" \ + --header 'Content-Type: application/json' \ + --data '{"status": "error"}' \ + --max-time 10 \ + --retry 5 \ + ${WEBHOOK_EXTRA_ARGS} + fi + ;; +esac + From 522c9218546eab5c8f2faff4072f7b2cba0d77d5 Mon Sep 17 00:00:00 2001 From: Arthur Bodera Date: Wed, 19 Jun 2024 10:10:39 +1000 Subject: [PATCH 2/6] Add support for granular webhooks in alpine.Dockerfile --- alpine.Dockerfile | 3 +++ 1 file changed, 3 insertions(+) diff --git a/alpine.Dockerfile b/alpine.Dockerfile index 943999c..4d94e79 100644 --- a/alpine.Dockerfile +++ b/alpine.Dockerfile @@ -30,6 +30,9 @@ ENV POSTGRES_DB="**None**" \ BACKUP_KEEP_MINS=1440 \ HEALTHCHECK_PORT=8080 \ WEBHOOK_URL="**None**" \ + WEBHOOK_ERROR_URL="**None**" \ + WEBHOOK_PRE_BACKUP_URL="**None**" \ + WEBHOOK_POST_BACKUP_URL="**None**" \ WEBHOOK_EXTRA_ARGS="" COPY hooks /hooks From efcef13be19c691bace6d92370e805e10425a1e8 Mon Sep 17 00:00:00 2001 From: Arthur Bodera Date: Wed, 19 Jun 2024 10:11:04 +1000 Subject: [PATCH 3/6] Add support for granular webhooks in debian.Dockerfile --- debian.Dockerfile | 3 +++ 1 file changed, 3 insertions(+) diff --git a/debian.Dockerfile b/debian.Dockerfile index 6fe7e50..5b77f8c 100644 --- a/debian.Dockerfile +++ b/debian.Dockerfile @@ -44,6 +44,9 @@ ENV POSTGRES_DB="**None**" \ BACKUP_KEEP_MINS=1440 \ HEALTHCHECK_PORT=8080 \ WEBHOOK_URL="**None**" \ + WEBHOOK_ERROR_URL="**None**" \ + WEBHOOK_PRE_BACKUP_URL="**None**" \ + WEBHOOK_POST_BACKUP_URL="**None**" \ WEBHOOK_EXTRA_ARGS="" COPY hooks /hooks From 7812894fdcdab298b40f038d41d0fcdcaeacda68 Mon Sep 17 00:00:00 2001 From: Arthur Bodera Date: Wed, 19 Jun 2024 10:12:53 +1000 Subject: [PATCH 4/6] Document granular webhooks. --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index 9e317bc..ac415e5 100644 --- a/README.md +++ b/README.md @@ -95,6 +95,9 @@ Most variables are the same as in the [official postgres image](https://hub.dock | SCHEDULE | [Cron-schedule](http://godoc.org/github.com/robfig/cron#hdr-Predefined_schedules) specifying the interval between postgres backups. Defaults to `@daily`. | | TZ | [POSIX TZ variable](https://www.gnu.org/software/libc/manual/html_node/TZ-Variable.html) specifying the timezone used to evaluate SCHEDULE cron (example "Europe/Paris"). | | WEBHOOK_URL | URL to be called after an error or after a successful backup (POST with a JSON payload, check `hooks/00-webhook` file for more info). Default disabled. | +| WEBHOOK_ERROR_URL | URL to be called in case backup fails. Default disabled. | +| WEBHOOK_PRE_BACKUP_URL | URL to be called when backup starts. Default disabled. | +| WEBHOOK_POST_BACKUP_URL | URL to be called when backup completes successfully. Default disabled. | | WEBHOOK_EXTRA_ARGS | Extra arguments for the `curl` execution in the webhook (check `hooks/00-webhook` file for more info). | #### Special Environment Variables From cf5f0ada3b39cfdfa33c7b61a96f19e14a7ee307 Mon Sep 17 00:00:00 2001 From: Arthur Bodera Date: Wed, 19 Jun 2024 10:14:06 +1000 Subject: [PATCH 5/6] Fix granular webhook payloads in 00-webhook --- hooks/00-webhook | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/hooks/00-webhook b/hooks/00-webhook index f6a9b33..08950e2 100755 --- a/hooks/00-webhook +++ b/hooks/00-webhook @@ -53,7 +53,7 @@ case "${ACTION}" in curl --request POST \ --url "${WEBHOOK_PRE_BACKUP_URL}" \ --header 'Content-Type: application/json' \ - --data '{"status": "error"}' \ + --data '{"status": "pre-backup"}' \ --max-time 10 \ --retry 5 \ ${WEBHOOK_EXTRA_ARGS} @@ -66,11 +66,10 @@ case "${ACTION}" in curl --request POST \ --url "${WEBHOOK_POST_BACKUP_URL}" \ --header 'Content-Type: application/json' \ - --data '{"status": "error"}' \ + --data '{"status": "post-backup"}' \ --max-time 10 \ --retry 5 \ ${WEBHOOK_EXTRA_ARGS} fi ;; esac - From d5e42112878b865751be32870878ce5ba9690e36 Mon Sep 17 00:00:00 2001 From: Pau RE Date: Thu, 20 Jun 2024 13:17:32 +0200 Subject: [PATCH 6/6] Simplify webhook logic --- hooks/00-webhook | 36 ++++++++++++++---------------------- 1 file changed, 14 insertions(+), 22 deletions(-) diff --git a/hooks/00-webhook b/hooks/00-webhook index 08950e2..37a743f 100755 --- a/hooks/00-webhook +++ b/hooks/00-webhook @@ -5,9 +5,9 @@ set -e # Possible actions: error, pre-backup, post-backup ACTION="${1}" -if [ "${WEBHOOK_URL}" != "**None**" ]; then - case "${ACTION}" in - "error") +case "${ACTION}" in + "error") + if [ "${WEBHOOK_URL}" != "**None**" ]; then echo "Execute error webhook call to ${WEBHOOK_URL}" curl --request POST \ --url "${WEBHOOK_URL}" \ @@ -16,25 +16,7 @@ if [ "${WEBHOOK_URL}" != "**None**" ]; then --max-time 10 \ --retry 5 \ ${WEBHOOK_EXTRA_ARGS} - ;; -# "pre-backup") -# echo "Nothing to do" -# ;; - "post-backup") - echo "Execute post-backup webhook call to ${WEBHOOK_URL}" - curl --request POST \ - --url "${WEBHOOK_URL}" \ - --header 'Content-Type: application/json' \ - --data '{"status": "post-backup"}' \ - --max-time 10 \ - --retry 5 \ - ${WEBHOOK_EXTRA_ARGS} - ;; - esac -fi - -case "${ACTION}" in - "error") + fi if [ "${WEBHOOK_ERROR_URL}" != "**None**" ]; then echo "Execute error webhook call to ${WEBHOOK_ERROR_URL}" curl --request POST \ @@ -61,6 +43,16 @@ case "${ACTION}" in ;; "post-backup") + if [ "${WEBHOOK_URL}" != "**None**" ]; then + echo "Execute post-backup webhook call to ${WEBHOOK_URL}" + curl --request POST \ + --url "${WEBHOOK_URL}" \ + --header 'Content-Type: application/json' \ + --data '{"status": "post-backup"}' \ + --max-time 10 \ + --retry 5 \ + ${WEBHOOK_EXTRA_ARGS} + fi if [ "${WEBHOOK_POST_BACKUP_URL}" != "**None**" ]; then echo "Execute post-backup webhook call to ${WEBHOOK_POST_BACKUP_URL}" curl --request POST \