-
-
Save minrwhite/cd33f4755b51a2f4c2f6275e0a299ed4 to your computer and use it in GitHub Desktop.
Execute a hook in './hooks/<service>/<action>' when that event is received - with hook for first start up
This file contains hidden or 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
#!/usr/bin/env bash | |
set -e | |
declare -A first_start | |
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 | |
if [ "$action" == "create" ]; then | |
first_start["$service"]=1 | |
fi | |
if [ "$action" == "start" ] && [ "${first_start[$service]}" -eq "1" ]; then | |
unset first_start["$service"] | |
local subhook="./hooks/$service/first_start" | |
if [ -x "$subhook" ]; then | |
"$subhook" "$entry" | |
fi | |
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