Skip to content

Commit

Permalink
Merge pull request #4 from djmaze/add-blacklisting
Browse files Browse the repository at this point in the history
Add blacklisting
  • Loading branch information
djmaze authored Jun 3, 2017
2 parents 591ac31 + 97b78c5 commit c495f43
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
2 changes: 2 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ FROM docker

ENV SLEEP_TIME='5m'

RUN apk add --update --no-cache bash

COPY shepherd /usr/local/bin/shepherd

ENTRYPOINT ["/usr/local/bin/shepherd"]
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ A Docker swarm service for automatically updating your services whenever their b
--replicas 1 \
--constraint "node.role==manager" \
--env SLEEP_TIME="5m" \
--env BLACKLIST_SERVICES="shepherd" \
--mount type=bind,source=/var/run/docker.sock,target=/var/run/docker.sock,ro \
mazzolino/shepherd

Expand Down
20 changes: 13 additions & 7 deletions shepherd
Original file line number Diff line number Diff line change
@@ -1,21 +1,27 @@
#!/bin/ash
# shellcheck shell=dash
#!/bin/bash
set -euo pipefail

update_services() {
local blacklist="$1"

for service in $(IFS="\n" docker service ls --quiet); do
local name image_with_digest image
name="$(docker service inspect "$service" -f '{{.Spec.Name}}')"
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" --image="$image" > /dev/null
if [[ " $blacklist " != *" $name "* ]]; then
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" --image="$image" > /dev/null
fi
done
}

main() {
local blacklist="${BLACKLIST_SERVICES:-}"
[[ "$blacklist" != "" ]] && echo "Excluding services: $blacklist"

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

0 comments on commit c495f43

Please sign in to comment.