Skip to content

Instantly share code, notes, and snippets.

@minrwhite
Forked from dnephin/compose-hooks.sh
Last active March 12, 2018 16:30
Show Gist options
  • Save minrwhite/cd33f4755b51a2f4c2f6275e0a299ed4 to your computer and use it in GitHub Desktop.
Save minrwhite/cd33f4755b51a2f4c2f6275e0a299ed4 to your computer and use it in GitHub Desktop.

Revisions

  1. minrwhite revised this gist Mar 12, 2018. 1 changed file with 16 additions and 1 deletion.
    17 changes: 16 additions & 1 deletion compose-hooks.sh
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,8 @@
    #!/bin/bash
    #!/usr/bin/env bash
    set -e

    declare -A first_start

    function handle_event() {
    local entry="$1"
    local action=$(echo $entry | jq -r '.action')
    @@ -9,10 +11,23 @@ function handle_event() {
    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
    )

  2. @dnephin dnephin revised this gist Jan 8, 2016. No changes.
  3. @dnephin dnephin created this gist Jan 8, 2016.
    18 changes: 18 additions & 0 deletions compose-hooks.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,18 @@
    #!/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
    )