From cba4f140aed02ee6ff1c73b52292e2b9e7fec0d3 Mon Sep 17 00:00:00 2001 From: Guillaume Tardif Date: Wed, 24 Feb 2021 12:06:17 +0100 Subject: [PATCH] =?UTF-8?q?Add=20=E2=80=94all=20option=20to=20compose=20ls?= =?UTF-8?q?,=20listing=20non=20running=20projects.=20Added=20e2e=20tests?= =?UTF-8?q?=20to=20stop,=20start,=20pause,=20unpause,=20ls=20=E2=80=94all,?= =?UTF-8?q?=20ps=20=E2=80=94all?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Guillaume Tardif --- aci/compose.go | 2 +- api/client/compose.go | 2 +- api/compose/api.go | 7 +- cli/cmd/compose/compose.go | 2 +- cli/cmd/compose/list.go | 9 +- cli/server/protos/compose/v1/compose.pb.go | 143 ++++++++++-------- cli/server/protos/compose/v1/compose.proto | 1 + .../protos/containers/v1/containers.pb.go | 2 +- cli/server/protos/contexts/v1/contexts.pb.go | 2 +- cli/server/protos/streams/v1/streams.pb.go | 2 +- cli/server/protos/volumes/v1/volumes.pb.go | 2 +- cli/server/proxy/compose.go | 2 +- ecs/list.go | 2 +- ecs/local/compose.go | 4 +- kube/compose.go | 2 +- local/compose/ls.go | 3 +- .../compose/fixtures/start-stop/compose.yml | 5 + local/e2e/compose/start_stop_test.go | 102 +++++++++++++ 18 files changed, 211 insertions(+), 83 deletions(-) create mode 100644 local/e2e/compose/fixtures/start-stop/compose.yml create mode 100644 local/e2e/compose/start_stop_test.go diff --git a/aci/compose.go b/aci/compose.go index a417be197..8beba0ba2 100644 --- a/aci/compose.go +++ b/aci/compose.go @@ -175,7 +175,7 @@ func (cs *aciComposeService) Ps(ctx context.Context, projectName string, options return res, nil } -func (cs *aciComposeService) List(ctx context.Context) ([]compose.Stack, error) { +func (cs *aciComposeService) List(ctx context.Context, opts compose.ListOptions) ([]compose.Stack, error) { containerGroups, err := getACIContainerGroups(ctx, cs.ctx.SubscriptionID, cs.ctx.ResourceGroup) if err != nil { return nil, err diff --git a/api/client/compose.go b/api/client/compose.go index 29373e473..75e7be163 100644 --- a/api/client/compose.go +++ b/api/client/compose.go @@ -68,7 +68,7 @@ func (c *composeService) Ps(context.Context, string, compose.PsOptions) ([]compo return nil, errdefs.ErrNotImplemented } -func (c *composeService) List(context.Context) ([]compose.Stack, error) { +func (c *composeService) List(context.Context, compose.ListOptions) ([]compose.Stack, error) { return nil, errdefs.ErrNotImplemented } diff --git a/api/compose/api.go b/api/compose/api.go index c68b5e93b..cd9dc4d86 100644 --- a/api/compose/api.go +++ b/api/compose/api.go @@ -48,7 +48,7 @@ type Service interface { // Ps executes the equivalent to a `compose ps` Ps(ctx context.Context, projectName string, options PsOptions) ([]ContainerSummary, error) // List executes the equivalent to a `docker stack ls` - List(ctx context.Context) ([]Stack, error) + List(ctx context.Context, options ListOptions) ([]Stack, error) // Convert translate compose model into backend's native format Convert(ctx context.Context, project *types.Project, options ConvertOptions) ([]byte, error) // Kill executes the equivalent to a `compose kill` @@ -165,6 +165,11 @@ func (opts *RunOptions) EnvironmentMap() types.MappingWithEquals { return environment } +// ListOptions group options of the ls API +type ListOptions struct { + All bool +} + // PsOptions group options of the Ps API type PsOptions struct { All bool diff --git a/cli/cmd/compose/compose.go b/cli/cmd/compose/compose.go index 5bb63cd9d..7cf9b0c17 100644 --- a/cli/cmd/compose/compose.go +++ b/cli/cmd/compose/compose.go @@ -113,7 +113,7 @@ func Command(contextType string) *cobra.Command { startCommand(&opts), stopCommand(&opts), psCommand(&opts), - listCommand(), + listCommand(contextType), logsCommand(&opts, contextType), convertCommand(&opts), killCommand(&opts), diff --git a/cli/cmd/compose/list.go b/cli/cmd/compose/list.go index b45b8f2a4..54f8d1d40 100644 --- a/cli/cmd/compose/list.go +++ b/cli/cmd/compose/list.go @@ -28,16 +28,18 @@ import ( "github.com/docker/compose-cli/api/client" "github.com/docker/compose-cli/api/compose" + "github.com/docker/compose-cli/api/context/store" "github.com/docker/compose-cli/cli/formatter" ) type lsOptions struct { Format string Quiet bool + All bool Filter opts.FilterOpt } -func listCommand() *cobra.Command { +func listCommand(contextType string) *cobra.Command { opts := lsOptions{Filter: opts.NewFilterOpt()} lsCmd := &cobra.Command{ Use: "ls", @@ -49,6 +51,9 @@ func listCommand() *cobra.Command { lsCmd.Flags().StringVar(&opts.Format, "format", "pretty", "Format the output. Values: [pretty | json].") lsCmd.Flags().BoolVarP(&opts.Quiet, "quiet", "q", false, "Only display IDs.") lsCmd.Flags().Var(&opts.Filter, "filter", "Filter output based on conditions provided.") + if contextType == store.DefaultContextType { + lsCmd.Flags().BoolVarP(&opts.All, "all", "a", false, "Show all stopped Compose projects") + } return lsCmd } @@ -68,7 +73,7 @@ func runList(ctx context.Context, opts lsOptions) error { if err != nil { return err } - stackList, err := c.ComposeService().List(ctx) + stackList, err := c.ComposeService().List(ctx, compose.ListOptions{All: opts.All}) if err != nil { return err } diff --git a/cli/server/protos/compose/v1/compose.pb.go b/cli/server/protos/compose/v1/compose.pb.go index ba8d408c2..b1affb9e4 100644 --- a/cli/server/protos/compose/v1/compose.pb.go +++ b/cli/server/protos/compose/v1/compose.pb.go @@ -16,7 +16,7 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: // protoc-gen-go v1.25.0 -// protoc v3.12.2 +// protoc v3.13.0 // source: cli/server/protos/compose/v1/compose.proto package v1 @@ -270,6 +270,7 @@ type ComposeStacksRequest struct { unknownFields protoimpl.UnknownFields ProjectName string `protobuf:"bytes,1,opt,name=projectName,proto3" json:"projectName,omitempty"` + All bool `protobuf:"varint,2,opt,name=all,proto3" json:"all,omitempty"` } func (x *ComposeStacksRequest) Reset() { @@ -311,6 +312,13 @@ func (x *ComposeStacksRequest) GetProjectName() string { return "" } +func (x *ComposeStacksRequest) GetAll() bool { + if x != nil { + return x.All + } + return false +} + type ComposeStacksResponse struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache @@ -645,78 +653,79 @@ var file_cli_server_protos_compose_v1_compose_proto_rawDesc = []byte{ 0x6c, 0x65, 0x73, 0x22, 0x37, 0x0a, 0x13, 0x43, 0x6f, 0x6d, 0x70, 0x6f, 0x73, 0x65, 0x44, 0x6f, 0x77, 0x6e, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x20, 0x0a, 0x0b, 0x70, 0x72, 0x6f, 0x6a, 0x65, 0x63, 0x74, 0x4e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, - 0x0b, 0x70, 0x72, 0x6f, 0x6a, 0x65, 0x63, 0x74, 0x4e, 0x61, 0x6d, 0x65, 0x22, 0x38, 0x0a, 0x14, + 0x0b, 0x70, 0x72, 0x6f, 0x6a, 0x65, 0x63, 0x74, 0x4e, 0x61, 0x6d, 0x65, 0x22, 0x4a, 0x0a, 0x14, 0x43, 0x6f, 0x6d, 0x70, 0x6f, 0x73, 0x65, 0x53, 0x74, 0x61, 0x63, 0x6b, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x20, 0x0a, 0x0b, 0x70, 0x72, 0x6f, 0x6a, 0x65, 0x63, 0x74, 0x4e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x70, 0x72, 0x6f, 0x6a, 0x65, - 0x63, 0x74, 0x4e, 0x61, 0x6d, 0x65, 0x22, 0x58, 0x0a, 0x15, 0x43, 0x6f, 0x6d, 0x70, 0x6f, 0x73, - 0x65, 0x53, 0x74, 0x61, 0x63, 0x6b, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, - 0x3f, 0x0a, 0x06, 0x73, 0x74, 0x61, 0x63, 0x6b, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, - 0x27, 0x2e, 0x63, 0x6f, 0x6d, 0x2e, 0x64, 0x6f, 0x63, 0x6b, 0x65, 0x72, 0x2e, 0x61, 0x70, 0x69, - 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x73, 0x2e, 0x63, 0x6f, 0x6d, 0x70, 0x6f, 0x73, 0x65, 0x2e, - 0x76, 0x31, 0x2e, 0x53, 0x74, 0x61, 0x63, 0x6b, 0x52, 0x06, 0x73, 0x74, 0x61, 0x63, 0x6b, 0x73, - 0x22, 0x5b, 0x0a, 0x05, 0x53, 0x74, 0x61, 0x63, 0x6b, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, - 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x02, 0x69, 0x64, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, - 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x16, 0x0a, - 0x06, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x73, - 0x74, 0x61, 0x74, 0x75, 0x73, 0x12, 0x16, 0x0a, 0x06, 0x72, 0x65, 0x61, 0x73, 0x6f, 0x6e, 0x18, - 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x72, 0x65, 0x61, 0x73, 0x6f, 0x6e, 0x22, 0x6a, 0x0a, - 0x16, 0x43, 0x6f, 0x6d, 0x70, 0x6f, 0x73, 0x65, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x73, - 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x20, 0x0a, 0x0b, 0x70, 0x72, 0x6f, 0x6a, 0x65, - 0x63, 0x74, 0x4e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x70, 0x72, - 0x6f, 0x6a, 0x65, 0x63, 0x74, 0x4e, 0x61, 0x6d, 0x65, 0x12, 0x18, 0x0a, 0x07, 0x77, 0x6f, 0x72, - 0x6b, 0x44, 0x69, 0x72, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x77, 0x6f, 0x72, 0x6b, - 0x44, 0x69, 0x72, 0x12, 0x14, 0x0a, 0x05, 0x66, 0x69, 0x6c, 0x65, 0x73, 0x18, 0x03, 0x20, 0x03, - 0x28, 0x09, 0x52, 0x05, 0x66, 0x69, 0x6c, 0x65, 0x73, 0x22, 0x60, 0x0a, 0x17, 0x43, 0x6f, 0x6d, - 0x70, 0x6f, 0x73, 0x65, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x73, 0x52, 0x65, 0x73, 0x70, - 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x45, 0x0a, 0x08, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x73, - 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x29, 0x2e, 0x63, 0x6f, 0x6d, 0x2e, 0x64, 0x6f, 0x63, - 0x6b, 0x65, 0x72, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x73, 0x2e, 0x63, - 0x6f, 0x6d, 0x70, 0x6f, 0x73, 0x65, 0x2e, 0x76, 0x31, 0x2e, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, - 0x65, 0x52, 0x08, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x73, 0x22, 0x79, 0x0a, 0x07, 0x53, - 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, - 0x28, 0x09, 0x52, 0x02, 0x69, 0x64, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x02, - 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x1a, 0x0a, 0x08, 0x72, 0x65, - 0x70, 0x6c, 0x69, 0x63, 0x61, 0x73, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x08, 0x72, 0x65, - 0x70, 0x6c, 0x69, 0x63, 0x61, 0x73, 0x12, 0x18, 0x0a, 0x07, 0x64, 0x65, 0x73, 0x69, 0x72, 0x65, - 0x64, 0x18, 0x04, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x07, 0x64, 0x65, 0x73, 0x69, 0x72, 0x65, 0x64, - 0x12, 0x14, 0x0a, 0x05, 0x50, 0x6f, 0x72, 0x74, 0x73, 0x18, 0x05, 0x20, 0x03, 0x28, 0x09, 0x52, - 0x05, 0x50, 0x6f, 0x72, 0x74, 0x73, 0x32, 0xe9, 0x03, 0x0a, 0x07, 0x43, 0x6f, 0x6d, 0x70, 0x6f, - 0x73, 0x65, 0x12, 0x6d, 0x0a, 0x02, 0x55, 0x70, 0x12, 0x32, 0x2e, 0x63, 0x6f, 0x6d, 0x2e, 0x64, + 0x63, 0x74, 0x4e, 0x61, 0x6d, 0x65, 0x12, 0x10, 0x0a, 0x03, 0x61, 0x6c, 0x6c, 0x18, 0x02, 0x20, + 0x01, 0x28, 0x08, 0x52, 0x03, 0x61, 0x6c, 0x6c, 0x22, 0x58, 0x0a, 0x15, 0x43, 0x6f, 0x6d, 0x70, + 0x6f, 0x73, 0x65, 0x53, 0x74, 0x61, 0x63, 0x6b, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, + 0x65, 0x12, 0x3f, 0x0a, 0x06, 0x73, 0x74, 0x61, 0x63, 0x6b, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, + 0x0b, 0x32, 0x27, 0x2e, 0x63, 0x6f, 0x6d, 0x2e, 0x64, 0x6f, 0x63, 0x6b, 0x65, 0x72, 0x2e, 0x61, + 0x70, 0x69, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x73, 0x2e, 0x63, 0x6f, 0x6d, 0x70, 0x6f, 0x73, + 0x65, 0x2e, 0x76, 0x31, 0x2e, 0x53, 0x74, 0x61, 0x63, 0x6b, 0x52, 0x06, 0x73, 0x74, 0x61, 0x63, + 0x6b, 0x73, 0x22, 0x5b, 0x0a, 0x05, 0x53, 0x74, 0x61, 0x63, 0x6b, 0x12, 0x0e, 0x0a, 0x02, 0x69, + 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x02, 0x69, 0x64, 0x12, 0x12, 0x0a, 0x04, 0x6e, + 0x61, 0x6d, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x12, + 0x16, 0x0a, 0x06, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, + 0x06, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x12, 0x16, 0x0a, 0x06, 0x72, 0x65, 0x61, 0x73, 0x6f, + 0x6e, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x72, 0x65, 0x61, 0x73, 0x6f, 0x6e, 0x22, + 0x6a, 0x0a, 0x16, 0x43, 0x6f, 0x6d, 0x70, 0x6f, 0x73, 0x65, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, + 0x65, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x20, 0x0a, 0x0b, 0x70, 0x72, 0x6f, + 0x6a, 0x65, 0x63, 0x74, 0x4e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, + 0x70, 0x72, 0x6f, 0x6a, 0x65, 0x63, 0x74, 0x4e, 0x61, 0x6d, 0x65, 0x12, 0x18, 0x0a, 0x07, 0x77, + 0x6f, 0x72, 0x6b, 0x44, 0x69, 0x72, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x77, 0x6f, + 0x72, 0x6b, 0x44, 0x69, 0x72, 0x12, 0x14, 0x0a, 0x05, 0x66, 0x69, 0x6c, 0x65, 0x73, 0x18, 0x03, + 0x20, 0x03, 0x28, 0x09, 0x52, 0x05, 0x66, 0x69, 0x6c, 0x65, 0x73, 0x22, 0x60, 0x0a, 0x17, 0x43, + 0x6f, 0x6d, 0x70, 0x6f, 0x73, 0x65, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x73, 0x52, 0x65, + 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x45, 0x0a, 0x08, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, + 0x65, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x29, 0x2e, 0x63, 0x6f, 0x6d, 0x2e, 0x64, 0x6f, 0x63, 0x6b, 0x65, 0x72, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x73, - 0x2e, 0x63, 0x6f, 0x6d, 0x70, 0x6f, 0x73, 0x65, 0x2e, 0x76, 0x31, 0x2e, 0x43, 0x6f, 0x6d, 0x70, - 0x6f, 0x73, 0x65, 0x55, 0x70, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x33, 0x2e, 0x63, - 0x6f, 0x6d, 0x2e, 0x64, 0x6f, 0x63, 0x6b, 0x65, 0x72, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x70, 0x72, - 0x6f, 0x74, 0x6f, 0x73, 0x2e, 0x63, 0x6f, 0x6d, 0x70, 0x6f, 0x73, 0x65, 0x2e, 0x76, 0x31, 0x2e, - 0x43, 0x6f, 0x6d, 0x70, 0x6f, 0x73, 0x65, 0x55, 0x70, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, - 0x65, 0x12, 0x73, 0x0a, 0x04, 0x44, 0x6f, 0x77, 0x6e, 0x12, 0x34, 0x2e, 0x63, 0x6f, 0x6d, 0x2e, + 0x2e, 0x63, 0x6f, 0x6d, 0x70, 0x6f, 0x73, 0x65, 0x2e, 0x76, 0x31, 0x2e, 0x53, 0x65, 0x72, 0x76, + 0x69, 0x63, 0x65, 0x52, 0x08, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x73, 0x22, 0x79, 0x0a, + 0x07, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, + 0x20, 0x01, 0x28, 0x09, 0x52, 0x02, 0x69, 0x64, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, + 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x1a, 0x0a, 0x08, + 0x72, 0x65, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x73, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x08, + 0x72, 0x65, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x73, 0x12, 0x18, 0x0a, 0x07, 0x64, 0x65, 0x73, 0x69, + 0x72, 0x65, 0x64, 0x18, 0x04, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x07, 0x64, 0x65, 0x73, 0x69, 0x72, + 0x65, 0x64, 0x12, 0x14, 0x0a, 0x05, 0x50, 0x6f, 0x72, 0x74, 0x73, 0x18, 0x05, 0x20, 0x03, 0x28, + 0x09, 0x52, 0x05, 0x50, 0x6f, 0x72, 0x74, 0x73, 0x32, 0xe9, 0x03, 0x0a, 0x07, 0x43, 0x6f, 0x6d, + 0x70, 0x6f, 0x73, 0x65, 0x12, 0x6d, 0x0a, 0x02, 0x55, 0x70, 0x12, 0x32, 0x2e, 0x63, 0x6f, 0x6d, + 0x2e, 0x64, 0x6f, 0x63, 0x6b, 0x65, 0x72, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x70, 0x72, 0x6f, 0x74, + 0x6f, 0x73, 0x2e, 0x63, 0x6f, 0x6d, 0x70, 0x6f, 0x73, 0x65, 0x2e, 0x76, 0x31, 0x2e, 0x43, 0x6f, + 0x6d, 0x70, 0x6f, 0x73, 0x65, 0x55, 0x70, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x33, + 0x2e, 0x63, 0x6f, 0x6d, 0x2e, 0x64, 0x6f, 0x63, 0x6b, 0x65, 0x72, 0x2e, 0x61, 0x70, 0x69, 0x2e, + 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x73, 0x2e, 0x63, 0x6f, 0x6d, 0x70, 0x6f, 0x73, 0x65, 0x2e, 0x76, + 0x31, 0x2e, 0x43, 0x6f, 0x6d, 0x70, 0x6f, 0x73, 0x65, 0x55, 0x70, 0x52, 0x65, 0x73, 0x70, 0x6f, + 0x6e, 0x73, 0x65, 0x12, 0x73, 0x0a, 0x04, 0x44, 0x6f, 0x77, 0x6e, 0x12, 0x34, 0x2e, 0x63, 0x6f, + 0x6d, 0x2e, 0x64, 0x6f, 0x63, 0x6b, 0x65, 0x72, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x70, 0x72, 0x6f, + 0x74, 0x6f, 0x73, 0x2e, 0x63, 0x6f, 0x6d, 0x70, 0x6f, 0x73, 0x65, 0x2e, 0x76, 0x31, 0x2e, 0x43, + 0x6f, 0x6d, 0x70, 0x6f, 0x73, 0x65, 0x44, 0x6f, 0x77, 0x6e, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, + 0x74, 0x1a, 0x35, 0x2e, 0x63, 0x6f, 0x6d, 0x2e, 0x64, 0x6f, 0x63, 0x6b, 0x65, 0x72, 0x2e, 0x61, + 0x70, 0x69, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x73, 0x2e, 0x63, 0x6f, 0x6d, 0x70, 0x6f, 0x73, + 0x65, 0x2e, 0x76, 0x31, 0x2e, 0x43, 0x6f, 0x6d, 0x70, 0x6f, 0x73, 0x65, 0x44, 0x6f, 0x77, 0x6e, + 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x79, 0x0a, 0x06, 0x53, 0x74, 0x61, 0x63, + 0x6b, 0x73, 0x12, 0x36, 0x2e, 0x63, 0x6f, 0x6d, 0x2e, 0x64, 0x6f, 0x63, 0x6b, 0x65, 0x72, 0x2e, + 0x61, 0x70, 0x69, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x73, 0x2e, 0x63, 0x6f, 0x6d, 0x70, 0x6f, + 0x73, 0x65, 0x2e, 0x76, 0x31, 0x2e, 0x43, 0x6f, 0x6d, 0x70, 0x6f, 0x73, 0x65, 0x53, 0x74, 0x61, + 0x63, 0x6b, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x37, 0x2e, 0x63, 0x6f, 0x6d, + 0x2e, 0x64, 0x6f, 0x63, 0x6b, 0x65, 0x72, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x70, 0x72, 0x6f, 0x74, + 0x6f, 0x73, 0x2e, 0x63, 0x6f, 0x6d, 0x70, 0x6f, 0x73, 0x65, 0x2e, 0x76, 0x31, 0x2e, 0x43, 0x6f, + 0x6d, 0x70, 0x6f, 0x73, 0x65, 0x53, 0x74, 0x61, 0x63, 0x6b, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, + 0x6e, 0x73, 0x65, 0x12, 0x7f, 0x0a, 0x08, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x73, 0x12, + 0x38, 0x2e, 0x63, 0x6f, 0x6d, 0x2e, 0x64, 0x6f, 0x63, 0x6b, 0x65, 0x72, 0x2e, 0x61, 0x70, 0x69, + 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x73, 0x2e, 0x63, 0x6f, 0x6d, 0x70, 0x6f, 0x73, 0x65, 0x2e, + 0x76, 0x31, 0x2e, 0x43, 0x6f, 0x6d, 0x70, 0x6f, 0x73, 0x65, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, + 0x65, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x39, 0x2e, 0x63, 0x6f, 0x6d, 0x2e, 0x64, 0x6f, 0x63, 0x6b, 0x65, 0x72, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x73, 0x2e, 0x63, 0x6f, 0x6d, 0x70, 0x6f, 0x73, 0x65, 0x2e, 0x76, 0x31, 0x2e, 0x43, 0x6f, 0x6d, - 0x70, 0x6f, 0x73, 0x65, 0x44, 0x6f, 0x77, 0x6e, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, - 0x35, 0x2e, 0x63, 0x6f, 0x6d, 0x2e, 0x64, 0x6f, 0x63, 0x6b, 0x65, 0x72, 0x2e, 0x61, 0x70, 0x69, - 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x73, 0x2e, 0x63, 0x6f, 0x6d, 0x70, 0x6f, 0x73, 0x65, 0x2e, - 0x76, 0x31, 0x2e, 0x43, 0x6f, 0x6d, 0x70, 0x6f, 0x73, 0x65, 0x44, 0x6f, 0x77, 0x6e, 0x52, 0x65, - 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x79, 0x0a, 0x06, 0x53, 0x74, 0x61, 0x63, 0x6b, 0x73, - 0x12, 0x36, 0x2e, 0x63, 0x6f, 0x6d, 0x2e, 0x64, 0x6f, 0x63, 0x6b, 0x65, 0x72, 0x2e, 0x61, 0x70, - 0x69, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x73, 0x2e, 0x63, 0x6f, 0x6d, 0x70, 0x6f, 0x73, 0x65, - 0x2e, 0x76, 0x31, 0x2e, 0x43, 0x6f, 0x6d, 0x70, 0x6f, 0x73, 0x65, 0x53, 0x74, 0x61, 0x63, 0x6b, - 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x37, 0x2e, 0x63, 0x6f, 0x6d, 0x2e, 0x64, - 0x6f, 0x63, 0x6b, 0x65, 0x72, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x73, - 0x2e, 0x63, 0x6f, 0x6d, 0x70, 0x6f, 0x73, 0x65, 0x2e, 0x76, 0x31, 0x2e, 0x43, 0x6f, 0x6d, 0x70, - 0x6f, 0x73, 0x65, 0x53, 0x74, 0x61, 0x63, 0x6b, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, - 0x65, 0x12, 0x7f, 0x0a, 0x08, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x73, 0x12, 0x38, 0x2e, - 0x63, 0x6f, 0x6d, 0x2e, 0x64, 0x6f, 0x63, 0x6b, 0x65, 0x72, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x70, - 0x72, 0x6f, 0x74, 0x6f, 0x73, 0x2e, 0x63, 0x6f, 0x6d, 0x70, 0x6f, 0x73, 0x65, 0x2e, 0x76, 0x31, - 0x2e, 0x43, 0x6f, 0x6d, 0x70, 0x6f, 0x73, 0x65, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x73, - 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x39, 0x2e, 0x63, 0x6f, 0x6d, 0x2e, 0x64, 0x6f, - 0x63, 0x6b, 0x65, 0x72, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x73, 0x2e, - 0x63, 0x6f, 0x6d, 0x70, 0x6f, 0x73, 0x65, 0x2e, 0x76, 0x31, 0x2e, 0x43, 0x6f, 0x6d, 0x70, 0x6f, - 0x73, 0x65, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, - 0x73, 0x65, 0x42, 0x3f, 0x5a, 0x3d, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, - 0x2f, 0x64, 0x6f, 0x63, 0x6b, 0x65, 0x72, 0x2f, 0x63, 0x6f, 0x6d, 0x70, 0x6f, 0x73, 0x65, 0x2d, - 0x63, 0x6c, 0x69, 0x2f, 0x63, 0x6c, 0x69, 0x2f, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x2f, 0x70, - 0x72, 0x6f, 0x74, 0x6f, 0x73, 0x2f, 0x63, 0x6f, 0x6d, 0x70, 0x6f, 0x73, 0x65, 0x2f, 0x76, 0x31, - 0x3b, 0x76, 0x31, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x70, 0x6f, 0x73, 0x65, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x73, 0x52, 0x65, 0x73, 0x70, + 0x6f, 0x6e, 0x73, 0x65, 0x42, 0x3f, 0x5a, 0x3d, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, + 0x6f, 0x6d, 0x2f, 0x64, 0x6f, 0x63, 0x6b, 0x65, 0x72, 0x2f, 0x63, 0x6f, 0x6d, 0x70, 0x6f, 0x73, + 0x65, 0x2d, 0x63, 0x6c, 0x69, 0x2f, 0x63, 0x6c, 0x69, 0x2f, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, + 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x73, 0x2f, 0x63, 0x6f, 0x6d, 0x70, 0x6f, 0x73, 0x65, 0x2f, + 0x76, 0x31, 0x3b, 0x76, 0x31, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( diff --git a/cli/server/protos/compose/v1/compose.proto b/cli/server/protos/compose/v1/compose.proto index 2858af163..81a088e86 100644 --- a/cli/server/protos/compose/v1/compose.proto +++ b/cli/server/protos/compose/v1/compose.proto @@ -48,6 +48,7 @@ message ComposeDownResponse { message ComposeStacksRequest { string projectName = 1; + bool all = 2; } message ComposeStacksResponse { diff --git a/cli/server/protos/containers/v1/containers.pb.go b/cli/server/protos/containers/v1/containers.pb.go index 6b98ce334..32a88513b 100644 --- a/cli/server/protos/containers/v1/containers.pb.go +++ b/cli/server/protos/containers/v1/containers.pb.go @@ -16,7 +16,7 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: // protoc-gen-go v1.25.0 -// protoc v3.12.2 +// protoc v3.13.0 // source: cli/server/protos/containers/v1/containers.proto package v1 diff --git a/cli/server/protos/contexts/v1/contexts.pb.go b/cli/server/protos/contexts/v1/contexts.pb.go index 6014e4292..7153570c8 100644 --- a/cli/server/protos/contexts/v1/contexts.pb.go +++ b/cli/server/protos/contexts/v1/contexts.pb.go @@ -16,7 +16,7 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: // protoc-gen-go v1.25.0 -// protoc v3.12.2 +// protoc v3.13.0 // source: cli/server/protos/contexts/v1/contexts.proto package v1 diff --git a/cli/server/protos/streams/v1/streams.pb.go b/cli/server/protos/streams/v1/streams.pb.go index a27c8ce9a..bfc775cc8 100644 --- a/cli/server/protos/streams/v1/streams.pb.go +++ b/cli/server/protos/streams/v1/streams.pb.go @@ -16,7 +16,7 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: // protoc-gen-go v1.25.0 -// protoc v3.12.2 +// protoc v3.13.0 // source: cli/server/protos/streams/v1/streams.proto package v1 diff --git a/cli/server/protos/volumes/v1/volumes.pb.go b/cli/server/protos/volumes/v1/volumes.pb.go index 435829760..22e15063e 100644 --- a/cli/server/protos/volumes/v1/volumes.pb.go +++ b/cli/server/protos/volumes/v1/volumes.pb.go @@ -16,7 +16,7 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: // protoc-gen-go v1.25.0 -// protoc v3.12.2 +// protoc v3.13.0 // source: cli/server/protos/volumes/v1/volumes.proto package v1 diff --git a/cli/server/proxy/compose.go b/cli/server/proxy/compose.go index 0fac7cc9d..fa3f914fe 100644 --- a/cli/server/proxy/compose.go +++ b/cli/server/proxy/compose.go @@ -77,7 +77,7 @@ func (p *proxy) Services(ctx context.Context, request *composev1.ComposeServices } func (p *proxy) Stacks(ctx context.Context, request *composev1.ComposeStacksRequest) (*composev1.ComposeStacksResponse, error) { - stacks, err := Client(ctx).ComposeService().List(ctx) + stacks, err := Client(ctx).ComposeService().List(ctx, compose.ListOptions{All: request.All}) if err != nil { return nil, err } diff --git a/ecs/list.go b/ecs/list.go index e54e780c8..7af738da1 100644 --- a/ecs/list.go +++ b/ecs/list.go @@ -23,7 +23,7 @@ import ( "github.com/docker/compose-cli/api/compose" ) -func (b *ecsAPIService) List(ctx context.Context) ([]compose.Stack, error) { +func (b *ecsAPIService) List(ctx context.Context, opts compose.ListOptions) ([]compose.Stack, error) { stacks, err := b.aws.ListStacks(ctx) if err != nil { return nil, err diff --git a/ecs/local/compose.go b/ecs/local/compose.go index 9600a3362..6ecce3e71 100644 --- a/ecs/local/compose.go +++ b/ecs/local/compose.go @@ -169,8 +169,8 @@ func (e ecsLocalSimulation) Logs(ctx context.Context, projectName string, consum func (e ecsLocalSimulation) Ps(ctx context.Context, projectName string, options compose.PsOptions) ([]compose.ContainerSummary, error) { return e.compose.Ps(ctx, projectName, options) } -func (e ecsLocalSimulation) List(ctx context.Context) ([]compose.Stack, error) { - return e.compose.List(ctx) +func (e ecsLocalSimulation) List(ctx context.Context, opts compose.ListOptions) ([]compose.Stack, error) { + return e.compose.List(ctx, opts) } func (e ecsLocalSimulation) RunOneOffContainer(ctx context.Context, project *types.Project, opts compose.RunOptions) (int, error) { return 0, errors.Wrap(errdefs.ErrNotImplemented, "use docker-compose run") diff --git a/kube/compose.go b/kube/compose.go index ae83da300..230914a6a 100644 --- a/kube/compose.go +++ b/kube/compose.go @@ -119,7 +119,7 @@ func (s *composeService) Down(ctx context.Context, projectName string, options c } // List executes the equivalent to a `docker stack ls` -func (s *composeService) List(ctx context.Context) ([]compose.Stack, error) { +func (s *composeService) List(ctx context.Context, opts compose.ListOptions) ([]compose.Stack, error) { return s.sdk.ListReleases() } diff --git a/local/compose/ls.go b/local/compose/ls.go index 2df407533..64a4eb6fc 100644 --- a/local/compose/ls.go +++ b/local/compose/ls.go @@ -27,9 +27,10 @@ import ( "github.com/docker/docker/api/types/filters" ) -func (s *composeService) List(ctx context.Context) ([]compose.Stack, error) { +func (s *composeService) List(ctx context.Context, opts compose.ListOptions) ([]compose.Stack, error) { list, err := s.apiClient.ContainerList(ctx, moby.ContainerListOptions{ Filters: filters.NewArgs(hasProjectLabelFilter()), + All: opts.All, }) if err != nil { return nil, err diff --git a/local/e2e/compose/fixtures/start-stop/compose.yml b/local/e2e/compose/fixtures/start-stop/compose.yml new file mode 100644 index 000000000..7ee4c1575 --- /dev/null +++ b/local/e2e/compose/fixtures/start-stop/compose.yml @@ -0,0 +1,5 @@ +services: + simple: + image: nginx + another: + image: nginx diff --git a/local/e2e/compose/start_stop_test.go b/local/e2e/compose/start_stop_test.go new file mode 100644 index 000000000..194288a03 --- /dev/null +++ b/local/e2e/compose/start_stop_test.go @@ -0,0 +1,102 @@ +/* + Copyright 2020 Docker Compose CLI authors + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +package e2e + +import ( + "fmt" + "strings" + "testing" + + testify "github.com/stretchr/testify/assert" + "gotest.tools/v3/assert" + + . "github.com/docker/compose-cli/utils/e2e" +) + +func TestStartStop(t *testing.T) { + c := NewParallelE2eCLI(t, binDir) + const projectName = "e2e-start-stop" + + getProjectRegx := func(status string) string { + // match output with random spaces like: + // e2e-start-stop running(3) + return fmt.Sprintf("%s\\s+%s\\(%d\\)", projectName, status, 2) + } + + getServiceRegx := func(service string, status string) string { + // match output with random spaces like: + // e2e-start-stop_db_1 db running + return fmt.Sprintf("%s_%s_1\\s+%s\\s+%s", projectName, service, service, status) + } + + t.Run("Up a project", func(t *testing.T) { + res := c.RunDockerOrExitError("compose", "-f", "./fixtures/start-stop/compose.yml", "--project-name", projectName, "up", "-d") + assert.Assert(t, strings.Contains("Container e2e-start-stop_simple_1 Started", res.Stdout()), res.Stdout()) + + res = c.RunDockerOrExitError("compose", "ls", "--all") + testify.Regexp(t, getProjectRegx("running"), res.Stdout()) + + res = c.RunDockerOrExitError("compose", "--project-name", projectName, "ps") + testify.Regexp(t, getServiceRegx("simple", "running"), res.Stdout()) + testify.Regexp(t, getServiceRegx("another", "running"), res.Stdout()) + }) + + t.Run("stop project", func(t *testing.T) { + c.RunDockerOrExitError("compose", "-f", "./fixtures/start-stop/compose.yml", "--project-name", projectName, "stop") + + res := c.RunDockerOrExitError("compose", "ls") + assert.Assert(t, !strings.Contains("e2e-start-stop", res.Combined()), res.Combined()) + + res = c.RunDockerOrExitError("compose", "ls", "--all") + testify.Regexp(t, getProjectRegx("exited"), res.Stdout()) + + res = c.RunDockerOrExitError("compose", "--project-name", projectName, "ps") + assert.Assert(t, !strings.Contains("e2e-start-stop_words_1", res.Combined()), res.Combined()) + + res = c.RunDockerOrExitError("compose", "--project-name", projectName, "ps", "--all") + testify.Regexp(t, getServiceRegx("simple", "exited"), res.Stdout()) + testify.Regexp(t, getServiceRegx("another", "exited"), res.Stdout()) + }) + + t.Run("start project", func(t *testing.T) { + c.RunDockerOrExitError("compose", "-f", "./fixtures/start-stop/compose.yml", "--project-name", projectName, "start") + + res := c.RunDockerOrExitError("compose", "ls") + testify.Regexp(t, getProjectRegx("running"), res.Stdout()) + }) + + t.Run("pause project", func(t *testing.T) { + c.RunDockerOrExitError("compose", "-f", "./fixtures/start-stop/compose.yml", "--project-name", projectName, "pause") + + res := c.RunDockerOrExitError("compose", "ls") + assert.Assert(t, !strings.Contains("e2e-start-stop", res.Combined()), res.Combined()) + + res = c.RunDockerOrExitError("compose", "ls", "--all") + testify.Regexp(t, getProjectRegx("paused"), res.Stdout()) + }) + + t.Run("unpause project", func(t *testing.T) { + c.RunDockerOrExitError("compose", "-f", "./fixtures/start-stop/compose.yml", "--project-name", projectName, "unpause") + + res := c.RunDockerOrExitError("compose", "ls") + testify.Regexp(t, getProjectRegx("running"), res.Stdout()) + }) + + t.Run("down", func(t *testing.T) { + _ = c.RunDockerCmd("compose", "--project-name", projectName, "down") + }) +}