From 7df2f7fbbd5bce5b20211b667fef97675d02c8cf Mon Sep 17 00:00:00 2001 From: Martin Honermeyer <7229+djmaze@users.noreply.github.com> Date: Fri, 23 Dec 2022 22:58:15 +0100 Subject: [PATCH] Add example for usage with swarm-cronjob (#89) --- README.md | 13 +++++++++-- docker-compose.swarm-cronjob.yml | 38 ++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+), 2 deletions(-) create mode 100644 docker-compose.swarm-cronjob.yml diff --git a/README.md b/README.md index 111e359..c36c081 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ A Docker swarm service for automatically updating your services whenever their b --mount type=bind,source=/var/run/docker.sock,target=/var/run/docker.sock,ro \ mazzolino/shepherd -## Or with docker-compose +### Or with Docker Compose version: "3" services: @@ -27,7 +27,7 @@ A Docker swarm service for automatically updating your services whenever their b constraints: - node.role == manager -### Configuration +## Configuration Shepherd will try to update your services every 5 minutes by default. You can adjust this value using the `SLEEP_TIME` variable. @@ -109,6 +109,15 @@ Example: --mount type=bind,source=/root/.docker/config.json,target=/root/.docker/config.json,ro \ mazzolino/shepherd +## Running on a cron schedule + +When running shepherd as described with a `SLEEP_TIME`, the de facto running times will drift the longer the container is running. If you want to run shepherd on a fixed schedule instead, it is recommended to pair it with [swarm-cronjob](https://github.com/crazy-max/swarm-cronjob): + +1. Create a *swarm-cronjob* service [as described in its documentation](https://crazymax.dev/swarm-cronjob/install/docker/#usage). +2. Set `RUN_ONCE_AND_EXIT` to `true`, `replicas` to `0` and `restart_policy` to `condition: none`. Add docker labels for the schedule. + +See [docker-compose.swarm-cronjob.yml](docker-compose.swarm-cronjob.yml) for a full stack example which includes both shepherd as well as swarm-cronjob. + ## How does it work? Shepherd just triggers updates by updating the image specification for each service, removing the current digest. diff --git a/docker-compose.swarm-cronjob.yml b/docker-compose.swarm-cronjob.yml new file mode 100644 index 0000000..d05ac92 --- /dev/null +++ b/docker-compose.swarm-cronjob.yml @@ -0,0 +1,38 @@ +version: "3" + +services: + app: + build: . + image: mazzolino/shepherd + environment: + TZ: 'US/Eastern' + FILTER_SERVICES: '' + IGNORELIST_SERVICES: "test" + RUN_ONCE_AND_EXIT: "true" + volumes: + - /var/run/docker.sock:/var/run/docker.sock:ro + deploy: + replicas: 0 + restart_policy: + condition: none + labels: + - swarm.cronjob.enable=true + # Start service every day at midnight + - swarm.cronjob.schedule=0 0 0 * * * + - swarm.cronjob.skip-running=true + placement: + constraints: + - node.role == manager + + scheduler: + image: crazymax/swarm-cronjob:latest + volumes: + - /var/run/docker.sock:/var/run/docker.sock:ro + environment: + - "TZ=Europe/Berlin" + - "LOG_LEVEL=info" + - "LOG_JSON=false" + deploy: + placement: + constraints: + - node.role == manager