Skip to content

Commit

Permalink
Merge branch 'andrasmaroy-master'
Browse files Browse the repository at this point in the history
  • Loading branch information
djmaze committed Jan 12, 2022
2 parents 218b285 + 73feedd commit a3c5b25
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ You can prevent services from being updated by appending them to the `IGNORELIST

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`.

You can set Shepherd to roll back a service to the previous version if the update fails by setting the `ROLLBACK_ON_FAILURE` variable.

You can enable private registry authentication by setting the `WITH_REGISTRY_AUTH` variable.

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.
Expand Down Expand Up @@ -62,6 +64,7 @@ Example:
--env APPRISE_SIDECAR_URL="apprise-microservice:5000" \
--env IMAGE_AUTOCLEAN_LIMIT="5" \
--env RUN_ONCE_AND_EXIT="true" \
--env ROLLBACK_ON_FAILURE="true" \
--mount type=bind,source=/var/run/docker.sock,target=/var/run/docker.sock,ro \
--mount type=bind,source=/root/.docker/config.json,target=/root/.docker/config.json,ro \
mazzolino/shepherd
Expand Down
14 changes: 13 additions & 1 deletion shepherd
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,19 @@ update_services() {
else
logger "Trying to update service $name with image $image" "true"

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

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

0 comments on commit a3c5b25

Please sign in to comment.