From e8d050c6dc6aa405a442377bdff4e4b61fd375e6 Mon Sep 17 00:00:00 2001 From: Nicolas Duchon Date: Fri, 17 May 2024 16:59:48 +0200 Subject: [PATCH 1/3] feat: allow multiple -notify-sighup / -notify-container --- README.md | 9 ++++++--- cmd/docker-gen/main.go | 20 ++++++++++---------- 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 1593bb03..8527efff 100644 --- a/README.md +++ b/README.md @@ -99,8 +99,13 @@ Options: run command after template is regenerated (e.g restart xyz) -notify-output log the output(stdout/stderr) of notify command + -notify-sighup container-ID + send HUP signal to container. + Equivalent to 'docker kill -s HUP container-ID', or `-notify-container container-ID -notify-signal 1`. + You can pass this option multiple times to send HUP to multiple containers. -notify-container container-ID - container to send a signal to + send -notify-signal signal (defaults to 1 / HUP) to container. + You can pass this option multiple times to notify multiple containers. -notify-filter key=value container filter for notification (e.g -notify-filter name=foo). You can have multiple of these. @@ -109,8 +114,6 @@ Options: signal to send to the -notify-container and -notify-filter. -1 to call docker restart. Defaults to 1 aka. HUP. All available signals available on the dockerclient https://github.com/fsouza/go-dockerclient/blob/01804dec8a84d0a77e63611f2b62d33e9bb2b64a/signal.go - -notify-sighup container-ID - send HUP signal to container. Equivalent to 'docker kill -s HUP container-ID', or `-notify-container container-ID -notify-signal 1` -only-exposed only include containers with exposed ports -only-published diff --git a/cmd/docker-gen/main.go b/cmd/docker-gen/main.go index 790777bf..89864fda 100644 --- a/cmd/docker-gen/main.go +++ b/cmd/docker-gen/main.go @@ -26,8 +26,8 @@ var ( wait string notifyCmd string notifyOutput bool - sighupContainerID string - notifyContainerID string + sighupContainerID stringslice + notifyContainerID stringslice notifyContainerSignal int notifyContainerFilter mapstringslice = make(mapstringslice) onlyExposed bool @@ -112,10 +112,10 @@ func initFlags() { flag.BoolVar(&includeStopped, "include-stopped", false, "include stopped containers") flag.BoolVar(¬ifyOutput, "notify-output", false, "log the output(stdout/stderr) of notify command") flag.StringVar(¬ifyCmd, "notify", "", "run command after template is regenerated (e.g `restart xyz`)") - flag.StringVar(&sighupContainerID, "notify-sighup", "", - "send HUP signal to container. Equivalent to docker kill -s HUP `container-ID`") - flag.StringVar(¬ifyContainerID, "notify-container", "", - "container to send a signal to") + flag.Var(&sighupContainerID, "notify-sighup", + "send HUP signal to container. Equivalent to docker kill -s HUP `container-ID`. You can pass this option multiple times to send HUP to multiple containers.") + flag.Var(¬ifyContainerID, "notify-container", + "send -notify-signal signal (defaults to 1 / HUP) to container. You can pass this option multiple times to notify multiple containers.") flag.Var(¬ifyContainerFilter, "notify-filter", "container filter for notification (e.g -notify-filter name=foo). You can have multiple of these. https://docs.docker.com/engine/reference/commandline/ps/#filter") flag.IntVar(¬ifyContainerSignal, "notify-signal", int(docker.SIGHUP), @@ -176,11 +176,11 @@ func main() { Interval: interval, KeepBlankLines: keepBlankLines, } - if sighupContainerID != "" { - cfg.NotifyContainers[sighupContainerID] = int(syscall.SIGHUP) + for _, id := range sighupContainerID { + cfg.NotifyContainers[id] = int(syscall.SIGHUP) } - if notifyContainerID != "" { - cfg.NotifyContainers[notifyContainerID] = notifyContainerSignal + for _, id := range notifyContainerID { + cfg.NotifyContainers[id] = notifyContainerSignal } if len(notifyContainerFilter) > 0 { cfg.NotifyContainersFilter = notifyContainerFilter From d80d7a96688a105ee0e41259f333445c8b62ad09 Mon Sep 17 00:00:00 2001 From: Nicolas Duchon Date: Fri, 17 May 2024 17:05:02 +0200 Subject: [PATCH 2/3] fix: remove duplicate config file paths --- cmd/docker-gen/main.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/cmd/docker-gen/main.go b/cmd/docker-gen/main.go index 89864fda..6eb792d2 100644 --- a/cmd/docker-gen/main.go +++ b/cmd/docker-gen/main.go @@ -7,6 +7,7 @@ import ( "os" "os/signal" "path/filepath" + "slices" "strings" "syscall" @@ -49,7 +50,6 @@ func (strings *stringslice) String() string { } func (strings *stringslice) Set(value string) error { - // TODO: Throw an error for duplicate `dest` *strings = append(*strings, value) return nil } @@ -150,6 +150,9 @@ func main() { os.Exit(1) } + slices.Sort(configFiles) + configFiles = slices.Compact(configFiles) + if len(configFiles) > 0 { for _, configFile := range configFiles { err := loadConfig(configFile) @@ -187,7 +190,8 @@ func main() { cfg.NotifyContainersSignal = notifyContainerSignal } configs = config.ConfigFile{ - Config: []config.Config{cfg}} + Config: []config.Config{cfg}, + } } all := false From ae220be2b291bef0e88aa07d59a526c1652122b7 Mon Sep 17 00:00:00 2001 From: Nicolas Duchon Date: Fri, 17 May 2024 17:05:26 +0200 Subject: [PATCH 3/3] docs: small changes --- README.md | 10 +++++----- cmd/docker-gen/main.go | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 8527efff..db72a6c6 100644 --- a/README.md +++ b/README.md @@ -108,12 +108,12 @@ Options: You can pass this option multiple times to notify multiple containers. -notify-filter key=value container filter for notification (e.g -notify-filter name=foo). - You can have multiple of these. + You can pass this option multiple times to combine filters with AND. https://docs.docker.com/engine/reference/commandline/ps/#filter -notify-signal signal signal to send to the -notify-container and -notify-filter. -1 to call docker restart. Defaults to 1 aka. HUP. All available signals available on the dockerclient - https://github.com/fsouza/go-dockerclient/blob/01804dec8a84d0a77e63611f2b62d33e9bb2b64a/signal.go + https://github.com/fsouza/go-dockerclient/blob/main/signal.go -only-exposed only include containers with exposed ports -only-published @@ -121,11 +121,11 @@ Options: -include-stopped include stopped containers -tlscacert string - path to TLS CA certificate file (default "/Users/jason/.docker/machine/machines/default/ca.pem") + path to TLS CA certificate file (default "~/.docker/machine/machines/default/ca.pem") -tlscert string - path to TLS client certificate file (default "/Users/jason/.docker/machine/machines/default/cert.pem") + path to TLS client certificate file (default "~/.docker/machine/machines/default/cert.pem") -tlskey string - path to TLS client key file (default "/Users/jason/.docker/machine/machines/default/key.pem") + path to TLS client key file (default "~/.docker/machine/machines/default/key.pem") -tlsverify verify docker daemon's TLS certicate (default true) -version diff --git a/cmd/docker-gen/main.go b/cmd/docker-gen/main.go index 6eb792d2..8ee86364 100644 --- a/cmd/docker-gen/main.go +++ b/cmd/docker-gen/main.go @@ -117,7 +117,7 @@ func initFlags() { flag.Var(¬ifyContainerID, "notify-container", "send -notify-signal signal (defaults to 1 / HUP) to container. You can pass this option multiple times to notify multiple containers.") flag.Var(¬ifyContainerFilter, "notify-filter", - "container filter for notification (e.g -notify-filter name=foo). You can have multiple of these. https://docs.docker.com/engine/reference/commandline/ps/#filter") + "container filter for notification (e.g -notify-filter name=foo). You can pass this option multiple times to combine filters with AND. https://docs.docker.com/engine/reference/commandline/ps/#filter") flag.IntVar(¬ifyContainerSignal, "notify-signal", int(docker.SIGHUP), "signal to send to the notify-container and notify-filter. Defaults to SIGHUP") flag.Var(&configFiles, "config", "config files with template directives. Config files will be merged if this option is specified multiple times.")