Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add example for usage with swarm-cronjob #89

Merged
merged 1 commit into from
Dec 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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