only (re)start selected services

Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
This commit is contained in:
Nicolas De Loof 2021-05-20 08:09:14 +02:00
parent dbd936b704
commit c76dd110c7
No known key found for this signature in database
GPG Key ID: 9858809D6F8F6E7E
4 changed files with 23 additions and 3 deletions

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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