Disabling color through environment variables (#598)

* This patch adds support for disabling color through environment variables.
- NO_COLOR: https://no-color.org/
- CLICOLOR,CLICOLOR_FORCE: https://bixense.com/clicolors/ ( [logrus built-in](6699a89a23/text_formatter.go (L46)) )

* use viper/cobra and add documentation. (https://github.com/containrrr/watchtower/pull/598#pullrequestreview-463814669)

Co-authored-by: Simon Aronsson <simme@arcticbit.se>
pull/626/head^2
bugficks 4 years ago committed by GitHub
parent 9bd3913a11
commit 158b6935d4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -63,6 +63,17 @@ func Execute() {
func PreRun(cmd *cobra.Command, args []string) { func PreRun(cmd *cobra.Command, args []string) {
f := cmd.PersistentFlags() f := cmd.PersistentFlags()
if enabled, _ := f.GetBool("no-color"); enabled {
log.SetFormatter(&log.TextFormatter{
DisableColors: true,
})
} else {
// enable logrus built-in support for https://bixense.com/clicolors/
log.SetFormatter(&log.TextFormatter{
EnvironmentOverrideColors: true,
})
}
if enabled, _ := f.GetBool("debug"); enabled { if enabled, _ := f.GetBool("debug"); enabled {
log.SetLevel(log.DebugLevel) log.SetLevel(log.DebugLevel)
} }

@ -88,6 +88,16 @@ Environment Variable: WATCHTOWER_TRACE
Default: false Default: false
``` ```
## ANSI colors
Disable ANSI color escape codes in log output.
```
Argument: --no-color
Environment Variable: NO_COLOR
Type: Boolean
Default: false
```
## Docker host ## Docker host
Docker daemon socket to connect to. Can be pointed at a remote Docker host by specifying a TCP endpoint as "tcp://hostname:port". Docker daemon socket to connect to. Can be pointed at a remote Docker host by specifying a TCP endpoint as "tcp://hostname:port".
@ -116,7 +126,7 @@ Will also include created and exited containers.
Environment Variable: WATCHTOWER_INCLUDE_STOPPED Environment Variable: WATCHTOWER_INCLUDE_STOPPED
Type: Boolean Type: Boolean
Default: false Default: false
``` ```
## Revive stopped ## Revive stopped
Start any stopped containers that have had their image updated. This argument is only usable with the `--include-stopped` argument. Start any stopped containers that have had their image updated. This argument is only usable with the `--include-stopped` argument.
@ -126,7 +136,7 @@ Start any stopped containers that have had their image updated. This argument is
Environment Variable: WATCHTOWER_REVIVE_STOPPED Environment Variable: WATCHTOWER_REVIVE_STOPPED
Type: Boolean Type: Boolean
Default: false Default: false
``` ```
## Poll interval ## Poll interval
Poll interval (in seconds). This value controls how frequently watchtower will poll for new images. Either `--schedule` or a poll interval can be defined, but not both. Poll interval (in seconds). This value controls how frequently watchtower will poll for new images. Either `--schedule` or a poll interval can be defined, but not both.
@ -136,7 +146,7 @@ Poll interval (in seconds). This value controls how frequently watchtower will p
Environment Variable: WATCHTOWER_POLL_INTERVAL Environment Variable: WATCHTOWER_POLL_INTERVAL
Type: Integer Type: Integer
Default: 300 Default: 300
``` ```
## Filter by enable label ## Filter by enable label
Update containers that have a `com.centurylinklabs.watchtower.enable` label set to true. Update containers that have a `com.centurylinklabs.watchtower.enable` label set to true.
@ -146,13 +156,13 @@ Update containers that have a `com.centurylinklabs.watchtower.enable` label set
Environment Variable: WATCHTOWER_LABEL_ENABLE Environment Variable: WATCHTOWER_LABEL_ENABLE
Type: Boolean Type: Boolean
Default: false Default: false
``` ```
## Filter by disable label ## Filter by disable label
**Do not** update containers that have `com.centurylinklabs.watchtower.enable` label set to false and no `--label-enable` argument is passed. Note that only one or the other (targeting by enable label) can be used at the same time to target containers. **Do not** update containers that have `com.centurylinklabs.watchtower.enable` label set to false and no `--label-enable` argument is passed. Note that only one or the other (targeting by enable label) can be used at the same time to target containers.
## Without updating containers ## Without updating containers
Will only monitor for new images, not update the containers. Will only monitor for new images, not update the containers.
> ### ⚠️ Please note > ### ⚠️ Please note
> >
@ -163,7 +173,7 @@ Will only monitor for new images, not update the containers.
Environment Variable: WATCHTOWER_MONITOR_ONLY Environment Variable: WATCHTOWER_MONITOR_ONLY
Type: Boolean Type: Boolean
Default: false Default: false
``` ```
## Without restarting containers ## Without restarting containers
Do not restart containers after updating. This option can be useful when the start of the containers Do not restart containers after updating. This option can be useful when the start of the containers
@ -186,10 +196,10 @@ them to a registry.
Environment Variable: WATCHTOWER_NO_PULL Environment Variable: WATCHTOWER_NO_PULL
Type: Boolean Type: Boolean
Default: false Default: false
``` ```
## Without sending a startup message ## Without sending a startup message
Do not send a message after watchtower started. Otherwise there will be an info-level notification. Do not send a message after watchtower started. Otherwise there will be an info-level notification.
``` ```
Argument: --no-startup-message Argument: --no-startup-message
@ -216,7 +226,7 @@ Runs Watchtower in HTTP API mode, only allowing image updates to be triggered by
Environment Variable: WATCHTOWER_HTTP_API Environment Variable: WATCHTOWER_HTTP_API
Type: Boolean Type: Boolean
Default: false Default: false
``` ```
## HTTP API Token ## HTTP API Token
Sets an authentication token to HTTP API requests. Sets an authentication token to HTTP API requests.
@ -226,7 +236,7 @@ Sets an authentication token to HTTP API requests.
Environment Variable: WATCHTOWER_HTTP_API_TOKEN Environment Variable: WATCHTOWER_HTTP_API_TOKEN
Type: String Type: String
Default: - Default: -
``` ```
## Filter by scope ## Filter by scope
Update containers that have a `com.centurylinklabs.watchtower.scope` label set with the same value as the given argument. This enables [running multiple instances](https://containrrr.github.io/watchtower/running-multiple-instances). Update containers that have a `com.centurylinklabs.watchtower.scope` label set with the same value as the given argument. This enables [running multiple instances](https://containrrr.github.io/watchtower/running-multiple-instances).
@ -239,7 +249,7 @@ Environment Variable: WATCHTOWER_SCOPE
``` ```
## Scheduling ## Scheduling
[Cron expression](https://pkg.go.dev/github.com/robfig/cron@v1.2.0?tab=doc#hdr-CRON_Expression_Format) in 6 fields (rather than the traditional 5) which defines when and how often to check for new images. Either `--interval` or the schedule expression [Cron expression](https://pkg.go.dev/github.com/robfig/cron@v1.2.0?tab=doc#hdr-CRON_Expression_Format) in 6 fields (rather than the traditional 5) which defines when and how often to check for new images. Either `--interval` or the schedule expression
can be defined, but not both. An example: `--schedule "0 0 4 * * *"` can be defined, but not both. An example: `--schedule "0 0 4 * * *"`
``` ```
@ -268,7 +278,7 @@ Timeout before the container is forcefully stopped. When set, this option will c
Environment Variable: WATCHTOWER_TIMEOUT Environment Variable: WATCHTOWER_TIMEOUT
Type: Duration Type: Duration
Default: 10s Default: 10s
``` ```
## TLS Verification ## TLS Verification
Use TLS when connecting to the Docker socket and verify the server's certificate. See below for options used to configure notifications. Use TLS when connecting to the Docker socket and verify the server's certificate. See below for options used to configure notifications.

@ -140,7 +140,12 @@ func RegisterSystemFlags(rootCmd *cobra.Command) {
"", "",
viper.GetString("WATCHTOWER_HTTP_API_TOKEN"), viper.GetString("WATCHTOWER_HTTP_API_TOKEN"),
"Sets an authentication token to HTTP API requests.") "Sets an authentication token to HTTP API requests.")
// https://no-color.org/
flags.BoolP(
"no-color",
"",
viper.IsSet("NO_COLOR"),
"Disable ANSI color escape codes in log output")
flags.StringP( flags.StringP(
"scope", "scope",
"", "",

Loading…
Cancel
Save