Skip to content
This repository was archived by the owner on Nov 27, 2023. It is now read-only.

Commit c76dd11

Browse files
committed
only (re)start selected services
Signed-off-by: Nicolas De Loof <[email protected]>
1 parent dbd936b commit c76dd11

File tree

4 files changed

+23
-3
lines changed

4 files changed

+23
-3
lines changed

api/compose/api.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,8 @@ type StartOptions struct {
122122
type RestartOptions struct {
123123
// Timeout override container restart timeout
124124
Timeout *time.Duration
125+
// Services passed in the command line to be restarted
126+
Services []string
125127
}
126128

127129
// StopOptions group options of the Stop API

cli/cmd/compose/restart.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ func runRestart(ctx context.Context, backend compose.Service, opts restartOption
5757
timeout := time.Duration(opts.timeout) * time.Second
5858
_, err = progress.Run(ctx, func(ctx context.Context) (string, error) {
5959
return "", backend.Restart(ctx, project, compose.RestartOptions{
60-
Timeout: &timeout,
60+
Timeout: &timeout,
61+
Services: services,
6162
})
6263
})
6364
return err

local/compose/restart.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"context"
2121

2222
"github.com/docker/compose-cli/api/compose"
23+
"github.com/docker/compose-cli/utils"
2324

2425
"github.com/compose-spec/compose-go/types"
2526
)
@@ -29,8 +30,16 @@ func (s *composeService) Restart(ctx context.Context, project *types.Project, op
2930
if err != nil {
3031
return err
3132
}
33+
34+
if len(options.Services) == 0 {
35+
options.Services = project.ServiceNames()
36+
}
37+
3238
err = InDependencyOrder(ctx, project, func(c context.Context, service types.ServiceConfig) error {
33-
return s.restartService(ctx, service.Name, options.Timeout)
39+
if utils.StringContains(options.Services, service.Name) {
40+
return s.restartService(ctx, service.Name, options.Timeout)
41+
}
42+
return nil
3443
})
3544
if err != nil {
3645
return err

local/compose/start.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"context"
2121

2222
"github.com/docker/compose-cli/api/compose"
23+
"github.com/docker/compose-cli/utils"
2324

2425
"github.com/compose-spec/compose-go/types"
2526
moby "github.com/docker/docker/api/types"
@@ -28,6 +29,10 @@ import (
2829
)
2930

3031
func (s *composeService) Start(ctx context.Context, project *types.Project, options compose.StartOptions) error {
32+
if len(options.Services) == 0 {
33+
options.Services = project.ServiceNames()
34+
}
35+
3136
var containers Containers
3237
if options.Attach != nil {
3338
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
3843
}
3944

4045
err := InDependencyOrder(ctx, project, func(c context.Context, service types.ServiceConfig) error {
41-
return s.startService(ctx, project, service)
46+
if utils.StringContains(options.Services, service.Name) {
47+
return s.startService(ctx, project, service)
48+
}
49+
return nil
4250
})
4351
if err != nil {
4452
return err

0 commit comments

Comments
 (0)