-
Notifications
You must be signed in to change notification settings - Fork 613
feat: filter containers seen by docker-gen #623
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
buchdag
wants to merge
3
commits into
main
Choose a base branch
from
filter-containers
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -87,62 +87,70 @@ Usage: docker-gen [options] template [dest] | |||||
Generate files from docker container meta-data | ||||||
|
||||||
Options: | ||||||
-config value | ||||||
config files with template directives. Config files will be merged if this option is specified multiple times. (default []) | ||||||
-config path | ||||||
config files with template directives. | ||||||
Config files will be merged if this option is specified multiple times. (default []) | ||||||
-container-filter key=value | ||||||
container filter for inclusion by docker-gen. | ||||||
You can pass this option multiple times to combine filters with AND. | ||||||
https://docs.docker.com/engine/reference/commandline/ps/#filter | ||||||
-endpoint string | ||||||
docker api endpoint (tcp|unix://..). Default unix:///var/run/docker.sock | ||||||
-include-stopped | ||||||
include stopped containers. | ||||||
Bypassed by when providing a container status filter (-container-filter status=foo). | ||||||
-interval int | ||||||
notify command interval (secs) | ||||||
-keep-blank-lines | ||||||
keep blank lines in the output file | ||||||
-notify restart xyz | ||||||
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 | ||||||
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 pass this option multiple times to combine filters with AND. | ||||||
https://docs.docker.com/engine/reference/commandline/ps/#filter | ||||||
-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-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/main/signal.go | ||||||
-only-exposed | ||||||
only include containers with exposed ports | ||||||
only include containers with exposed ports. | ||||||
Bypassed by when using the exposed filter with (-container-filter exposed=foo). | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
-only-published | ||||||
only include containers with published ports (implies -only-exposed) | ||||||
-include-stopped | ||||||
include stopped containers | ||||||
only include containers with published ports (implies -only-exposed). | ||||||
Bypassed by when providing a container published filter (-container-filter published=foo). | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
-tlscacert string | ||||||
path to TLS CA certificate file (default "~/.docker/machine/machines/default/ca.pem") | ||||||
path to TLS CA certificate file (default "~/.docker/ca.pem") | ||||||
-tlscert string | ||||||
path to TLS client certificate file (default "~/.docker/machine/machines/default/cert.pem") | ||||||
path to TLS client certificate file (default "~/.docker/cert.pem") | ||||||
-tlskey string | ||||||
path to TLS client key file (default "~/.docker/machine/machines/default/key.pem") | ||||||
path to TLS client key file (default "~/.docker/key.pem") | ||||||
-tlsverify | ||||||
verify docker daemon's TLS certicate (default true) | ||||||
verify docker daemon's TLS certicate | ||||||
-version | ||||||
show version | ||||||
-wait string | ||||||
minimum and maximum durations to wait (e.g. "500ms:2s") before triggering generate | ||||||
-watch | ||||||
watch for container changes | ||||||
-wait | ||||||
minimum (and/or maximum) duration to wait after each container change before triggering | ||||||
|
||||||
Arguments: | ||||||
template - path to a template to generate | ||||||
dest - path to write the template. If not specfied, STDOUT is used | ||||||
dest - path to write the template to. If not specfied, STDOUT is used | ||||||
|
||||||
Environment Variables: | ||||||
DOCKER_HOST - default value for -endpoint | ||||||
DOCKER_CERT_PATH - directory path containing key.pem, cert.pm and ca.pem | ||||||
DOCKER_TLS_VERIFY - enable client TLS verification] | ||||||
DOCKER_CERT_PATH - directory path containing key.pem, cert.pem and ca.pem | ||||||
DOCKER_TLS_VERIFY - enable client TLS verification | ||||||
``` | ||||||
|
||||||
If no `<dest>` file is specified, the output is sent to stdout. Mainly useful for debugging. | ||||||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -34,6 +34,7 @@ var ( | |||||
onlyExposed bool | ||||||
onlyPublished bool | ||||||
includeStopped bool | ||||||
containerFilter mapstringslice = make(mapstringslice) | ||||||
configFiles stringslice | ||||||
configs config.ConfigFile | ||||||
interval int | ||||||
|
@@ -77,7 +78,7 @@ Options:`) | |||||
println(` | ||||||
Arguments: | ||||||
template - path to a template to generate | ||||||
dest - path to a write the template. If not specfied, STDOUT is used`) | ||||||
dest - path to write the template to. If not specfied, STDOUT is used`) | ||||||
|
||||||
println(` | ||||||
Environment Variables: | ||||||
|
@@ -97,21 +98,35 @@ func loadConfig(file string) error { | |||||
} | ||||||
|
||||||
func initFlags() { | ||||||
|
||||||
certPath := filepath.Join(os.Getenv("DOCKER_CERT_PATH")) | ||||||
if certPath == "" { | ||||||
certPath = filepath.Join(os.Getenv("HOME"), ".docker") | ||||||
} | ||||||
|
||||||
flag.BoolVar(&version, "version", false, "show version") | ||||||
|
||||||
// General configuration options | ||||||
flag.BoolVar(&watch, "watch", false, "watch for container changes") | ||||||
flag.StringVar(&wait, "wait", "", "minimum and maximum durations to wait (e.g. \"500ms:2s\") before triggering generate") | ||||||
flag.BoolVar(&onlyExposed, "only-exposed", false, "only include containers with exposed ports") | ||||||
flag.Var(&configFiles, "config", "config files with template directives. Config files will be merged if this option is specified multiple times.") | ||||||
flag.BoolVar(&keepBlankLines, "keep-blank-lines", false, "keep blank lines in the output file") | ||||||
|
||||||
// Containers filtering options | ||||||
flag.BoolVar(&onlyExposed, "only-exposed", false, | ||||||
"only include containers with exposed ports. Bypassed when providing a container exposed filter (-container-filter exposed=foo).") | ||||||
flag.BoolVar(&onlyPublished, "only-published", false, | ||||||
"only include containers with published ports (implies -only-exposed)") | ||||||
flag.BoolVar(&includeStopped, "include-stopped", false, "include stopped containers") | ||||||
flag.BoolVar(¬ifyOutput, "notify-output", false, "log the output(stdout/stderr) of notify command") | ||||||
"only include containers with published ports (implies -only-exposed). Bypassed when providing a container published filter (-container-filter published=foo).") | ||||||
flag.BoolVar(&includeStopped, "include-stopped", false, | ||||||
"include stopped containers. Bypassed by when providing a container status filter (-container-filter status=foo).") | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
flag.Var(&containerFilter, "container-filter", | ||||||
"container filter for inclusion by docker-gen. You can pass this option multiple times to combine filters with AND. https://docs.docker.com/engine/reference/commandline/ps/#filter") | ||||||
|
||||||
// Command notification options | ||||||
flag.StringVar(¬ifyCmd, "notify", "", "run command after template is regenerated (e.g `restart xyz`)") | ||||||
flag.BoolVar(¬ifyOutput, "notify-output", false, "log the output(stdout/stderr) of notify command") | ||||||
flag.IntVar(&interval, "interval", 0, "notify command interval (secs)") | ||||||
|
||||||
// Containers notification options | ||||||
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", | ||||||
|
@@ -120,9 +135,8 @@ func initFlags() { | |||||
"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.") | ||||||
flag.IntVar(&interval, "interval", 0, "notify command interval (secs)") | ||||||
flag.BoolVar(&keepBlankLines, "keep-blank-lines", false, "keep blank lines in the output file") | ||||||
|
||||||
// Docker API endpoint configuration options | ||||||
flag.StringVar(&endpoint, "endpoint", "", "docker api endpoint (tcp|unix://..). Default unix:///var/run/docker.sock") | ||||||
flag.StringVar(&tlsCert, "tlscert", filepath.Join(certPath, "cert.pem"), "path to TLS client certificate file") | ||||||
flag.StringVar(&tlsKey, "tlskey", filepath.Join(certPath, "key.pem"), "path to TLS client key file") | ||||||
|
@@ -173,9 +187,7 @@ func main() { | |||||
NotifyCmd: notifyCmd, | ||||||
NotifyOutput: notifyOutput, | ||||||
NotifyContainers: make(map[string]int), | ||||||
OnlyExposed: onlyExposed, | ||||||
OnlyPublished: onlyPublished, | ||||||
IncludeStopped: includeStopped, | ||||||
ContainerFilter: containerFilter, | ||||||
Interval: interval, | ||||||
KeepBlankLines: keepBlankLines, | ||||||
} | ||||||
|
@@ -189,25 +201,37 @@ func main() { | |||||
cfg.NotifyContainersFilter = notifyContainerFilter | ||||||
cfg.NotifyContainersSignal = notifyContainerSignal | ||||||
} | ||||||
if len(cfg.ContainerFilter["status"]) == 0 { | ||||||
if includeStopped { | ||||||
cfg.ContainerFilter["status"] = []string{ | ||||||
"created", | ||||||
"restarting", | ||||||
"running", | ||||||
"removing", | ||||||
"paused", | ||||||
"exited", | ||||||
"dead", | ||||||
} | ||||||
} else { | ||||||
cfg.ContainerFilter["status"] = []string{"running"} | ||||||
} | ||||||
} | ||||||
if onlyPublished && len(cfg.ContainerFilter["publish"]) == 0 { | ||||||
cfg.ContainerFilter["publish"] = []string{"1-65535"} | ||||||
} else if onlyExposed && len(cfg.ContainerFilter["publish"]) == 0 { | ||||||
cfg.ContainerFilter["expose"] = []string{"1-65535"} | ||||||
} | ||||||
configs = config.ConfigFile{ | ||||||
Config: []config.Config{cfg}, | ||||||
} | ||||||
} | ||||||
|
||||||
all := false | ||||||
for _, config := range configs.Config { | ||||||
if config.IncludeStopped { | ||||||
all = true | ||||||
} | ||||||
} | ||||||
|
||||||
generator, err := generator.NewGenerator(generator.GeneratorConfig{ | ||||||
Endpoint: endpoint, | ||||||
TLSKey: tlsKey, | ||||||
TLSCert: tlsCert, | ||||||
TLSCACert: tlsCaCert, | ||||||
TLSVerify: tlsVerify, | ||||||
All: all, | ||||||
ConfigFile: configs, | ||||||
}) | ||||||
|
||||||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.