From 2f28baa52d49e60199b61fe4955e5c814aeab670 Mon Sep 17 00:00:00 2001 From: "Dowideit, Sven (O&A, St. Lucia)" Date: Mon, 8 Jul 2019 16:29:07 +1000 Subject: [PATCH] really bad way to allow multiple containers per service Signed-off-by: Dowideit, Sven (O&A, St. Lucia) --- pkg/commands/docker.go | 11 +++++------ pkg/commands/service.go | 15 ++++++++------- pkg/gui/project_panel.go | 2 +- pkg/gui/services_panel.go | 14 +++++++------- 4 files changed, 21 insertions(+), 21 deletions(-) diff --git a/pkg/commands/docker.go b/pkg/commands/docker.go index 7961977e..edc3c6ff 100644 --- a/pkg/commands/docker.go +++ b/pkg/commands/docker.go @@ -238,20 +238,19 @@ func (c *DockerCommand) RefreshContainersAndServices() error { } func (c *DockerCommand) assignContainersToServices(containers []*Container, services []*Service) { -L: for _, service := range services { for _, container := range containers { if !container.OneOff && container.ServiceName == service.Name { - service.Container = container - continue L + service.Container = append(service.Container, container) + continue } if container.Container.Labels["com.docker.swarm.service.name"] == service.Name { //Swarm service - service.Container = container - continue L + service.Container = append(service.Container, container) + container.ServiceName = service.Name + continue } } - service.Container = nil } } diff --git a/pkg/commands/service.go b/pkg/commands/service.go index 59580ef4..c2b96cb2 100644 --- a/pkg/commands/service.go +++ b/pkg/commands/service.go @@ -1,9 +1,10 @@ package commands import ( - "github.com/docker/docker/api/types/container" "os/exec" + "github.com/docker/docker/api/types/container" + "github.com/docker/docker/api/types" "github.com/fatih/color" "github.com/jesseduffield/lazydocker/pkg/utils" @@ -16,24 +17,24 @@ type Service struct { ID string OSCommand *OSCommand Log *logrus.Entry - Container *Container + Container []*Container DockerCommand LimitedDockerCommand } // GetDisplayStrings returns the dispaly string of Container func (s *Service) GetDisplayStrings(isFocused bool) []string { - if s.Container == nil { + if len(s.Container) == 0 { return []string{utils.ColoredString("none", color.FgBlue), s.Name, ""} } - cont := s.Container + cont := s.Container[0] return []string{cont.GetDisplayStatus(), s.Name, cont.GetDisplayCPUPerc()} } // Remove removes the service's containers func (s *Service) Remove(options types.ContainerRemoveOptions) error { - return s.Container.Remove(options) + return s.Container[0].Remove(options) } // Stop stops the service's containers @@ -58,12 +59,12 @@ func (s *Service) Restart() error { // Attach attaches to the service func (s *Service) Attach() (*exec.Cmd, error) { - return s.Container.Attach() + return s.Container[0].Attach() } // Top returns process information func (s *Service) Top() (container.ContainerTopOKBody, error) { - return s.Container.Top() + return s.Container[0].Top() } // ViewLogs attaches to a subprocess viewing the service's logs diff --git a/pkg/gui/project_panel.go b/pkg/gui/project_panel.go index 76435f6b..cb6d2548 100644 --- a/pkg/gui/project_panel.go +++ b/pkg/gui/project_panel.go @@ -35,7 +35,7 @@ func (gui *Gui) refreshProject() error { if gui.DockerCommand.InDockerComposeProject { for _, service := range gui.DockerCommand.Services { if service.Container != nil { - projectName = service.Container.Details.Config.Labels["com.docker.compose.project"] + projectName = service.Container[0].Details.Config.Labels["com.docker.compose.project"] break } } diff --git a/pkg/gui/services_panel.go b/pkg/gui/services_panel.go index 460a3a07..8b4a95c4 100644 --- a/pkg/gui/services_panel.go +++ b/pkg/gui/services_panel.go @@ -47,7 +47,7 @@ func (gui *Gui) handleServiceSelect(g *gocui.Gui, v *gocui.View) error { containerID := "" if service.Container != nil { - containerID = service.Container.ID + containerID = service.Container[0].ID } if err := gui.focusPoint(0, gui.State.Panels.Services.SelectedLine, len(gui.DockerCommand.Services), v); err != nil { @@ -77,7 +77,7 @@ func (gui *Gui) handleServiceSelect(g *gocui.Gui, v *gocui.View) error { if service.Container == nil { return gui.renderString(gui.g, "main", gui.Tr.NoContainer) } - if err := gui.renderContainerConfig(service.Container); err != nil { + if err := gui.renderContainerConfig(service.Container[0]); err != nil { return err } case "top": @@ -92,11 +92,11 @@ func (gui *Gui) handleServiceSelect(g *gocui.Gui, v *gocui.View) error { } func (gui *Gui) renderServiceStats(service *commands.Service) error { - if service.Container == nil { + if len(service.Container) == 0 { return nil } - return gui.renderContainerStats(service.Container) + return gui.renderContainerStats(service.Container[0]) } func (gui *Gui) renderServiceTop(service *commands.Service) error { @@ -120,13 +120,13 @@ func (gui *Gui) renderServiceLogs(service *commands.Service) error { return nil } - if service.Container == nil { + if len(service.Container) == 0 { return gui.T.NewTask(func(stop chan struct{}) { gui.clearMainView() }) } - return gui.renderContainerLogs(service.Container) + return gui.renderContainerLogs(service.Container[0]) } func (gui *Gui) handleServicesNextLine(g *gocui.Gui, v *gocui.View) error { @@ -374,7 +374,7 @@ func (gui *Gui) handleServicesCustomCommand(g *gocui.Gui, v *gocui.View) error { commandObject := gui.DockerCommand.NewCommandObject(commands.CommandObject{ Service: service, - Container: service.Container, + Container: service.Container[0], }) var customCommands []config.CustomCommand