From 3f593b75dc9f0e1ea09003414a17576ed07f47b0 Mon Sep 17 00:00:00 2001 From: "Dowideit, Sven (O&A, St. Lucia)" Date: Mon, 8 Jul 2019 16:11:32 +1000 Subject: [PATCH] Docker Swarm stack support Signed-off-by: Dowideit, Sven (O&A, St. Lucia) --- pkg/commands/docker.go | 19 +++++++++---------- pkg/config/app_config.go | 6 ++++++ 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/pkg/commands/docker.go b/pkg/commands/docker.go index 53b7d13a..7961977e 100644 --- a/pkg/commands/docker.go +++ b/pkg/commands/docker.go @@ -4,7 +4,6 @@ import ( "bufio" "context" "encoding/json" - "fmt" "os/exec" "sort" "strings" @@ -91,14 +90,9 @@ func NewDockerCommand(log *logrus.Entry, osCommand *OSCommand, tr *i18n.Translat log.Warn(command) - err = osCommand.RunCommand( - utils.ApplyTemplate( - config.UserConfig.CommandTemplates.CheckDockerComposeConfig, - dockerCommand.NewCommandObject(CommandObject{}), - ), - ) + err = osCommand.RunCommand(command) if err != nil { - dockerCommand.InDockerComposeProject = false + //dockerCommand.InDockerComposeProject = false log.Warn(err.Error()) } @@ -251,6 +245,11 @@ L: service.Container = container continue L } + if container.Container.Labels["com.docker.swarm.service.name"] == service.Name { + //Swarm service + service.Container = container + continue L + } } service.Container = nil } @@ -348,8 +347,8 @@ func (c *DockerCommand) GetServices() ([]*Service, error) { return nil, nil } - composeCommand := c.Config.UserConfig.CommandTemplates.DockerCompose - output, err := c.OSCommand.RunCommandWithOutput(fmt.Sprintf("%s config --hash=*", composeCommand)) + composeConfigHash := c.Config.UserConfig.CommandTemplates.DockerComposeConfigHash + output, err := c.OSCommand.RunCommandWithOutput(composeConfigHash) if err != nil { return nil, err } diff --git a/pkg/config/app_config.go b/pkg/config/app_config.go index 3e62e4e9..afa91f1e 100644 --- a/pkg/config/app_config.go +++ b/pkg/config/app_config.go @@ -175,6 +175,11 @@ type CommandTemplatesConfig struct { // file(s) DockerComposeConfig string `yaml:"dockerComposeConfig,omitempty"` + // Print the service config hash, one per line. + // Set "service1,service2" for a list of specified services + // or use the wildcard symbol to display all services + DockerComposeConfigHash string `yaml:"dockerComposeConfigHash,omitempty"` + // CheckDockerComposeConfig is what we use to check whether we are in a // docker-compose context. If the command returns an error then we clearly // aren't in a docker-compose config and we then just hide the services panel @@ -335,6 +340,7 @@ func GetDefaultConfig() UserConfig { AllLogs: "{{ .DockerCompose }} logs --tail=300 --follow", ViewAllLogs: "{{ .DockerCompose }} logs", DockerComposeConfig: "{{ .DockerCompose }} config", + DockerComposeConfigHash: "{{ .DockerCompose }} config --hash=*", CheckDockerComposeConfig: "{{ .DockerCompose }} config --quiet", ContainerLogs: "docker logs --timestamps --follow --since=60m {{ .Container.ID }}", ViewContainerLogs: "docker logs --timestamps --follow --since=60m {{ .Container.ID }}",