mirror of
https://github.com/containrrr/watchtower.git
synced 2026-02-12 02:14:21 +01:00
Add docker api version parameter
This commit is contained in:
parent
5a6b63a5c7
commit
b4b2e51aa0
3 changed files with 24 additions and 8 deletions
|
|
@ -18,10 +18,6 @@ import (
|
|||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
// DockerAPIMinVersion is the minimum version of the docker api required to
|
||||
// use watchtower
|
||||
const DockerAPIMinVersion string = "1.24"
|
||||
|
||||
var (
|
||||
client container.Client
|
||||
scheduleSpec string
|
||||
|
|
@ -90,7 +86,7 @@ func PreRun(cmd *cobra.Command, args []string) {
|
|||
lifecycleHooks, _ = f.GetBool("enable-lifecycle-hooks")
|
||||
|
||||
// configure environment vars for client
|
||||
err := flags.EnvConfig(cmd, DockerAPIMinVersion)
|
||||
err := flags.EnvConfig(cmd)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -75,7 +75,17 @@ Docker daemon socket to connect to. Can be pointed at a remote Docker host by sp
|
|||
Environment Variable: DOCKER_HOST
|
||||
Type: String
|
||||
Default: "unix:///var/run/docker.sock"
|
||||
```
|
||||
```
|
||||
|
||||
## Docker API version
|
||||
The API version to use by the Docker client for connecting to the Docker daemon.
|
||||
|
||||
```
|
||||
Argument: --api-version, -a
|
||||
Environment Variable: DOCKER_API_VERSION
|
||||
Type: String
|
||||
Default: "1.24"
|
||||
```
|
||||
|
||||
## Include stopped
|
||||
Will also include created and exited containers.
|
||||
|
|
|
|||
|
|
@ -9,11 +9,16 @@ import (
|
|||
"github.com/spf13/viper"
|
||||
)
|
||||
|
||||
// DockerAPIMinVersion is the minimum version of the docker api required to
|
||||
// use watchtower
|
||||
const DockerAPIMinVersion string = "1.24"
|
||||
|
||||
// RegisterDockerFlags that are used directly by the docker api client
|
||||
func RegisterDockerFlags(rootCmd *cobra.Command) {
|
||||
flags := rootCmd.PersistentFlags()
|
||||
flags.StringP("host", "H", viper.GetString("DOCKER_HOST"), "daemon socket to connect to")
|
||||
flags.BoolP("tlsverify", "v", viper.GetBool("DOCKER_TLS_VERIFY"), "use TLS and verify the remote")
|
||||
flags.StringP("api-version", "a", viper.GetString("DOCKER_API_VERSION"), "api version to use by docker client")
|
||||
}
|
||||
|
||||
// RegisterSystemFlags that are used by watchtower to modify the program flow
|
||||
|
|
@ -215,6 +220,7 @@ Should only be used for testing.
|
|||
func SetDefaults() {
|
||||
viper.AutomaticEnv()
|
||||
viper.SetDefault("DOCKER_HOST", "unix:///var/run/docker.sock")
|
||||
viper.SetDefault("DOCKER_API_VERSION", DockerAPIMinVersion)
|
||||
viper.SetDefault("WATCHTOWER_POLL_INTERVAL", 300)
|
||||
viper.SetDefault("WATCHTOWER_TIMEOUT", time.Second*10)
|
||||
viper.SetDefault("WATCHTOWER_NOTIFICATIONS", []string{})
|
||||
|
|
@ -225,10 +231,11 @@ func SetDefaults() {
|
|||
|
||||
// EnvConfig translates the command-line options into environment variables
|
||||
// that will initialize the api client
|
||||
func EnvConfig(cmd *cobra.Command, dockerAPIMinVersion string) error {
|
||||
func EnvConfig(cmd *cobra.Command) error {
|
||||
var err error
|
||||
var host string
|
||||
var tls bool
|
||||
var version string
|
||||
|
||||
flags := cmd.PersistentFlags()
|
||||
|
||||
|
|
@ -238,13 +245,16 @@ func EnvConfig(cmd *cobra.Command, dockerAPIMinVersion string) error {
|
|||
if tls, err = flags.GetBool("tlsverify"); err != nil {
|
||||
return err
|
||||
}
|
||||
if version, err = flags.GetString("api-version"); err != nil {
|
||||
return err
|
||||
}
|
||||
if err = setEnvOptStr("DOCKER_HOST", host); err != nil {
|
||||
return err
|
||||
}
|
||||
if err = setEnvOptBool("DOCKER_TLS_VERIFY", tls); err != nil {
|
||||
return err
|
||||
}
|
||||
if err = setEnvOptStr("DOCKER_API_VERSION", dockerAPIMinVersion); err != nil {
|
||||
if err = setEnvOptStr("DOCKER_API_VERSION", version); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue