Last active
October 21, 2022 20:44
-
-
Save dnephin/c56b479810f863527e90 to your computer and use it in GitHub Desktop.
Execute a hook in './hooks/<service>/<action>' when that event is received
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -e | |
function handle_event() { | |
local entry="$1" | |
local action=$(echo $entry | jq -r '.action') | |
local service=$(echo $entry | jq -r '.service') | |
local hook="./hooks/$service/$action" | |
if [ -x "$hook" ]; then | |
"$hook" "$entry" | |
fi | |
} | |
docker-compose events --json | ( | |
while read line; do | |
handle_event "$line" | |
done | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is lovely. Thank you :)
I think it would be great if this example could be included in the docker-compose documentation page for the
events
command.