Skip to content

Commit a3c5b25

Browse files
committed
Merge branch 'andrasmaroy-master'
2 parents 218b285 + 73feedd commit a3c5b25

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

README.md

+3
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ You can prevent services from being updated by appending them to the `IGNORELIST
3535

3636
Alternatively you can specify a filter for the services you want updated using the `FILTER_SERVICES` variable. This can be anything accepted by the filtering flag in `docker service ls`.
3737

38+
You can set Shepherd to roll back a service to the previous version if the update fails by setting the `ROLLBACK_ON_FAILURE` variable.
39+
3840
You can enable private registry authentication by setting the `WITH_REGISTRY_AUTH` variable.
3941

4042
If you need to authenticate to a registry (for example in order to get around the [Docker Hub rate limits](https://www.docker.com/increase-rate-limit)), you can set the variables `REGISTRY_USER` and `REGISTRY_PASSWORD`. If you are not using Docker Hub but a private registry, set `REGISTRY_HOST` to the hostname of your registry.
@@ -62,6 +64,7 @@ Example:
6264
--env APPRISE_SIDECAR_URL="apprise-microservice:5000" \
6365
--env IMAGE_AUTOCLEAN_LIMIT="5" \
6466
--env RUN_ONCE_AND_EXIT="true" \
67+
--env ROLLBACK_ON_FAILURE="true" \
6568
--mount type=bind,source=/var/run/docker.sock,target=/var/run/docker.sock,ro \
6669
--mount type=bind,source=/root/.docker/config.json,target=/root/.docker/config.json,ro \
6770
mazzolino/shepherd

shepherd

+13-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,19 @@ update_services() {
5252
else
5353
logger "Trying to update service $name with image $image" "true"
5454

55-
docker service update "$name" $detach_option $registry_auth $no_resolve_image_flag --image="$image" > /dev/null
55+
if ! docker service update "$name" $detach_option $registry_auth $no_resolve_image_flag --image="$image" > /dev/null; then
56+
logger "Service $name update failed!"
57+
if [[ "${ROLLBACK_ON_FAILURE+x}" ]]; then
58+
logger "Rolling $name back"
59+
docker service update "$name" $detach_option $registry_auth $no_resolve_image_flag --rollback > /dev/null
60+
fi
61+
if [[ "$apprise_sidecar_url" != "" ]]; then
62+
title="[Shepherd] Service $name update failed"
63+
body="$(date) Service $name failed to update to $(docker service inspect "$name" -f '{{.Spec.TaskTemplate.ContainerSpec.Image}}')"
64+
curl -X POST -H "Content-Type: application/json" --data "{\"title\": \"$title\", \"body\": \"$body\"}" "$apprise_sidecar_url"
65+
fi
66+
continue # continue with next service
67+
fi
5668

5769
previousImage=$(docker service inspect "$name" -f '{{.PreviousSpec.TaskTemplate.ContainerSpec.Image}}')
5870
currentImage=$(docker service inspect "$name" -f '{{.Spec.TaskTemplate.ContainerSpec.Image}}')

0 commit comments

Comments
 (0)