mirror of https://github.com/docker/compose.git
only (re)start selected services
Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
This commit is contained in:
parent
dbd936b704
commit
c76dd110c7
|
@ -122,6 +122,8 @@ type StartOptions struct {
|
||||||
type RestartOptions struct {
|
type RestartOptions struct {
|
||||||
// Timeout override container restart timeout
|
// Timeout override container restart timeout
|
||||||
Timeout *time.Duration
|
Timeout *time.Duration
|
||||||
|
// Services passed in the command line to be restarted
|
||||||
|
Services []string
|
||||||
}
|
}
|
||||||
|
|
||||||
// StopOptions group options of the Stop API
|
// StopOptions group options of the Stop API
|
||||||
|
|
|
@ -57,7 +57,8 @@ func runRestart(ctx context.Context, backend compose.Service, opts restartOption
|
||||||
timeout := time.Duration(opts.timeout) * time.Second
|
timeout := time.Duration(opts.timeout) * time.Second
|
||||||
_, err = progress.Run(ctx, func(ctx context.Context) (string, error) {
|
_, err = progress.Run(ctx, func(ctx context.Context) (string, error) {
|
||||||
return "", backend.Restart(ctx, project, compose.RestartOptions{
|
return "", backend.Restart(ctx, project, compose.RestartOptions{
|
||||||
Timeout: &timeout,
|
Timeout: &timeout,
|
||||||
|
Services: services,
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
return err
|
return err
|
||||||
|
|
|
@ -20,6 +20,7 @@ import (
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
"github.com/docker/compose-cli/api/compose"
|
"github.com/docker/compose-cli/api/compose"
|
||||||
|
"github.com/docker/compose-cli/utils"
|
||||||
|
|
||||||
"github.com/compose-spec/compose-go/types"
|
"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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if len(options.Services) == 0 {
|
||||||
|
options.Services = project.ServiceNames()
|
||||||
|
}
|
||||||
|
|
||||||
err = InDependencyOrder(ctx, project, func(c context.Context, service types.ServiceConfig) error {
|
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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
|
@ -20,6 +20,7 @@ import (
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
"github.com/docker/compose-cli/api/compose"
|
"github.com/docker/compose-cli/api/compose"
|
||||||
|
"github.com/docker/compose-cli/utils"
|
||||||
|
|
||||||
"github.com/compose-spec/compose-go/types"
|
"github.com/compose-spec/compose-go/types"
|
||||||
moby "github.com/docker/docker/api/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 {
|
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
|
var containers Containers
|
||||||
if options.Attach != nil {
|
if options.Attach != nil {
|
||||||
c, err := s.attach(ctx, project, options.Attach, options.Services)
|
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 {
|
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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
Loading…
Reference in New Issue