Skip to content

Commit

Permalink
Merge pull request #5 from djmaze/0.2-fixes
Browse files Browse the repository at this point in the history
Fixes for 0.2
  • Loading branch information
djmaze authored Jun 3, 2017
2 parents 31f6ff3 + 43138d8 commit 0cee1cb
Showing 1 changed file with 23 additions and 5 deletions.
28 changes: 23 additions & 5 deletions shepherd
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
#!/bin/bash
set -euo pipefail

server_version() {
docker version -f "{{.Server.Version}}"
}

update_services() {
local blacklist="$1"
local supports_detach_option=$2
local detach_option=""
[ $supports_detach_option = true ] && detach_option="--detach=false"

for service in $(IFS="\n" docker service ls --quiet); do
local name image_with_digest image
Expand All @@ -11,19 +18,30 @@ update_services() {
image_with_digest="$(docker service inspect "$service" -f '{{.Spec.TaskTemplate.ContainerSpec.Image}}')"
image=$(echo "$image_with_digest" | cut -d@ -f1)
echo "Updating service $name with image $image"
docker service update "$service" --detach=false --image="$image" > /dev/null
docker service update "$service" $detach_option --image="$image" > /dev/null
fi
done
}

main() {
local blacklist="${BLACKLIST_SERVICES:-}"
local blacklist sleep_time supports_detach_option
blacklist="${BLACKLIST_SERVICES:-}"
sleep_time="${SLEEP_TIME:-5m}"

supports_detach_option=false
if [[ "$(server_version)" > "17.05" ]]; then
supports_detach_option=true
echo "Enabling synchronous service updates"
else
supports_detach_option=false
fi

[[ "$blacklist" != "" ]] && echo "Excluding services: $blacklist"

while true; do
update_services "${blacklist}"
echo "Sleeping ${SLEEP_TIME} before next update"
sleep "${SLEEP_TIME}"
update_services "$blacklist" "$supports_detach_option"
echo "Sleeping $sleep_time before next update"
sleep "$sleep_time"
done
}

Expand Down

0 comments on commit 0cee1cb

Please sign in to comment.