nolint:gocyclo
(ctx context.Context, projectName string, options api.PsOptions)
| 30 | |
| 31 | //nolint:gocyclo |
| 32 | func (s *composeService) Ps(ctx context.Context, projectName string, options api.PsOptions) ([]api.ContainerSummary, error) { |
| 33 | projectName = strings.ToLower(projectName) |
| 34 | oneOff := oneOffExclude |
| 35 | if options.All { |
| 36 | oneOff = oneOffInclude |
| 37 | } |
| 38 | containers, err := s.getContainers(ctx, projectName, oneOff, options.All, options.Services...) |
| 39 | if err != nil { |
| 40 | return nil, err |
| 41 | } |
| 42 | |
| 43 | if len(options.Services) != 0 { |
| 44 | containers = containers.filter(isService(options.Services...)) |
| 45 | } |
| 46 | summary := make([]api.ContainerSummary, len(containers)) |
| 47 | eg, ctx := errgroup.WithContext(ctx) |
| 48 | for i, ctr := range containers { |
| 49 | eg.Go(func() error { |
| 50 | publishers := make([]api.PortPublisher, len(ctr.Ports)) |
| 51 | sort.Slice(ctr.Ports, func(i, j int) bool { |
| 52 | return ctr.Ports[i].PrivatePort < ctr.Ports[j].PrivatePort |
| 53 | }) |
| 54 | for i, p := range ctr.Ports { |
| 55 | var url string |
| 56 | if p.IP.IsValid() { |
| 57 | url = p.IP.String() |
| 58 | } |
| 59 | publishers[i] = api.PortPublisher{ |
| 60 | URL: url, // TODO(thaJeztah); change this to a netip.Addr ?? |
| 61 | TargetPort: int(p.PrivatePort), |
| 62 | PublishedPort: int(p.PublicPort), |
| 63 | Protocol: p.Type, |
| 64 | } |
| 65 | } |
| 66 | |
| 67 | inspect, err := s.apiClient().ContainerInspect(ctx, ctr.ID, client.ContainerInspectOptions{}) |
| 68 | if err != nil { |
| 69 | return err |
| 70 | } |
| 71 | |
| 72 | var ( |
| 73 | health container.HealthStatus |
| 74 | exitCode int |
| 75 | ) |
| 76 | if inspect.Container.State != nil { |
| 77 | switch inspect.Container.State.Status { |
| 78 | case container.StateRunning: |
| 79 | if inspect.Container.State.Health != nil { |
| 80 | health = inspect.Container.State.Health.Status |
| 81 | } |
| 82 | case container.StateExited, container.StateDead: |
| 83 | exitCode = inspect.Container.State.ExitCode |
| 84 | } |
| 85 | } |
| 86 | |
| 87 | var ( |
| 88 | local int |
| 89 | mounts []string |
nothing calls this directly
no test coverage detected