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

Commit

Permalink
only stop/remove selected services
Browse files Browse the repository at this point in the history
Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
  • Loading branch information
ndeloof committed Apr 20, 2021
1 parent d866491 commit 0914f12
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 5 deletions.
8 changes: 6 additions & 2 deletions api/compose/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,9 @@ type RestartOptions struct {
// StopOptions group options of the Stop API
type StopOptions struct {
// Timeout override container stop timeout
Timeout *time.Duration
Timeout *time.Duration
// Services passed in the command line to be stopped
Services []string
}

// UpOptions group options of the Up API
Expand Down Expand Up @@ -186,7 +188,9 @@ type RemoveOptions struct {
// Volumes remove anonymous volumes
Volumes bool
// Force don't ask to confirm removal
Force bool
Force bool
// Services passed in the command line to be removed
Services []string
}

// RunOptions group options of the Run API
Expand Down
5 changes: 4 additions & 1 deletion cli/cmd/compose/remove.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -83,6 +85,7 @@ func runRemove(ctx context.Context, opts removeOptions, services []string) error

reosurces, err := c.ComposeService().Remove(ctx, project, compose.RemoveOptions{
DryRun: true,
Services: services,
})
if err != nil {
return err
Expand Down
1 change: 1 addition & 0 deletions cli/cmd/compose/stop.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ 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,
Services: services,
})
})
return err
Expand Down
7 changes: 6 additions & 1 deletion local/compose/remove.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
7 changes: 6 additions & 1 deletion local/compose/stop.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit 0914f12

Please sign in to comment.