-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[examples] add an example for pre and post run command.
- Loading branch information
Showing
5 changed files
with
74 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# Examples | ||
|
||
## [cronjob](./cronjob) | ||
|
||
Run *gantry* at the specific time. | ||
|
||
## [prune-and-watchtower](./prune-and-watchtower) | ||
|
||
Run [`docker system prune`](https://docs.docker.com/engine/reference/commandline/system_prune/) and [*watchtower*](https://github.com/containrrr/watchtower) with *gantry*. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# prune and watchtower | ||
|
||
This example run `docker system prune` and *watchtower* before updating docker swarm services. | ||
|
||
* [`docker system prune`](https://docs.docker.com/engine/reference/commandline/system_prune/) removes all unused containers, networks and images. | ||
* [*watchtower*](https://github.com/containrrr/watchtower) updates standalone docker containers. | ||
* [*gantry*](https://github.com/shizunge/gantry) updates docker swarm services. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
version: "3.8" | ||
|
||
services: | ||
gantry: | ||
image: shizunge/gantry | ||
volumes: | ||
- /var/run/docker.sock:/var/run/docker.sock | ||
environment: | ||
- "GANTRY_NODE_NAME={{.Node.Hostname}}" | ||
- "GANTRY_PRE_RUN_CMD=SERVICE_NAME=gantry-prune; | ||
docker service remove $${SERVICE_NAME} 2>/dev/null; | ||
docker service create --mode global-job --name $${SERVICE_NAME} | ||
--mount type=bind,source=/var/run/docker.sock,destination=/var/run/docker.sock | ||
--entrypoint docker | ||
alpinelinux/docker-cli | ||
system prune -f; | ||
docker service logs $${SERVICE_NAME}; | ||
docker service remove $${SERVICE_NAME}; | ||
SERVICE_NAME=gantry-container; | ||
docker service remove $${SERVICE_NAME} 2>/dev/null; | ||
docker service create --mode global-job --name $${SERVICE_NAME} | ||
--mount type=bind,source=/var/run/docker.sock,destination=/var/run/docker.sock | ||
ghcr.io/containrrr/watchtower | ||
--cleanup=true | ||
--label-enable | ||
--run-once=true | ||
--stop-timeout=60s | ||
--tlsverify=true; | ||
docker service logs $${SERVICE_NAME}; | ||
docker service remove $${SERVICE_NAME}; | ||
" | ||
- "GANTRY_POST_RUN_CMD=echo \"This is a post run command.\";" | ||
- "GANTRY_SLEEP_SECONDS=0" | ||
deploy: | ||
replicas: 0 | ||
placement: | ||
constraints: | ||
- node.role==manager | ||
restart_policy: | ||
condition: none | ||
labels: | ||
- swarm.cronjob.enable=true | ||
- swarm.cronjob.schedule=45 23 0 * * * | ||
- swarm.cronjob.skip-running=true | ||
|
||
cronjob: | ||
image: crazymax/swarm-cronjob:latest | ||
volumes: | ||
- /var/run/docker.sock:/var/run/docker.sock | ||
deploy: | ||
placement: | ||
constraints: | ||
- node.role==manager |