Преглед изворни кода

Merge pull request #1693 from docker/restart_services

Nicolas De loof пре 4 година
родитељ
комит
24e63e8675
4 измењених фајлова са 23 додато и 3 уклоњено
  1. 2 0
      api/compose/api.go
  2. 2 1
      cli/cmd/compose/restart.go
  3. 10 1
      local/compose/restart.go
  4. 9 1
      local/compose/start.go

+ 2 - 0
api/compose/api.go

@@ -122,6 +122,8 @@ type StartOptions struct {
 type RestartOptions struct {
 	// Timeout override container restart timeout
 	Timeout *time.Duration
+	// Services passed in the command line to be restarted
+	Services []string
 }
 
 // StopOptions group options of the Stop API

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

@@ -57,7 +57,8 @@ func runRestart(ctx context.Context, backend compose.Service, opts restartOption
 	timeout := time.Duration(opts.timeout) * time.Second
 	_, err = progress.Run(ctx, func(ctx context.Context) (string, error) {
 		return "", backend.Restart(ctx, project, compose.RestartOptions{
-			Timeout: &timeout,
+			Timeout:  &timeout,
+			Services: services,
 		})
 	})
 	return err

+ 10 - 1
local/compose/restart.go

@@ -20,6 +20,7 @@ import (
 	"context"
 
 	"github.com/docker/compose-cli/api/compose"
+	"github.com/docker/compose-cli/utils"
 
 	"github.com/compose-spec/compose-go/types"
 )
@@ -29,8 +30,16 @@ func (s *composeService) Restart(ctx context.Context, project *types.Project, op
 	if err != nil {
 		return err
 	}
+
+	if len(options.Services) == 0 {
+		options.Services = project.ServiceNames()
+	}
+
 	err = InDependencyOrder(ctx, project, func(c context.Context, service types.ServiceConfig) error {
-		return s.restartService(ctx, service.Name, options.Timeout)
+		if utils.StringContains(options.Services, service.Name) {
+			return s.restartService(ctx, service.Name, options.Timeout)
+		}
+		return nil
 	})
 	if err != nil {
 		return err

+ 9 - 1
local/compose/start.go

@@ -20,6 +20,7 @@ import (
 	"context"
 
 	"github.com/docker/compose-cli/api/compose"
+	"github.com/docker/compose-cli/utils"
 
 	"github.com/compose-spec/compose-go/types"
 	moby "github.com/docker/docker/api/types"
@@ -28,6 +29,10 @@ import (
 )
 
 func (s *composeService) Start(ctx context.Context, project *types.Project, options compose.StartOptions) error {
+	if len(options.Services) == 0 {
+		options.Services = project.ServiceNames()
+	}
+
 	var containers Containers
 	if options.Attach != nil {
 		c, err := s.attach(ctx, project, options.Attach, options.Services)
@@ -38,7 +43,10 @@ func (s *composeService) Start(ctx context.Context, project *types.Project, opti
 	}
 
 	err := InDependencyOrder(ctx, project, func(c context.Context, service types.ServiceConfig) error {
-		return s.startService(ctx, project, service)
+		if utils.StringContains(options.Services, service.Name) {
+			return s.startService(ctx, project, service)
+		}
+		return nil
 	})
 	if err != nil {
 		return err