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

Commit b86ff6b

Browse files
authored
Merge pull request #1747 from ndeloof/down_progress
2 parents bb54b9a + dec9169 commit b86ff6b

File tree

6 files changed

+80
-46
lines changed

6 files changed

+80
-46
lines changed

aci/compose.go

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,15 @@ import (
2222
"net/http"
2323

2424
"github.com/compose-spec/compose-go/types"
25+
"github.com/pkg/errors"
2526
"github.com/sirupsen/logrus"
2627

2728
"github.com/docker/compose-cli/aci/convert"
2829
"github.com/docker/compose-cli/aci/login"
2930
"github.com/docker/compose-cli/api/compose"
3031
"github.com/docker/compose-cli/api/context/store"
3132
"github.com/docker/compose-cli/api/errdefs"
33+
"github.com/docker/compose-cli/api/progress"
3234
"github.com/docker/compose-cli/utils/formatter"
3335
)
3436

@@ -123,21 +125,29 @@ func (cs aciComposeService) warnKeepVolumeOnDown(ctx context.Context, projectNam
123125
}
124126

125127
func (cs *aciComposeService) Down(ctx context.Context, projectName string, options compose.DownOptions) error {
126-
logrus.Debugf("Down on projectName with name %q", projectName)
127-
128-
if err := cs.warnKeepVolumeOnDown(ctx, projectName); err != nil {
129-
return err
130-
}
131-
132-
cg, err := deleteACIContainerGroup(ctx, cs.ctx, projectName)
133-
if err != nil {
134-
return err
128+
if options.Volumes {
129+
return errors.Wrap(errdefs.ErrNotImplemented, "--volumes option is not supported on ACI")
135130
}
136-
if cg.IsHTTPStatus(http.StatusNoContent) {
137-
return errdefs.ErrNotFound
131+
if options.Images != "" {
132+
return errors.Wrap(errdefs.ErrNotImplemented, "--rmi option is not supported on ACI")
138133
}
134+
return progress.Run(ctx, func(ctx context.Context) error {
135+
logrus.Debugf("Down on project with name %q", projectName)
139136

140-
return err
137+
if err := cs.warnKeepVolumeOnDown(ctx, projectName); err != nil {
138+
return err
139+
}
140+
141+
cg, err := deleteACIContainerGroup(ctx, cs.ctx, projectName)
142+
if err != nil {
143+
return err
144+
}
145+
if cg.IsHTTPStatus(http.StatusNoContent) {
146+
return errdefs.ErrNotFound
147+
}
148+
149+
return err
150+
})
141151
}
142152

143153
func (cs *aciComposeService) Ps(ctx context.Context, projectName string, options compose.PsOptions) ([]compose.ContainerSummary, error) {

cli/cmd/compose/compose.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ func RootCommand(contextType string, backend compose.Service) *cobra.Command {
218218

219219
command.AddCommand(
220220
upCommand(&opts, contextType, backend),
221-
downCommand(&opts, contextType, backend),
221+
downCommand(&opts, backend),
222222
startCommand(&opts, backend),
223223
restartCommand(&opts, backend),
224224
stopCommand(&opts, backend),

cli/cmd/compose/down.go

Lines changed: 23 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@ import (
2525
"github.com/spf13/cobra"
2626

2727
"github.com/docker/compose-cli/api/compose"
28-
"github.com/docker/compose-cli/api/context/store"
29-
"github.com/docker/compose-cli/api/progress"
3028
)
3129

3230
type downOptions struct {
@@ -38,7 +36,7 @@ type downOptions struct {
3836
images string
3937
}
4038

41-
func downCommand(p *projectOptions, contextType string, backend compose.Service) *cobra.Command {
39+
func downCommand(p *projectOptions, backend compose.Service) *cobra.Command {
4240
opts := downOptions{
4341
projectOptions: p,
4442
}
@@ -63,39 +61,33 @@ func downCommand(p *projectOptions, contextType string, backend compose.Service)
6361
flags := downCmd.Flags()
6462
flags.BoolVar(&opts.removeOrphans, "remove-orphans", false, "Remove containers for services not defined in the Compose file.")
6563
flags.IntVarP(&opts.timeout, "timeout", "t", 10, "Specify a shutdown timeout in seconds")
66-
67-
switch contextType {
68-
case store.LocalContextType, store.DefaultContextType, store.EcsLocalSimulationContextType:
69-
flags.BoolVarP(&opts.volumes, "volumes", "v", false, " Remove named volumes declared in the `volumes` section of the Compose file and anonymous volumes attached to containers.")
70-
flags.StringVar(&opts.images, "rmi", "", `Remove images used by services. "local" remove only images that don't have a custom tag ("local"|"all")`)
71-
}
64+
flags.BoolVarP(&opts.volumes, "volumes", "v", false, " Remove named volumes declared in the `volumes` section of the Compose file and anonymous volumes attached to containers.")
65+
flags.StringVar(&opts.images, "rmi", "", `Remove images used by services. "local" remove only images that don't have a custom tag ("local"|"all")`)
7266
return downCmd
7367
}
7468

7569
func runDown(ctx context.Context, backend compose.Service, opts downOptions) error {
76-
return progress.Run(ctx, func(ctx context.Context) error {
77-
name := opts.ProjectName
78-
var project *types.Project
79-
if opts.ProjectName == "" {
80-
p, err := opts.toProject(nil)
81-
if err != nil {
82-
return err
83-
}
84-
project = p
85-
name = p.Name
70+
name := opts.ProjectName
71+
var project *types.Project
72+
if opts.ProjectName == "" {
73+
p, err := opts.toProject(nil)
74+
if err != nil {
75+
return err
8676
}
77+
project = p
78+
name = p.Name
79+
}
8780

88-
var timeout *time.Duration
89-
if opts.timeChanged {
90-
timeoutValue := time.Duration(opts.timeout) * time.Second
91-
timeout = &timeoutValue
92-
}
93-
return backend.Down(ctx, name, compose.DownOptions{
94-
RemoveOrphans: opts.removeOrphans,
95-
Project: project,
96-
Timeout: timeout,
97-
Images: opts.images,
98-
Volumes: opts.volumes,
99-
})
81+
var timeout *time.Duration
82+
if opts.timeChanged {
83+
timeoutValue := time.Duration(opts.timeout) * time.Second
84+
timeout = &timeoutValue
85+
}
86+
return backend.Down(ctx, name, compose.DownOptions{
87+
RemoveOrphans: opts.removeOrphans,
88+
Project: project,
89+
Timeout: timeout,
90+
Images: opts.images,
91+
Volumes: opts.volumes,
10092
})
10193
}

ecs/down.go

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,26 @@ package ecs
1919
import (
2020
"context"
2121

22-
"github.com/docker/compose-cli/api/compose"
22+
"github.com/pkg/errors"
2323

24+
"github.com/docker/compose-cli/api/compose"
25+
"github.com/docker/compose-cli/api/errdefs"
2426
"github.com/docker/compose-cli/api/progress"
2527
)
2628

2729
func (b *ecsAPIService) Down(ctx context.Context, projectName string, options compose.DownOptions) error {
30+
if options.Volumes {
31+
return errors.Wrap(errdefs.ErrNotImplemented, "--volumes option is not supported on ECS")
32+
}
33+
if options.Images != "" {
34+
return errors.Wrap(errdefs.ErrNotImplemented, "--rmi option is not supported on ECS")
35+
}
36+
return progress.Run(ctx, func(ctx context.Context) error {
37+
return b.down(ctx, projectName)
38+
})
39+
}
40+
41+
func (b *ecsAPIService) down(ctx context.Context, projectName string) error {
2842
resources, err := b.aws.ListStackResources(ctx, projectName)
2943
if err != nil {
3044
return err

kube/compose.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424
"strings"
2525

2626
"github.com/compose-spec/compose-go/types"
27+
"github.com/pkg/errors"
2728

2829
"github.com/docker/compose-cli/api/compose"
2930
apicontext "github.com/docker/compose-cli/api/context"
@@ -110,8 +111,19 @@ func (s *composeService) Up(ctx context.Context, project *types.Project, options
110111

111112
// Down executes the equivalent to a `compose down`
112113
func (s *composeService) Down(ctx context.Context, projectName string, options compose.DownOptions) error {
113-
w := progress.ContextWriter(ctx)
114+
if options.Volumes {
115+
return errors.Wrap(errdefs.ErrNotImplemented, "--volumes option is not supported on Kubernetes")
116+
}
117+
if options.Images != "" {
118+
return errors.Wrap(errdefs.ErrNotImplemented, "--rmi option is not supported on Kubernetes")
119+
}
120+
return progress.Run(ctx, func(ctx context.Context) error {
121+
return s.down(ctx, projectName, options)
122+
})
123+
}
114124

125+
func (s *composeService) down(ctx context.Context, projectName string, options compose.DownOptions) error {
126+
w := progress.ContextWriter(ctx)
115127
eventName := fmt.Sprintf("Remove %s", projectName)
116128
w.Event(progress.CreatingEvent(eventName))
117129

local/compose/down.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,12 @@ import (
3636
type downOp func() error
3737

3838
func (s *composeService) Down(ctx context.Context, projectName string, options compose.DownOptions) error {
39+
return progress.Run(ctx, func(ctx context.Context) error {
40+
return s.down(ctx, projectName, options)
41+
})
42+
}
43+
44+
func (s *composeService) down(ctx context.Context, projectName string, options compose.DownOptions) error {
3945
w := progress.ContextWriter(ctx)
4046
resourceToRemove := false
4147

0 commit comments

Comments
 (0)