Merge pull request #1577 from ndeloof/stop_services

only stop/remove selected services
This commit is contained in:
Nicolas De loof 2021-04-20 21:05:03 +02:00 committed by GitHub
commit 510ffc10a5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 24 additions and 6 deletions

View File

@ -126,6 +126,8 @@ type RestartOptions struct {
type StopOptions struct {
// Timeout override container stop timeout
Timeout *time.Duration
// Services passed in the command line to be stopped
Services []string
}
// UpOptions group options of the Up API
@ -187,6 +189,8 @@ type RemoveOptions struct {
Volumes bool
// Force don't ask to confirm removal
Force bool
// Services passed in the command line to be removed
Services []string
}
// RunOptions group options of the Run API

View File

@ -32,7 +32,7 @@ import (
"github.com/docker/compose-cli/utils"
"github.com/docker/docker/pkg/stringid"
units "github.com/docker/go-units"
"github.com/docker/go-units"
)
type imageOptions struct {

View File

@ -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 {
@ -82,7 +84,8 @@ func runRemove(ctx context.Context, opts removeOptions, services []string) error
}
reosurces, err := c.ComposeService().Remove(ctx, project, compose.RemoveOptions{
DryRun: true,
DryRun: true,
Services: services,
})
if err != nil {
return err

View File

@ -69,7 +69,8 @@ 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,
Timeout: timeout,
Services: services,
})
})
return err

View File

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

View File

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