diff --git a/README.md b/README.md index 4ce8043..610fb5e 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ docker service create \ shizunge/gantry ``` -Or with docker compose, see the [example](examples/docker-compose.yml). +Or with docker compose, see the [example](examples/README.md). You can also run *Gantry* as a script outside the container `source ./src/entrypoint.sh`. *Gantry* is written to work with `busybox ash` as well as `bash`. diff --git a/examples/README.md b/examples/README.md new file mode 100644 index 0000000..bbabf36 --- /dev/null +++ b/examples/README.md @@ -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*. + diff --git a/examples/docker-compose.yml b/examples/cronjob/docker-compose.yml similarity index 79% rename from examples/docker-compose.yml rename to examples/cronjob/docker-compose.yml index 4e52cd7..b3ac1a0 100644 --- a/examples/docker-compose.yml +++ b/examples/cronjob/docker-compose.yml @@ -7,7 +7,8 @@ services: - /var/run/docker.sock:/var/run/docker.sock environment: - "GANTRY_NODE_NAME={{.Node.Hostname}}" - - "GANTRY_SERVICES_SELF=${STACK}_gantry" + # The gantry service is able to find the name of itself service. Use GANTRY_SERVICES_SELF when you want to set a different value. + # - "GANTRY_SERVICES_SELF=${STACK}_gantry" - "GANTRY_SLEEP_SECONDS=0" deploy: replicas: 0 diff --git a/examples/prune-and-watchtower/README.md b/examples/prune-and-watchtower/README.md new file mode 100644 index 0000000..9389e98 --- /dev/null +++ b/examples/prune-and-watchtower/README.md @@ -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. + diff --git a/examples/prune-and-watchtower/docker-compose.yml b/examples/prune-and-watchtower/docker-compose.yml new file mode 100644 index 0000000..1c6a8f0 --- /dev/null +++ b/examples/prune-and-watchtower/docker-compose.yml @@ -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