Skip to content

Commit

Permalink
Add support for specifying UPDATE_OPTIONS and ROLLBACK_OPTIONS
Browse files Browse the repository at this point in the history
  • Loading branch information
moschlar committed Jul 28, 2022
1 parent f554c8e commit 8d4857b
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 2 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## Unreleased

**Implemented enhancements:**

- Add support for specifying UPDATE_OPTIONS and ROLLBACK_OPTIONS [\#77](https://github.com/djmaze/shepherd/pull/77) ([moschlar](https://github.com/moschlar))

## [0.6.0](https://github.com/djmaze/shepherd/tree/0.6.0) (2022-01-12)

[Full Changelog](https://github.com/djmaze/shepherd/compare/0.5.0...0.6.0)
Expand Down
2 changes: 2 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ ENV SLEEP_TIME='5m'
ENV FILTER_SERVICES=''
ENV TZ='US/Eastern'
ENV VERBOSE='true'
ENV UPDATE_OPTIONS=''
ENV ROLLBACK_OPTIONS=''

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

Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ Alternatively you can specify a filter for the services you want updated using t

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 control additional parameters for the `docker service update` and `docker service update --rollback` calls using the variables `UPDATE_OPTIONS` and `ROLLBACK_OPTIONS`.

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 variable `REGISTRY_USER` and store the password either in a [docker secret](https://docs.docker.com/engine/swarm/secrets/) named `shepherd_registry_password` or in the environment variable `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 @@ -67,6 +69,7 @@ Example:
--env IMAGE_AUTOCLEAN_LIMIT="5" \
--env RUN_ONCE_AND_EXIT="true" \
--env ROLLBACK_ON_FAILURE="true" \
--env UPDATE_OPTIONS="--update-delay 30s" \
--env TZ=Europe/Berlin \
--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 \
Expand Down
2 changes: 2 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ services:
SLEEP_TIME: '5m'
FILTER_SERVICES: ''
VERBOSE: 'true'
#UPDATE_OPTIONS: '--update-delay 30s'
#ROLLBACK_OPTIONS: '--rollback-delay 0s'
volumes:
- /var/run/docker.sock:/var/run/docker.sock
deploy:
Expand Down
6 changes: 4 additions & 2 deletions shepherd
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,13 @@ update_services() {
else
logger "Trying to update service $name with image $image" "true"

if ! docker service update "$name" $detach_option $registry_auth $no_resolve_image_flag --image="$image" > /dev/null; then
# shellcheck disable=SC2086
if ! docker service update "$name" $detach_option $registry_auth $no_resolve_image_flag ${UPDATE_OPTIONS} --image="$image" > /dev/null; then
logger "Service $name update failed on $hostname!"
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
# shellcheck disable=SC2086
docker service update "$name" $detach_option $registry_auth $no_resolve_image_flag ${ROLLBACK_OPTIONS} --rollback > /dev/null
fi
if [[ "$apprise_sidecar_url" != "" ]]; then
title="[Shepherd] Service $name update failed on $hostname"
Expand Down

0 comments on commit 8d4857b

Please sign in to comment.