Merge pull request #1218 from docker/ps_all

Introduce --all option on compose ps
This commit is contained in:
Nicolas De loof 2021-02-02 14:24:14 +01:00 committed by GitHub
commit b5ac3183d7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 27 additions and 16 deletions

View File

@ -124,19 +124,19 @@ func (cs *aciComposeService) Down(ctx context.Context, projectName string, optio
return err return err
} }
func (cs *aciComposeService) Ps(ctx context.Context, project string) ([]compose.ContainerSummary, error) { func (cs *aciComposeService) Ps(ctx context.Context, projectName string, options compose.PsOptions) ([]compose.ContainerSummary, error) {
groupsClient, err := login.NewContainerGroupsClient(cs.ctx.SubscriptionID) groupsClient, err := login.NewContainerGroupsClient(cs.ctx.SubscriptionID)
if err != nil { if err != nil {
return nil, err return nil, err
} }
group, err := groupsClient.Get(ctx, cs.ctx.ResourceGroup, project) group, err := groupsClient.Get(ctx, cs.ctx.ResourceGroup, projectName)
if err != nil { if err != nil {
return nil, err return nil, err
} }
if group.Containers == nil || len(*group.Containers) == 0 { if group.Containers == nil || len(*group.Containers) == 0 {
return nil, fmt.Errorf("no containers found in ACI container group %s", project) return nil, fmt.Errorf("no containers found in ACI container group %s", projectName)
} }
res := []compose.ContainerSummary{} res := []compose.ContainerSummary{}
@ -158,7 +158,7 @@ func (cs *aciComposeService) Ps(ctx context.Context, project string) ([]compose.
res = append(res, compose.ContainerSummary{ res = append(res, compose.ContainerSummary{
ID: id, ID: id,
Name: id, Name: id,
Project: project, Project: projectName,
Service: *container.Name, Service: *container.Name,
State: convert.GetStatus(container, group), State: convert.GetStatus(container, group),
Publishers: publishers, Publishers: publishers,

View File

@ -64,7 +64,7 @@ func (c *composeService) Logs(context.Context, string, compose.LogConsumer, comp
return errdefs.ErrNotImplemented return errdefs.ErrNotImplemented
} }
func (c *composeService) Ps(context.Context, string) ([]compose.ContainerSummary, error) { func (c *composeService) Ps(context.Context, string, compose.PsOptions) ([]compose.ContainerSummary, error) {
return nil, errdefs.ErrNotImplemented return nil, errdefs.ErrNotImplemented
} }

View File

@ -44,7 +44,7 @@ type Service interface {
// Logs executes the equivalent to a `compose logs` // Logs executes the equivalent to a `compose logs`
Logs(ctx context.Context, projectName string, consumer LogConsumer, options LogOptions) error Logs(ctx context.Context, projectName string, consumer LogConsumer, options LogOptions) error
// Ps executes the equivalent to a `compose ps` // Ps executes the equivalent to a `compose ps`
Ps(ctx context.Context, projectName string) ([]ContainerSummary, error) Ps(ctx context.Context, projectName string, options PsOptions) ([]ContainerSummary, error)
// List executes the equivalent to a `docker stack ls` // List executes the equivalent to a `docker stack ls`
List(ctx context.Context) ([]Stack, error) List(ctx context.Context) ([]Stack, error)
// Convert translate compose model into backend's native format // Convert translate compose model into backend's native format
@ -91,6 +91,11 @@ type RunOptions struct {
Reader io.Reader Reader io.Reader
} }
// PsOptions group options of the Ps API
type PsOptions struct {
All bool
}
// PortPublisher hold status about published port // PortPublisher hold status about published port
type PortPublisher struct { type PortPublisher struct {
URL string URL string

View File

@ -27,12 +27,14 @@ import (
"github.com/spf13/cobra" "github.com/spf13/cobra"
"github.com/docker/compose-cli/api/client" "github.com/docker/compose-cli/api/client"
"github.com/docker/compose-cli/api/compose"
"github.com/docker/compose-cli/cli/formatter" "github.com/docker/compose-cli/cli/formatter"
) )
type psOptions struct { type psOptions struct {
*projectOptions *projectOptions
Format string Format string
All bool
Quiet bool Quiet bool
} }
@ -49,6 +51,7 @@ func psCommand(p *projectOptions) *cobra.Command {
} }
psCmd.Flags().StringVar(&opts.Format, "format", "pretty", "Format the output. Values: [pretty | json].") psCmd.Flags().StringVar(&opts.Format, "format", "pretty", "Format the output. Values: [pretty | json].")
psCmd.Flags().BoolVarP(&opts.Quiet, "quiet", "q", false, "Only display IDs") psCmd.Flags().BoolVarP(&opts.Quiet, "quiet", "q", false, "Only display IDs")
psCmd.Flags().BoolVarP(&opts.All, "all", "a", false, "Show all stopped containers (including those created by the run command)")
return psCmd return psCmd
} }
@ -62,7 +65,9 @@ func runPs(ctx context.Context, opts psOptions) error {
if err != nil { if err != nil {
return err return err
} }
containers, err := c.ComposeService().Ps(ctx, projectName) containers, err := c.ComposeService().Ps(ctx, projectName, compose.PsOptions{
All: opts.All,
})
if err != nil { if err != nil {
return err return err
} }

View File

@ -59,7 +59,7 @@ func (p *proxy) Services(ctx context.Context, request *composev1.ComposeServices
projectName = project.Name projectName = project.Name
} }
response := []*composev1.Service{} response := []*composev1.Service{}
_, err := Client(ctx).ComposeService().Ps(ctx, projectName) _, err := Client(ctx).ComposeService().Ps(ctx, projectName, compose.PsOptions{})
if err != nil { if err != nil {
return nil, err return nil, err
} }

View File

@ -162,8 +162,8 @@ func (e ecsLocalSimulation) Logs(ctx context.Context, projectName string, consum
return e.compose.Logs(ctx, projectName, consumer, options) return e.compose.Logs(ctx, projectName, consumer, options)
} }
func (e ecsLocalSimulation) Ps(ctx context.Context, projectName string) ([]compose.ContainerSummary, error) { func (e ecsLocalSimulation) Ps(ctx context.Context, projectName string, options compose.PsOptions) ([]compose.ContainerSummary, error) {
return e.compose.Ps(ctx, projectName) return e.compose.Ps(ctx, projectName, options)
} }
func (e ecsLocalSimulation) List(ctx context.Context) ([]compose.Stack, error) { func (e ecsLocalSimulation) List(ctx context.Context) ([]compose.Stack, error) {
return e.compose.List(ctx) return e.compose.List(ctx)

View File

@ -22,12 +22,12 @@ import (
"github.com/docker/compose-cli/api/compose" "github.com/docker/compose-cli/api/compose"
) )
func (b *ecsAPIService) Ps(ctx context.Context, project string) ([]compose.ContainerSummary, error) { func (b *ecsAPIService) Ps(ctx context.Context, projectName string, options compose.PsOptions) ([]compose.ContainerSummary, error) {
cluster, err := b.aws.GetStackClusterID(ctx, project) cluster, err := b.aws.GetStackClusterID(ctx, projectName)
if err != nil { if err != nil {
return nil, err return nil, err
} }
servicesARN, err := b.aws.ListStackServices(ctx, project) servicesARN, err := b.aws.ListStackServices(ctx, projectName)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -43,7 +43,7 @@ func (b *ecsAPIService) Ps(ctx context.Context, project string) ([]compose.Conta
return nil, err return nil, err
} }
tasks, err := b.aws.DescribeServiceTasks(ctx, cluster, project, service.Name) tasks, err := b.aws.DescribeServiceTasks(ctx, cluster, projectName, service.Name)
if err != nil { if err != nil {
return nil, err return nil, err
} }

View File

@ -94,7 +94,7 @@ func (s *composeService) Logs(ctx context.Context, projectName string, consumer
} }
// Ps executes the equivalent to a `compose ps` // Ps executes the equivalent to a `compose ps`
func (s *composeService) Ps(ctx context.Context, projectName string) ([]compose.ContainerSummary, error) { func (s *composeService) Ps(ctx context.Context, projectName string, options compose.PsOptions) ([]compose.ContainerSummary, error) {
return nil, errdefs.ErrNotImplemented return nil, errdefs.ErrNotImplemented
} }

View File

@ -27,11 +27,12 @@ import (
"github.com/docker/compose-cli/api/compose" "github.com/docker/compose-cli/api/compose"
) )
func (s *composeService) Ps(ctx context.Context, projectName string) ([]compose.ContainerSummary, error) { func (s *composeService) Ps(ctx context.Context, projectName string, options compose.PsOptions) ([]compose.ContainerSummary, error) {
containers, err := s.apiClient.ContainerList(ctx, moby.ContainerListOptions{ containers, err := s.apiClient.ContainerList(ctx, moby.ContainerListOptions{
Filters: filters.NewArgs( Filters: filters.NewArgs(
projectFilter(projectName), projectFilter(projectName),
), ),
All: options.All,
}) })
if err != nil { if err != nil {
return nil, err return nil, err