Skip to content

Instantly share code, notes, and snippets.

@briceburg
Forked from dnephin/compose-hooks.sh
Created February 20, 2016 17:38
Show Gist options
  • Save briceburg/9e376a3abf3d9f299b35 to your computer and use it in GitHub Desktop.
Save briceburg/9e376a3abf3d9f299b35 to your computer and use it in GitHub Desktop.
Execute a hook in './hooks/<service>/<action>' when that event is received
#!/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