diff --git a/cmd/uncloud/service/ls.go b/cmd/uncloud/service/ls.go index 22d76f85..cc0c62a9 100644 --- a/cmd/uncloud/service/ls.go +++ b/cmd/uncloud/service/ls.go @@ -60,19 +60,20 @@ func list(ctx context.Context, uncli *cli.CLI, contextName string) error { return fmt.Errorf("write header: %w", err) } } - if _, err = fmt.Fprintln(tw, "NAME\tMODE\tREPLICAS\tENDPOINTS"); err != nil { + if _, err = fmt.Fprintln(tw, "NAME\tMODE\tREPLICAS\tIMAGE\tENDPOINTS"); err != nil { return fmt.Errorf("write header: %w", err) } for _, s := range services { - endpointsSlice := s.Endpoints() - endpoints := strings.Join(endpointsSlice, ", ") + images := strings.Join(s.Images(), ", ") + endpoints := strings.Join(s.Endpoints(), ", ") if haveDuplicateNames { if _, err = fmt.Fprintf(tw, "%s\t", s.ID); err != nil { return fmt.Errorf("write row: %w", err) } } - if _, err = fmt.Fprintf(tw, "%s\t%s\t%d\t%s\n", s.Name, s.Mode, len(s.Containers), endpoints); err != nil { + if _, err = fmt.Fprintf(tw, "%s\t%s\t%d\t%s\t%s\n", + s.Name, s.Mode, len(s.Containers), images, endpoints); err != nil { return fmt.Errorf("write row: %w", err) } } diff --git a/pkg/api/service.go b/pkg/api/service.go index 68514d49..976c36a7 100644 --- a/pkg/api/service.go +++ b/pkg/api/service.go @@ -346,6 +346,15 @@ type MachineServiceContainer struct { Container ServiceContainer } +// Images returns a sorted list of unique images used by the service containers. +func (s *Service) Images() []string { + images := make(map[string]struct{}) + for _, ctr := range s.Containers { + images[ctr.Container.Config.Image] = struct{}{} + } + return slices.Sorted(maps.Keys(images)) +} + // Endpoints returns the exposed HTTP and HTTPS endpoints of the service. func (s *Service) Endpoints() []string { endpoints := make(map[string]struct{})