зеркало из https://github.com/docker/compose-cli.git
pause/unpause only need project name. use getContainers where possible
Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
This commit is contained in:
Родитель
80c82415d9
Коммит
7d85485242
|
@ -72,11 +72,11 @@ func (cs *aciComposeService) Stop(ctx context.Context, project *types.Project, o
|
|||
return errdefs.ErrNotImplemented
|
||||
}
|
||||
|
||||
func (cs *aciComposeService) Pause(ctx context.Context, project *types.Project) error {
|
||||
func (cs *aciComposeService) Pause(ctx context.Context, project string, options compose.PauseOptions) error {
|
||||
return errdefs.ErrNotImplemented
|
||||
}
|
||||
|
||||
func (cs *aciComposeService) UnPause(ctx context.Context, project *types.Project) error {
|
||||
func (cs *aciComposeService) UnPause(ctx context.Context, project string, options compose.PauseOptions) error {
|
||||
return errdefs.ErrNotImplemented
|
||||
}
|
||||
|
||||
|
|
|
@ -96,11 +96,11 @@ func (c *composeService) Exec(ctx context.Context, project *types.Project, opts
|
|||
return errdefs.ErrNotImplemented
|
||||
}
|
||||
|
||||
func (c *composeService) Pause(ctx context.Context, project *types.Project) error {
|
||||
func (c *composeService) Pause(ctx context.Context, project string, options compose.PauseOptions) error {
|
||||
return errdefs.ErrNotImplemented
|
||||
}
|
||||
|
||||
func (c *composeService) UnPause(ctx context.Context, project *types.Project) error {
|
||||
func (c *composeService) UnPause(ctx context.Context, project string, options compose.PauseOptions) error {
|
||||
return errdefs.ErrNotImplemented
|
||||
}
|
||||
|
||||
|
|
|
@ -63,9 +63,9 @@ type Service interface {
|
|||
// Exec executes a command in a running service container
|
||||
Exec(ctx context.Context, project *types.Project, opts RunOptions) error
|
||||
// Pause executes the equivalent to a `compose pause`
|
||||
Pause(ctx context.Context, project *types.Project) error
|
||||
Pause(ctx context.Context, project string, options PauseOptions) error
|
||||
// UnPause executes the equivalent to a `compose unpause`
|
||||
UnPause(ctx context.Context, project *types.Project) error
|
||||
UnPause(ctx context.Context, project string, options PauseOptions) error
|
||||
// Top executes the equivalent to a `compose top`
|
||||
Top(ctx context.Context, projectName string, services []string) ([]ContainerProcSummary, error)
|
||||
// Events executes the equivalent to a `compose events`
|
||||
|
@ -303,6 +303,12 @@ type LogOptions struct {
|
|||
Timestamps bool
|
||||
}
|
||||
|
||||
// PauseOptions group options of the Pause API
|
||||
type PauseOptions struct {
|
||||
// Services passed in the command line to be started
|
||||
Services []string
|
||||
}
|
||||
|
||||
const (
|
||||
// STARTING indicates that stack is being deployed
|
||||
STARTING string = "Starting"
|
||||
|
|
|
@ -22,6 +22,7 @@ import (
|
|||
"github.com/spf13/cobra"
|
||||
|
||||
"github.com/docker/compose-cli/api/client"
|
||||
"github.com/docker/compose-cli/api/compose"
|
||||
"github.com/docker/compose-cli/api/progress"
|
||||
)
|
||||
|
||||
|
@ -49,13 +50,15 @@ func runPause(ctx context.Context, opts pauseOptions, services []string) error {
|
|||
return err
|
||||
}
|
||||
|
||||
project, err := opts.toProject(services)
|
||||
project, err := opts.toProjectName()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
_, err = progress.Run(ctx, func(ctx context.Context) (string, error) {
|
||||
return "", c.ComposeService().Pause(ctx, project)
|
||||
return "", c.ComposeService().Pause(ctx, project, compose.PauseOptions{
|
||||
Services: services,
|
||||
})
|
||||
})
|
||||
return err
|
||||
}
|
||||
|
@ -84,13 +87,15 @@ func runUnPause(ctx context.Context, opts unpauseOptions, services []string) err
|
|||
return err
|
||||
}
|
||||
|
||||
project, err := opts.toProject(services)
|
||||
project, err := opts.toProjectName()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
_, err = progress.Run(ctx, func(ctx context.Context) (string, error) {
|
||||
return "", c.ComposeService().UnPause(ctx, project)
|
||||
return "", c.ComposeService().UnPause(ctx, project, compose.PauseOptions{
|
||||
Services: services,
|
||||
})
|
||||
})
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -188,12 +188,12 @@ func (e ecsLocalSimulation) Exec(ctx context.Context, project *types.Project, op
|
|||
return errdefs.ErrNotImplemented
|
||||
}
|
||||
|
||||
func (e ecsLocalSimulation) Pause(ctx context.Context, project *types.Project) error {
|
||||
return e.compose.Pause(ctx, project)
|
||||
func (e ecsLocalSimulation) Pause(ctx context.Context, project string, options compose.PauseOptions) error {
|
||||
return e.compose.Pause(ctx, project, options)
|
||||
}
|
||||
|
||||
func (e ecsLocalSimulation) UnPause(ctx context.Context, project *types.Project) error {
|
||||
return e.compose.UnPause(ctx, project)
|
||||
func (e ecsLocalSimulation) UnPause(ctx context.Context, project string, options compose.PauseOptions) error {
|
||||
return e.compose.UnPause(ctx, project, options)
|
||||
}
|
||||
|
||||
func (e ecsLocalSimulation) Top(ctx context.Context, projectName string, services []string) ([]compose.ContainerProcSummary, error) {
|
||||
|
|
|
@ -59,11 +59,11 @@ func (b *ecsAPIService) Stop(ctx context.Context, project *types.Project, option
|
|||
return errdefs.ErrNotImplemented
|
||||
}
|
||||
|
||||
func (b *ecsAPIService) Pause(ctx context.Context, project *types.Project) error {
|
||||
func (b *ecsAPIService) Pause(ctx context.Context, project string, options compose.PauseOptions) error {
|
||||
return errdefs.ErrNotImplemented
|
||||
}
|
||||
|
||||
func (b *ecsAPIService) UnPause(ctx context.Context, project *types.Project) error {
|
||||
func (b *ecsAPIService) UnPause(ctx context.Context, project string, options compose.PauseOptions) error {
|
||||
return errdefs.ErrNotImplemented
|
||||
}
|
||||
|
||||
|
|
|
@ -252,11 +252,11 @@ func (s *composeService) Exec(ctx context.Context, project *types.Project, opts
|
|||
return errdefs.ErrNotImplemented
|
||||
}
|
||||
|
||||
func (s *composeService) Pause(ctx context.Context, project *types.Project) error {
|
||||
func (s *composeService) Pause(ctx context.Context, project string, options compose.PauseOptions) error {
|
||||
return errdefs.ErrNotImplemented
|
||||
}
|
||||
|
||||
func (s *composeService) UnPause(ctx context.Context, project *types.Project) error {
|
||||
func (s *composeService) UnPause(ctx context.Context, project string, options compose.PauseOptions) error {
|
||||
return errdefs.ErrNotImplemented
|
||||
}
|
||||
|
||||
|
|
|
@ -33,7 +33,7 @@ import (
|
|||
)
|
||||
|
||||
func (s *composeService) attach(ctx context.Context, project *types.Project, listener compose.ContainerEventListener, selectedServices []string) (Containers, error) {
|
||||
containers, err := s.getContainers(ctx, project, oneOffExclude, selectedServices)
|
||||
containers, err := s.getContainers(ctx, project.Name, oneOffExclude, true, selectedServices...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
@ -21,7 +21,6 @@ import (
|
|||
"fmt"
|
||||
"sort"
|
||||
|
||||
"github.com/compose-spec/compose-go/types"
|
||||
moby "github.com/docker/docker/api/types"
|
||||
"github.com/docker/docker/api/types/filters"
|
||||
|
||||
|
@ -39,10 +38,10 @@ const (
|
|||
oneOffOnly
|
||||
)
|
||||
|
||||
func (s *composeService) getContainers(ctx context.Context, project *types.Project, oneOff oneOff, selectedServices []string) (Containers, error) {
|
||||
func (s *composeService) getContainers(ctx context.Context, project string, oneOff oneOff, stopped bool, selectedServices ...string) (Containers, error) {
|
||||
var containers Containers
|
||||
f := filters.NewArgs(
|
||||
projectFilter(project.Name),
|
||||
projectFilter(project),
|
||||
)
|
||||
switch oneOff {
|
||||
case oneOffOnly:
|
||||
|
@ -53,15 +52,14 @@ func (s *composeService) getContainers(ctx context.Context, project *types.Proje
|
|||
}
|
||||
containers, err := s.apiClient.ContainerList(ctx, moby.ContainerListOptions{
|
||||
Filters: f,
|
||||
All: true,
|
||||
All: stopped,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(selectedServices) == 0 {
|
||||
selectedServices = project.ServiceNames()
|
||||
if len(selectedServices) > 0 {
|
||||
containers = containers.filter(isService(selectedServices...))
|
||||
}
|
||||
containers = containers.filter(isService(selectedServices...))
|
||||
return containers, nil
|
||||
}
|
||||
|
||||
|
|
|
@ -26,7 +26,6 @@ import (
|
|||
"github.com/compose-spec/compose-go/types"
|
||||
moby "github.com/docker/docker/api/types"
|
||||
"github.com/docker/docker/api/types/container"
|
||||
"github.com/docker/docker/api/types/filters"
|
||||
"github.com/docker/docker/api/types/mount"
|
||||
"github.com/docker/docker/api/types/network"
|
||||
"github.com/docker/docker/api/types/strslice"
|
||||
|
@ -69,10 +68,7 @@ func (s *composeService) Create(ctx context.Context, project *types.Project, opt
|
|||
}
|
||||
|
||||
var observedState Containers
|
||||
observedState, err = s.apiClient.ContainerList(ctx, moby.ContainerListOptions{
|
||||
Filters: filters.NewArgs(projectFilter(project.Name)),
|
||||
All: true,
|
||||
})
|
||||
observedState, err = s.getContainers(ctx, project.Name, oneOffInclude, true)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -39,10 +39,7 @@ func (s *composeService) Down(ctx context.Context, projectName string, options c
|
|||
resourceToRemove := false
|
||||
|
||||
var containers Containers
|
||||
containers, err := s.apiClient.ContainerList(ctx, moby.ContainerListOptions{
|
||||
Filters: filters.NewArgs(projectFilter(projectName)),
|
||||
All: true,
|
||||
})
|
||||
containers, err := s.getContainers(ctx, projectName, oneOffInclude, true)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -21,7 +21,6 @@ import (
|
|||
|
||||
"github.com/compose-spec/compose-go/types"
|
||||
moby "github.com/docker/docker/api/types"
|
||||
"github.com/docker/docker/api/types/filters"
|
||||
"golang.org/x/sync/errgroup"
|
||||
|
||||
"github.com/docker/compose-cli/api/compose"
|
||||
|
@ -32,10 +31,7 @@ func (s *composeService) Kill(ctx context.Context, project *types.Project, optio
|
|||
w := progress.ContextWriter(ctx)
|
||||
|
||||
var containers Containers
|
||||
containers, err := s.apiClient.ContainerList(ctx, moby.ContainerListOptions{
|
||||
Filters: filters.NewArgs(projectFilter(project.Name)),
|
||||
All: true,
|
||||
})
|
||||
containers, err := s.getContainers(ctx, project.Name, oneOffInclude, true)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -18,8 +18,6 @@ package compose
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/docker/docker/api/types/filters"
|
||||
|
||||
|
@ -47,10 +45,6 @@ func projectFilter(projectName string) filters.KeyValuePair {
|
|||
return filters.Arg("label", fmt.Sprintf("%s=%s", projectLabel, projectName))
|
||||
}
|
||||
|
||||
func oneOffFilter(oneOff bool) filters.KeyValuePair {
|
||||
return filters.Arg("label", fmt.Sprintf("%s=%s", oneoffLabel, strings.Title(strconv.FormatBool(oneOff))))
|
||||
}
|
||||
|
||||
func serviceFilter(serviceName string) filters.KeyValuePair {
|
||||
return filters.Arg("label", fmt.Sprintf("%s=%s", serviceLabel, serviceName))
|
||||
}
|
||||
|
|
|
@ -24,28 +24,12 @@ import (
|
|||
"github.com/docker/compose-cli/utils"
|
||||
|
||||
"github.com/docker/docker/api/types"
|
||||
"github.com/docker/docker/api/types/filters"
|
||||
"github.com/docker/docker/pkg/stdcopy"
|
||||
"golang.org/x/sync/errgroup"
|
||||
)
|
||||
|
||||
func (s *composeService) Logs(ctx context.Context, projectName string, consumer compose.LogConsumer, options compose.LogOptions) error {
|
||||
list, err := s.apiClient.ContainerList(ctx, types.ContainerListOptions{
|
||||
Filters: filters.NewArgs(
|
||||
projectFilter(projectName),
|
||||
oneOffFilter(false),
|
||||
),
|
||||
All: true,
|
||||
})
|
||||
|
||||
ignore := func(string) bool {
|
||||
return false
|
||||
}
|
||||
if len(options.Services) > 0 {
|
||||
ignore = func(s string) bool {
|
||||
return !utils.StringContains(options.Services, s)
|
||||
}
|
||||
}
|
||||
list, err := s.getContainers(ctx, projectName, oneOffExclude, true, options.Services...)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -54,9 +38,6 @@ func (s *composeService) Logs(ctx context.Context, projectName string, consumer
|
|||
for _, c := range list {
|
||||
c := c
|
||||
service := c.Labels[serviceLabel]
|
||||
if ignore(service) {
|
||||
continue
|
||||
}
|
||||
container, err := s.apiClient.ContainerInspect(ctx, c.ID)
|
||||
if err != nil {
|
||||
return err
|
||||
|
|
|
@ -19,15 +19,15 @@ package compose
|
|||
import (
|
||||
"context"
|
||||
|
||||
"github.com/compose-spec/compose-go/types"
|
||||
moby "github.com/docker/docker/api/types"
|
||||
"golang.org/x/sync/errgroup"
|
||||
|
||||
"github.com/docker/compose-cli/api/compose"
|
||||
"github.com/docker/compose-cli/api/progress"
|
||||
)
|
||||
|
||||
func (s *composeService) Pause(ctx context.Context, project *types.Project) error {
|
||||
containers, err := s.getContainers(ctx, project, oneOffExclude, nil)
|
||||
func (s *composeService) Pause(ctx context.Context, project string, options compose.PauseOptions) error {
|
||||
containers, err := s.getContainers(ctx, project, oneOffExclude, true, options.Services...)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -48,8 +48,8 @@ func (s *composeService) Pause(ctx context.Context, project *types.Project) erro
|
|||
return eg.Wait()
|
||||
}
|
||||
|
||||
func (s *composeService) UnPause(ctx context.Context, project *types.Project) error {
|
||||
containers, err := s.getContainers(ctx, project, oneOffExclude, nil)
|
||||
func (s *composeService) UnPause(ctx context.Context, project string, options compose.PauseOptions) error {
|
||||
containers, err := s.getContainers(ctx, project, oneOffExclude, true, options.Services...)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -20,18 +20,13 @@ import (
|
|||
"context"
|
||||
"fmt"
|
||||
|
||||
moby "github.com/docker/docker/api/types"
|
||||
"github.com/docker/docker/api/types/filters"
|
||||
"golang.org/x/sync/errgroup"
|
||||
|
||||
"github.com/docker/compose-cli/api/compose"
|
||||
)
|
||||
|
||||
func (s *composeService) Ps(ctx context.Context, projectName string, options compose.PsOptions) ([]compose.ContainerSummary, error) {
|
||||
containers, err := s.apiClient.ContainerList(ctx, moby.ContainerListOptions{
|
||||
Filters: filters.NewArgs(projectFilter(projectName)),
|
||||
All: options.All,
|
||||
})
|
||||
containers, err := s.getContainers(ctx, projectName, oneOffInclude, options.All)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
@ -29,7 +29,7 @@ import (
|
|||
)
|
||||
|
||||
func (s *composeService) Remove(ctx context.Context, project *types.Project, options compose.RemoveOptions) ([]string, error) {
|
||||
containers, err := s.getContainers(ctx, project, oneOffInclude, nil)
|
||||
containers, err := s.getContainers(ctx, project.Name, oneOffInclude, true)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
@ -30,10 +30,7 @@ import (
|
|||
)
|
||||
|
||||
func (s *composeService) RunOneOffContainer(ctx context.Context, project *types.Project, opts compose.RunOptions) (int, error) {
|
||||
observedState, err := s.apiClient.ContainerList(ctx, apitypes.ContainerListOptions{
|
||||
Filters: filters.NewArgs(projectFilter(project.Name)),
|
||||
All: true,
|
||||
})
|
||||
observedState, err := s.getContainers(ctx, project.Name, oneOffInclude, true)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
|
|
@ -20,7 +20,6 @@ import (
|
|||
"context"
|
||||
|
||||
"github.com/docker/docker/api/types"
|
||||
"github.com/docker/docker/api/types/filters"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
|
@ -103,12 +102,7 @@ func GetContextContainerState(ctx context.Context) (ContainersState, error) {
|
|||
}
|
||||
|
||||
func (s composeService) getUpdatedContainersStateContext(ctx context.Context, projectName string) (context.Context, error) {
|
||||
observedState, err := s.apiClient.ContainerList(ctx, types.ContainerListOptions{
|
||||
Filters: filters.NewArgs(
|
||||
projectFilter(projectName),
|
||||
),
|
||||
All: true,
|
||||
})
|
||||
observedState, err := s.getContainers(ctx, projectName, oneOffInclude, true)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
@ -23,23 +23,16 @@ import (
|
|||
"github.com/docker/compose-cli/api/progress"
|
||||
|
||||
"github.com/compose-spec/compose-go/types"
|
||||
moby "github.com/docker/docker/api/types"
|
||||
"github.com/docker/docker/api/types/filters"
|
||||
)
|
||||
|
||||
func (s *composeService) Stop(ctx context.Context, project *types.Project, options compose.StopOptions) error {
|
||||
w := progress.ContextWriter(ctx)
|
||||
var containers Containers
|
||||
containers, err := s.apiClient.ContainerList(ctx, moby.ContainerListOptions{
|
||||
Filters: filters.NewArgs(projectFilter(project.Name)),
|
||||
All: true,
|
||||
})
|
||||
containers, err := s.getContainers(ctx, project.Name, oneOffInclude, true, project.ServiceNames()...)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
containers = containers.filter(isService(project.ServiceNames()...))
|
||||
|
||||
return InReverseDependencyOrder(ctx, project, func(c context.Context, service types.ServiceConfig) error {
|
||||
return s.stopContainers(ctx, w, containers.filter(isService(service.Name)), options.Timeout)
|
||||
})
|
||||
|
|
|
@ -20,16 +20,12 @@ import (
|
|||
"context"
|
||||
|
||||
"github.com/docker/compose-cli/api/compose"
|
||||
moby "github.com/docker/docker/api/types"
|
||||
"github.com/docker/docker/api/types/filters"
|
||||
"golang.org/x/sync/errgroup"
|
||||
)
|
||||
|
||||
func (s *composeService) Top(ctx context.Context, projectName string, services []string) ([]compose.ContainerProcSummary, error) {
|
||||
var containers Containers
|
||||
containers, err := s.apiClient.ContainerList(ctx, moby.ContainerListOptions{
|
||||
Filters: filters.NewArgs(projectFilter(projectName)),
|
||||
})
|
||||
containers, err := s.getContainers(ctx, projectName, oneOffInclude, false)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче