Skip to content

Commit

Permalink
Add example for usage with swarm-cronjob (#89)
Browse files Browse the repository at this point in the history
  • Loading branch information
djmaze authored Dec 23, 2022
1 parent 27e3561 commit 7df2f7f
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 2 deletions.
13 changes: 11 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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.

Expand Down Expand Up @@ -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.
Expand Down
38 changes: 38 additions & 0 deletions docker-compose.swarm-cronjob.yml
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 7df2f7f

Please sign in to comment.