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

Commit d073c93

Browse files
authored
Merge pull request #1509 from docker/pause_project_name
pause/unpause only need project name. use getContainers where possible
2 parents 0e8a56b + 7d85485 commit d073c93

File tree

21 files changed

+50
-102
lines changed

21 files changed

+50
-102
lines changed

aci/compose.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,11 @@ func (cs *aciComposeService) Stop(ctx context.Context, project *types.Project, o
7272
return errdefs.ErrNotImplemented
7373
}
7474

75-
func (cs *aciComposeService) Pause(ctx context.Context, project *types.Project) error {
75+
func (cs *aciComposeService) Pause(ctx context.Context, project string, options compose.PauseOptions) error {
7676
return errdefs.ErrNotImplemented
7777
}
7878

79-
func (cs *aciComposeService) UnPause(ctx context.Context, project *types.Project) error {
79+
func (cs *aciComposeService) UnPause(ctx context.Context, project string, options compose.PauseOptions) error {
8080
return errdefs.ErrNotImplemented
8181
}
8282

api/client/compose.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,11 +96,11 @@ func (c *composeService) Exec(ctx context.Context, project *types.Project, opts
9696
return errdefs.ErrNotImplemented
9797
}
9898

99-
func (c *composeService) Pause(ctx context.Context, project *types.Project) error {
99+
func (c *composeService) Pause(ctx context.Context, project string, options compose.PauseOptions) error {
100100
return errdefs.ErrNotImplemented
101101
}
102102

103-
func (c *composeService) UnPause(ctx context.Context, project *types.Project) error {
103+
func (c *composeService) UnPause(ctx context.Context, project string, options compose.PauseOptions) error {
104104
return errdefs.ErrNotImplemented
105105
}
106106

api/compose/api.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,9 @@ type Service interface {
6363
// Exec executes a command in a running service container
6464
Exec(ctx context.Context, project *types.Project, opts RunOptions) error
6565
// Pause executes the equivalent to a `compose pause`
66-
Pause(ctx context.Context, project *types.Project) error
66+
Pause(ctx context.Context, project string, options PauseOptions) error
6767
// UnPause executes the equivalent to a `compose unpause`
68-
UnPause(ctx context.Context, project *types.Project) error
68+
UnPause(ctx context.Context, project string, options PauseOptions) error
6969
// Top executes the equivalent to a `compose top`
7070
Top(ctx context.Context, projectName string, services []string) ([]ContainerProcSummary, error)
7171
// Events executes the equivalent to a `compose events`
@@ -303,6 +303,12 @@ type LogOptions struct {
303303
Timestamps bool
304304
}
305305

306+
// PauseOptions group options of the Pause API
307+
type PauseOptions struct {
308+
// Services passed in the command line to be started
309+
Services []string
310+
}
311+
306312
const (
307313
// STARTING indicates that stack is being deployed
308314
STARTING string = "Starting"

cli/cmd/compose/pause.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"github.com/spf13/cobra"
2323

2424
"github.com/docker/compose-cli/api/client"
25+
"github.com/docker/compose-cli/api/compose"
2526
"github.com/docker/compose-cli/api/progress"
2627
)
2728

@@ -49,13 +50,15 @@ func runPause(ctx context.Context, opts pauseOptions, services []string) error {
4950
return err
5051
}
5152

52-
project, err := opts.toProject(services)
53+
project, err := opts.toProjectName()
5354
if err != nil {
5455
return err
5556
}
5657

5758
_, err = progress.Run(ctx, func(ctx context.Context) (string, error) {
58-
return "", c.ComposeService().Pause(ctx, project)
59+
return "", c.ComposeService().Pause(ctx, project, compose.PauseOptions{
60+
Services: services,
61+
})
5962
})
6063
return err
6164
}
@@ -84,13 +87,15 @@ func runUnPause(ctx context.Context, opts unpauseOptions, services []string) err
8487
return err
8588
}
8689

87-
project, err := opts.toProject(services)
90+
project, err := opts.toProjectName()
8891
if err != nil {
8992
return err
9093
}
9194

9295
_, err = progress.Run(ctx, func(ctx context.Context) (string, error) {
93-
return "", c.ComposeService().UnPause(ctx, project)
96+
return "", c.ComposeService().UnPause(ctx, project, compose.PauseOptions{
97+
Services: services,
98+
})
9499
})
95100
return err
96101
}

ecs/local/compose.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -188,12 +188,12 @@ func (e ecsLocalSimulation) Exec(ctx context.Context, project *types.Project, op
188188
return errdefs.ErrNotImplemented
189189
}
190190

191-
func (e ecsLocalSimulation) Pause(ctx context.Context, project *types.Project) error {
192-
return e.compose.Pause(ctx, project)
191+
func (e ecsLocalSimulation) Pause(ctx context.Context, project string, options compose.PauseOptions) error {
192+
return e.compose.Pause(ctx, project, options)
193193
}
194194

195-
func (e ecsLocalSimulation) UnPause(ctx context.Context, project *types.Project) error {
196-
return e.compose.UnPause(ctx, project)
195+
func (e ecsLocalSimulation) UnPause(ctx context.Context, project string, options compose.PauseOptions) error {
196+
return e.compose.UnPause(ctx, project, options)
197197
}
198198

199199
func (e ecsLocalSimulation) Top(ctx context.Context, projectName string, services []string) ([]compose.ContainerProcSummary, error) {

ecs/up.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,11 @@ func (b *ecsAPIService) Stop(ctx context.Context, project *types.Project, option
5959
return errdefs.ErrNotImplemented
6060
}
6161

62-
func (b *ecsAPIService) Pause(ctx context.Context, project *types.Project) error {
62+
func (b *ecsAPIService) Pause(ctx context.Context, project string, options compose.PauseOptions) error {
6363
return errdefs.ErrNotImplemented
6464
}
6565

66-
func (b *ecsAPIService) UnPause(ctx context.Context, project *types.Project) error {
66+
func (b *ecsAPIService) UnPause(ctx context.Context, project string, options compose.PauseOptions) error {
6767
return errdefs.ErrNotImplemented
6868
}
6969

kube/compose.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -252,11 +252,11 @@ func (s *composeService) Exec(ctx context.Context, project *types.Project, opts
252252
return errdefs.ErrNotImplemented
253253
}
254254

255-
func (s *composeService) Pause(ctx context.Context, project *types.Project) error {
255+
func (s *composeService) Pause(ctx context.Context, project string, options compose.PauseOptions) error {
256256
return errdefs.ErrNotImplemented
257257
}
258258

259-
func (s *composeService) UnPause(ctx context.Context, project *types.Project) error {
259+
func (s *composeService) UnPause(ctx context.Context, project string, options compose.PauseOptions) error {
260260
return errdefs.ErrNotImplemented
261261
}
262262

local/compose/attach.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ import (
3333
)
3434

3535
func (s *composeService) attach(ctx context.Context, project *types.Project, listener compose.ContainerEventListener, selectedServices []string) (Containers, error) {
36-
containers, err := s.getContainers(ctx, project, oneOffExclude, selectedServices)
36+
containers, err := s.getContainers(ctx, project.Name, oneOffExclude, true, selectedServices...)
3737
if err != nil {
3838
return nil, err
3939
}

local/compose/containers.go

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import (
2121
"fmt"
2222
"sort"
2323

24-
"github.com/compose-spec/compose-go/types"
2524
moby "github.com/docker/docker/api/types"
2625
"github.com/docker/docker/api/types/filters"
2726

@@ -39,10 +38,10 @@ const (
3938
oneOffOnly
4039
)
4140

42-
func (s *composeService) getContainers(ctx context.Context, project *types.Project, oneOff oneOff, selectedServices []string) (Containers, error) {
41+
func (s *composeService) getContainers(ctx context.Context, project string, oneOff oneOff, stopped bool, selectedServices ...string) (Containers, error) {
4342
var containers Containers
4443
f := filters.NewArgs(
45-
projectFilter(project.Name),
44+
projectFilter(project),
4645
)
4746
switch oneOff {
4847
case oneOffOnly:
@@ -53,15 +52,14 @@ func (s *composeService) getContainers(ctx context.Context, project *types.Proje
5352
}
5453
containers, err := s.apiClient.ContainerList(ctx, moby.ContainerListOptions{
5554
Filters: f,
56-
All: true,
55+
All: stopped,
5756
})
5857
if err != nil {
5958
return nil, err
6059
}
61-
if len(selectedServices) == 0 {
62-
selectedServices = project.ServiceNames()
60+
if len(selectedServices) > 0 {
61+
containers = containers.filter(isService(selectedServices...))
6362
}
64-
containers = containers.filter(isService(selectedServices...))
6563
return containers, nil
6664
}
6765

local/compose/create.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ import (
2626
"github.com/compose-spec/compose-go/types"
2727
moby "github.com/docker/docker/api/types"
2828
"github.com/docker/docker/api/types/container"
29-
"github.com/docker/docker/api/types/filters"
3029
"github.com/docker/docker/api/types/mount"
3130
"github.com/docker/docker/api/types/network"
3231
"github.com/docker/docker/api/types/strslice"
@@ -69,10 +68,7 @@ func (s *composeService) Create(ctx context.Context, project *types.Project, opt
6968
}
7069

7170
var observedState Containers
72-
observedState, err = s.apiClient.ContainerList(ctx, moby.ContainerListOptions{
73-
Filters: filters.NewArgs(projectFilter(project.Name)),
74-
All: true,
75-
})
71+
observedState, err = s.getContainers(ctx, project.Name, oneOffInclude, true)
7672
if err != nil {
7773
return err
7874
}

0 commit comments

Comments
 (0)