# Gantry - Docker service updater
[](https://github.com/shizunge/gantry/releases/latest)
[](https://github.com/shizunge/gantry/blob/main/LICENSE)
[](https://hub.docker.com/r/shizunge/gantry)
[](https://hub.docker.com/r/shizunge/gantry)
[](https://github.com/shizunge/gantry/actions/workflows/on-push.yml)
[](https://codecov.io/gh/shizunge/gantry)
[](https://www.codefactor.io/repository/github/shizunge/gantry)
[*Gantry*](https://github.com/shizunge/gantry) automatically updates selected docker swarm services to newer images with the same tag. It is inspired by but [enhanced Shepherd](docs/migration.md).
## Usage
*Gantry* is released as a container [image](https://hub.docker.com/r/shizunge/gantry). You can create a docker service and run it on a swarm manager node.
```
docker service create \
--name gantry \
--mode replicated-job \
--constraint "node.role==manager" \
--mount type=bind,source=/var/run/docker.sock,target=/var/run/docker.sock \
shizunge/gantry
```
The [examples folder](examples/README.md) contains example docker compose files, and more methods to launch *Gantry*, like [at a specific time](examples/cronjob) and [via webhook](examples/webhook).
You can also run *Gantry* as a script directly on the host outside the container
```
./src/entrypoint.sh
```
*Gantry* is written to work with `busybox ash` (v1.35+) as well as `bash`.
## Configurations
You can configure the most behaviors of *Gantry* via environment variables.
### Common
| Environment Variable | Default |Description |
|-----------------------|---------|------------|
| GANTRY_LOG_FORMAT | `text` | Log format, plain text or structured. Valid values are `text`, `json`. |
| GANTRY_LOG_LEVEL | `INFO` | Control how many logs generated by *Gantry*. Valid values are `NONE`, `ERROR`, `WARN`, `INFO`, `DEBUG`. |
| GANTRY_NODE_NAME | | Add node name to logs. If not set, *Gantry* will use the host name of the Docker Swarm's manager, which is read from either the Docker daemon socket of current node or `DOCKER_HOST`. |
| GANTRY_POST_RUN_CMD | | Command(s) to `eval` after each updating iteration. For [example](examples/prune-and-watchtower), you can use this to remove unused containers, networks and images and update standalone docker containers. |
| GANTRY_PRE_RUN_CMD | | Command(s) to `eval` before each updating iteration. For [example](examples/prune-and-watchtower), you can use this to remove unused containers, networks and images and update standalone docker containers. If you changed *Gantry* configurations in the pre-run command(s), the new value would apply to the following updating. If the last pre-run command failed, *Gantry* would skip updating services. |
| GANTRY_SLEEP_SECONDS | 0 | Interval between two updates. Set it to 0 to run *Gantry* once and then exit. When this is a non-zero value, after an updating, *Gantry* will sleep until the next scheduled update. The actual sleep time is this value minus time spent on updating services. |
| GANTRY_TRIGGER_PATH | | Path to watch for triggering the next update. Set this to an empty string to disable watching. This can be used with a [webhook](examples/webhook). In combination with `GANTRY_SLEEP_SECONDS`, updates will occur when either condition is met. |
| TZ | | Set timezone for time in logs. |
*Gantry* bases on Docker command line, [environment variables](https://docs.docker.com/engine/reference/commandline/cli/#environment-variables) for Docker command line also works for *Gantry*.
### To login to registries
| Environment Variable | Default | Description |
|-----------------------|---------|-------------|
| DOCKER_CONFIG | | The location of the [client configuration files](https://docs.docker.com/engine/reference/commandline/cli/#configuration-files) where authentication stores. It applys to all Docker commands, i.e. to all services. See [Authentication](docs/authentication.md). You can apply a different value to a particular service via [labels](#labels). |
| GANTRY_REGISTRY_CONFIG | | See [Authentication](docs/authentication.md). |
| GANTRY_REGISTRY_CONFIG_FILE | | See [Authentication](docs/authentication.md). |
| GANTRY_REGISTRY_CONFIGS_FILE | | See [Authentication](docs/authentication.md). |
| GANTRY_REGISTRY_HOST | | See [Authentication](docs/authentication.md). |
| GANTRY_REGISTRY_HOST_FILE | | See [Authentication](docs/authentication.md). |
| GANTRY_REGISTRY_PASSWORD | | See [Authentication](docs/authentication.md). |
| GANTRY_REGISTRY_PASSWORD_FILE | | See [Authentication](docs/authentication.md). |
| GANTRY_REGISTRY_USER | | See [Authentication](docs/authentication.md). |
| GANTRY_REGISTRY_USER_FILE | | See [Authentication](docs/authentication.md). |
### To select services
| Environment Variable | Default | Description |
|-----------------------|---------|-------------|
| GANTRY_SERVICES_EXCLUDED | | A space separated list of services names that are excluded from updating. |
| GANTRY_SERVICES_EXCLUDED_FILTERS | `label=gantry.services.excluded=true` | A space separated list of [filters](https://docs.docker.com/engine/reference/commandline/service_ls/#filter), e.g. `label=project=project-a`. Exclude services which match the given filters from updating. The default value allows you to add label `gantry.services.excluded=true` to services to exclude them from updating. Note that multiple filters will be logical **ANDED**. An empty string means no filters, as a result *Gantry* will not exclude any services. |
| GANTRY_SERVICES_FILTERS | | A space separated list of [filters](https://docs.docker.com/engine/reference/commandline/service_ls/#filter) that are accepted by `docker service ls --filter` to select services to update, e.g. `label=project=project-a`. Note that multiple filters will be logical **ANDED**. An empty string means no filters, as a result *Gantry* will update all services. Also see [How to filters multiple services by name](docs/faq.md#how-to-filters-multiple-services-by-name). |
> NOTE: *Gantry* reads labels on the services not on the containers. The labels need to go to the [deploy](https://docs.docker.com/reference/compose-file/deploy/#labels) section, if you are using docker compose files to setup your services.
### To check if new images are available
| Environment Variable | Default | Description |
|-----------------------|---------|-------------|
| GANTRY_MANIFEST_CMD | buildx | Valid values are `buildx`, `manifest`, and `none`.
Set which command for manifest inspection.