浏览代码

only stop/remove selected services

Signed-off-by: Nicolas De Loof <[email protected]>
Nicolas De Loof 4 年之前
父节点
当前提交
5cead2266d
共有 6 个文件被更改,包括 24 次插入6 次删除
  1. 4 0
      api/compose/api.go
  2. 1 1
      cli/cmd/compose/images.go
  3. 5 2
      cli/cmd/compose/remove.go
  4. 2 1
      cli/cmd/compose/stop.go
  5. 6 1
      local/compose/remove.go
  6. 6 1
      local/compose/stop.go

+ 4 - 0
api/compose/api.go

@@ -126,6 +126,8 @@ type RestartOptions struct {
 type StopOptions struct {
 	// Timeout override container stop timeout
 	Timeout *time.Duration
+	// Services passed in the command line to be stopped
+	Services []string
 }
 
 // UpOptions group options of the Up API
@@ -187,6 +189,8 @@ type RemoveOptions struct {
 	Volumes bool
 	// Force don't ask to confirm removal
 	Force bool
+	// Services passed in the command line to be removed
+	Services []string
 }
 
 // RunOptions group options of the Run API

+ 1 - 1
cli/cmd/compose/images.go

@@ -32,7 +32,7 @@ import (
 	"github.com/docker/compose-cli/utils"
 	"github.com/docker/docker/pkg/stringid"
 
-	units "github.com/docker/go-units"
+	"github.com/docker/go-units"
 )
 
 type imageOptions struct {

+ 5 - 2
cli/cmd/compose/remove.go

@@ -73,7 +73,9 @@ func runRemove(ctx context.Context, opts removeOptions, services []string) error
 
 	if opts.stop {
 		_, err = progress.Run(ctx, func(ctx context.Context) (string, error) {
-			err := c.ComposeService().Stop(ctx, project, compose.StopOptions{})
+			err := c.ComposeService().Stop(ctx, project, compose.StopOptions{
+				Services: services,
+			})
 			return "", err
 		})
 		if err != nil {
@@ -82,7 +84,8 @@ func runRemove(ctx context.Context, opts removeOptions, services []string) error
 	}
 
 	reosurces, err := c.ComposeService().Remove(ctx, project, compose.RemoveOptions{
-		DryRun: true,
+		DryRun:   true,
+		Services: services,
 	})
 	if err != nil {
 		return err

+ 2 - 1
cli/cmd/compose/stop.go

@@ -69,7 +69,8 @@ func runStop(ctx context.Context, opts stopOptions, services []string) error {
 	}
 	_, err = progress.Run(ctx, func(ctx context.Context) (string, error) {
 		return "", c.ComposeService().Stop(ctx, project, compose.StopOptions{
-			Timeout: timeout,
+			Timeout:  timeout,
+			Services: services,
 		})
 	})
 	return err

+ 6 - 1
local/compose/remove.go

@@ -29,7 +29,12 @@ import (
 )
 
 func (s *composeService) Remove(ctx context.Context, project *types.Project, options compose.RemoveOptions) ([]string, error) {
-	containers, err := s.getContainers(ctx, project.Name, oneOffInclude, true)
+	services := options.Services
+	if len(services) == 0 {
+		services = project.ServiceNames()
+	}
+
+	containers, err := s.getContainers(ctx, project.Name, oneOffInclude, true, services...)
 	if err != nil {
 		return nil, err
 	}

+ 6 - 1
local/compose/stop.go

@@ -27,8 +27,13 @@ import (
 
 func (s *composeService) Stop(ctx context.Context, project *types.Project, options compose.StopOptions) error {
 	w := progress.ContextWriter(ctx)
+
+	services := options.Services
+	if len(services) == 0 {
+		services = project.ServiceNames()
+	}
 	var containers Containers
-	containers, err := s.getContainers(ctx, project.Name, oneOffInclude, true, project.ServiceNames()...)
+	containers, err := s.getContainers(ctx, project.Name, oneOffInclude, true, services...)
 	if err != nil {
 		return err
 	}