Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add blacklisting #4

Merged
merged 2 commits into from
Jun 3, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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