mirror of
https://github.com/containrrr/watchtower.git
synced 2025-09-22 05:40:50 +02:00
Feat/lifecycle hooks (#351)
* feat(update): add lifecycle hooks to the update action * fix(ci): add bash tests for lifecycle-hooks to the ci workflow * fix(ci): move integration tests to an isolated step * fix(ci): fix malformed all-contributors json * fix(ci): disable automatic bash test until we figure out a reasonable way to run it in circleci
This commit is contained in:
parent
874180a518
commit
bfae38dbf8
12 changed files with 499 additions and 73 deletions
45
docs/lifecycle-hooks.md
Normal file
45
docs/lifecycle-hooks.md
Normal file
|
@ -0,0 +1,45 @@
|
|||
|
||||
## Executing commands before and after updating
|
||||
|
||||
> **DO NOTE**: Both commands are shell commands executed with `sh`, and therefore require the
|
||||
> container to provide the `sh` executable.
|
||||
|
||||
It is possible to execute a *pre-update* command and a *post-update* command
|
||||
**inside** every container updated by watchtower. The *pre-update* command is
|
||||
executed before stopping the container, and the *post-update* command is
|
||||
executed after restarting the container.
|
||||
|
||||
This feature is disabled by default. To enable it, you need to set the option
|
||||
`--enable-lifecycle-hooks` on the command line, or set the environment variable
|
||||
`WATCHTOWER_LIFECYCLE_HOOKS` to true.
|
||||
|
||||
|
||||
|
||||
### Specifying update commands
|
||||
|
||||
The commands are specified using docker container labels, with
|
||||
`com.centurylinklabs.watchtower.pre-update-command` for the *pre-update*
|
||||
command and `com.centurylinklabs.watchtower.lifecycle.post-update` for the
|
||||
*post-update* command.
|
||||
|
||||
These labels can be declared as instructions in a Dockerfile:
|
||||
|
||||
```docker
|
||||
LABEL com.centurylinklabs.watchtower.lifecycle.pre-update="/dump-data.sh"
|
||||
LABEL com.centurylinklabs.watchtower.lifecycle.post-update="/restore-data.sh"
|
||||
```
|
||||
|
||||
Or be specified as part of the `docker run` command line:
|
||||
|
||||
```bash
|
||||
docker run -d \
|
||||
--label=com.centurylinklabs.watchtower.lifecycle.pre-update="/dump-data.sh" \
|
||||
--label=com.centurylinklabs.watchtower.lifecycle.post-update="/restore-data.sh" \
|
||||
someimage
|
||||
```
|
||||
|
||||
### Execution failure
|
||||
|
||||
The failure of a command to execute, identified by an exit code different than
|
||||
0, will not prevent watchtower from updating the container. Only an error
|
||||
log statement containing the exit code will be reported.
|
Loading…
Add table
Add a link
Reference in a new issue