mirror of
https://github.com/docker/compose.git
synced 2025-07-23 21:54:40 +02:00
Merge pull request #1747 from ndeloof/down_progress
This commit is contained in:
commit
b86ff6b18f
@ -22,6 +22,7 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"github.com/compose-spec/compose-go/types"
|
"github.com/compose-spec/compose-go/types"
|
||||||
|
"github.com/pkg/errors"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
|
|
||||||
"github.com/docker/compose-cli/aci/convert"
|
"github.com/docker/compose-cli/aci/convert"
|
||||||
@ -29,6 +30,7 @@ import (
|
|||||||
"github.com/docker/compose-cli/api/compose"
|
"github.com/docker/compose-cli/api/compose"
|
||||||
"github.com/docker/compose-cli/api/context/store"
|
"github.com/docker/compose-cli/api/context/store"
|
||||||
"github.com/docker/compose-cli/api/errdefs"
|
"github.com/docker/compose-cli/api/errdefs"
|
||||||
|
"github.com/docker/compose-cli/api/progress"
|
||||||
"github.com/docker/compose-cli/utils/formatter"
|
"github.com/docker/compose-cli/utils/formatter"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -123,21 +125,29 @@ func (cs aciComposeService) warnKeepVolumeOnDown(ctx context.Context, projectNam
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (cs *aciComposeService) Down(ctx context.Context, projectName string, options compose.DownOptions) error {
|
func (cs *aciComposeService) Down(ctx context.Context, projectName string, options compose.DownOptions) error {
|
||||||
logrus.Debugf("Down on projectName with name %q", projectName)
|
if options.Volumes {
|
||||||
|
return errors.Wrap(errdefs.ErrNotImplemented, "--volumes option is not supported on ACI")
|
||||||
|
}
|
||||||
|
if options.Images != "" {
|
||||||
|
return errors.Wrap(errdefs.ErrNotImplemented, "--rmi option is not supported on ACI")
|
||||||
|
}
|
||||||
|
return progress.Run(ctx, func(ctx context.Context) error {
|
||||||
|
logrus.Debugf("Down on project with name %q", projectName)
|
||||||
|
|
||||||
|
if err := cs.warnKeepVolumeOnDown(ctx, projectName); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
cg, err := deleteACIContainerGroup(ctx, cs.ctx, projectName)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if cg.IsHTTPStatus(http.StatusNoContent) {
|
||||||
|
return errdefs.ErrNotFound
|
||||||
|
}
|
||||||
|
|
||||||
if err := cs.warnKeepVolumeOnDown(ctx, projectName); err != nil {
|
|
||||||
return err
|
return err
|
||||||
}
|
})
|
||||||
|
|
||||||
cg, err := deleteACIContainerGroup(ctx, cs.ctx, projectName)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if cg.IsHTTPStatus(http.StatusNoContent) {
|
|
||||||
return errdefs.ErrNotFound
|
|
||||||
}
|
|
||||||
|
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cs *aciComposeService) Ps(ctx context.Context, projectName string, options compose.PsOptions) ([]compose.ContainerSummary, error) {
|
func (cs *aciComposeService) Ps(ctx context.Context, projectName string, options compose.PsOptions) ([]compose.ContainerSummary, error) {
|
||||||
|
@ -218,7 +218,7 @@ func RootCommand(contextType string, backend compose.Service) *cobra.Command {
|
|||||||
|
|
||||||
command.AddCommand(
|
command.AddCommand(
|
||||||
upCommand(&opts, contextType, backend),
|
upCommand(&opts, contextType, backend),
|
||||||
downCommand(&opts, contextType, backend),
|
downCommand(&opts, backend),
|
||||||
startCommand(&opts, backend),
|
startCommand(&opts, backend),
|
||||||
restartCommand(&opts, backend),
|
restartCommand(&opts, backend),
|
||||||
stopCommand(&opts, backend),
|
stopCommand(&opts, backend),
|
||||||
|
@ -25,8 +25,6 @@ import (
|
|||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
|
||||||
"github.com/docker/compose-cli/api/compose"
|
"github.com/docker/compose-cli/api/compose"
|
||||||
"github.com/docker/compose-cli/api/context/store"
|
|
||||||
"github.com/docker/compose-cli/api/progress"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type downOptions struct {
|
type downOptions struct {
|
||||||
@ -38,7 +36,7 @@ type downOptions struct {
|
|||||||
images string
|
images string
|
||||||
}
|
}
|
||||||
|
|
||||||
func downCommand(p *projectOptions, contextType string, backend compose.Service) *cobra.Command {
|
func downCommand(p *projectOptions, backend compose.Service) *cobra.Command {
|
||||||
opts := downOptions{
|
opts := downOptions{
|
||||||
projectOptions: p,
|
projectOptions: p,
|
||||||
}
|
}
|
||||||
@ -63,39 +61,33 @@ func downCommand(p *projectOptions, contextType string, backend compose.Service)
|
|||||||
flags := downCmd.Flags()
|
flags := downCmd.Flags()
|
||||||
flags.BoolVar(&opts.removeOrphans, "remove-orphans", false, "Remove containers for services not defined in the Compose file.")
|
flags.BoolVar(&opts.removeOrphans, "remove-orphans", false, "Remove containers for services not defined in the Compose file.")
|
||||||
flags.IntVarP(&opts.timeout, "timeout", "t", 10, "Specify a shutdown timeout in seconds")
|
flags.IntVarP(&opts.timeout, "timeout", "t", 10, "Specify a shutdown timeout in seconds")
|
||||||
|
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.")
|
||||||
switch contextType {
|
flags.StringVar(&opts.images, "rmi", "", `Remove images used by services. "local" remove only images that don't have a custom tag ("local"|"all")`)
|
||||||
case store.LocalContextType, store.DefaultContextType, store.EcsLocalSimulationContextType:
|
|
||||||
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.")
|
|
||||||
flags.StringVar(&opts.images, "rmi", "", `Remove images used by services. "local" remove only images that don't have a custom tag ("local"|"all")`)
|
|
||||||
}
|
|
||||||
return downCmd
|
return downCmd
|
||||||
}
|
}
|
||||||
|
|
||||||
func runDown(ctx context.Context, backend compose.Service, opts downOptions) error {
|
func runDown(ctx context.Context, backend compose.Service, opts downOptions) error {
|
||||||
return progress.Run(ctx, func(ctx context.Context) error {
|
name := opts.ProjectName
|
||||||
name := opts.ProjectName
|
var project *types.Project
|
||||||
var project *types.Project
|
if opts.ProjectName == "" {
|
||||||
if opts.ProjectName == "" {
|
p, err := opts.toProject(nil)
|
||||||
p, err := opts.toProject(nil)
|
if err != nil {
|
||||||
if err != nil {
|
return err
|
||||||
return err
|
|
||||||
}
|
|
||||||
project = p
|
|
||||||
name = p.Name
|
|
||||||
}
|
}
|
||||||
|
project = p
|
||||||
|
name = p.Name
|
||||||
|
}
|
||||||
|
|
||||||
var timeout *time.Duration
|
var timeout *time.Duration
|
||||||
if opts.timeChanged {
|
if opts.timeChanged {
|
||||||
timeoutValue := time.Duration(opts.timeout) * time.Second
|
timeoutValue := time.Duration(opts.timeout) * time.Second
|
||||||
timeout = &timeoutValue
|
timeout = &timeoutValue
|
||||||
}
|
}
|
||||||
return backend.Down(ctx, name, compose.DownOptions{
|
return backend.Down(ctx, name, compose.DownOptions{
|
||||||
RemoveOrphans: opts.removeOrphans,
|
RemoveOrphans: opts.removeOrphans,
|
||||||
Project: project,
|
Project: project,
|
||||||
Timeout: timeout,
|
Timeout: timeout,
|
||||||
Images: opts.images,
|
Images: opts.images,
|
||||||
Volumes: opts.volumes,
|
Volumes: opts.volumes,
|
||||||
})
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
16
ecs/down.go
16
ecs/down.go
@ -19,12 +19,26 @@ package ecs
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
"github.com/docker/compose-cli/api/compose"
|
"github.com/pkg/errors"
|
||||||
|
|
||||||
|
"github.com/docker/compose-cli/api/compose"
|
||||||
|
"github.com/docker/compose-cli/api/errdefs"
|
||||||
"github.com/docker/compose-cli/api/progress"
|
"github.com/docker/compose-cli/api/progress"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (b *ecsAPIService) Down(ctx context.Context, projectName string, options compose.DownOptions) error {
|
func (b *ecsAPIService) Down(ctx context.Context, projectName string, options compose.DownOptions) error {
|
||||||
|
if options.Volumes {
|
||||||
|
return errors.Wrap(errdefs.ErrNotImplemented, "--volumes option is not supported on ECS")
|
||||||
|
}
|
||||||
|
if options.Images != "" {
|
||||||
|
return errors.Wrap(errdefs.ErrNotImplemented, "--rmi option is not supported on ECS")
|
||||||
|
}
|
||||||
|
return progress.Run(ctx, func(ctx context.Context) error {
|
||||||
|
return b.down(ctx, projectName)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b *ecsAPIService) down(ctx context.Context, projectName string) error {
|
||||||
resources, err := b.aws.ListStackResources(ctx, projectName)
|
resources, err := b.aws.ListStackResources(ctx, projectName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -24,6 +24,7 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/compose-spec/compose-go/types"
|
"github.com/compose-spec/compose-go/types"
|
||||||
|
"github.com/pkg/errors"
|
||||||
|
|
||||||
"github.com/docker/compose-cli/api/compose"
|
"github.com/docker/compose-cli/api/compose"
|
||||||
apicontext "github.com/docker/compose-cli/api/context"
|
apicontext "github.com/docker/compose-cli/api/context"
|
||||||
@ -110,8 +111,19 @@ func (s *composeService) Up(ctx context.Context, project *types.Project, options
|
|||||||
|
|
||||||
// Down executes the equivalent to a `compose down`
|
// Down executes the equivalent to a `compose down`
|
||||||
func (s *composeService) Down(ctx context.Context, projectName string, options compose.DownOptions) error {
|
func (s *composeService) Down(ctx context.Context, projectName string, options compose.DownOptions) error {
|
||||||
w := progress.ContextWriter(ctx)
|
if options.Volumes {
|
||||||
|
return errors.Wrap(errdefs.ErrNotImplemented, "--volumes option is not supported on Kubernetes")
|
||||||
|
}
|
||||||
|
if options.Images != "" {
|
||||||
|
return errors.Wrap(errdefs.ErrNotImplemented, "--rmi option is not supported on Kubernetes")
|
||||||
|
}
|
||||||
|
return progress.Run(ctx, func(ctx context.Context) error {
|
||||||
|
return s.down(ctx, projectName, options)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *composeService) down(ctx context.Context, projectName string, options compose.DownOptions) error {
|
||||||
|
w := progress.ContextWriter(ctx)
|
||||||
eventName := fmt.Sprintf("Remove %s", projectName)
|
eventName := fmt.Sprintf("Remove %s", projectName)
|
||||||
w.Event(progress.CreatingEvent(eventName))
|
w.Event(progress.CreatingEvent(eventName))
|
||||||
|
|
||||||
|
@ -36,6 +36,12 @@ import (
|
|||||||
type downOp func() error
|
type downOp func() error
|
||||||
|
|
||||||
func (s *composeService) Down(ctx context.Context, projectName string, options compose.DownOptions) error {
|
func (s *composeService) Down(ctx context.Context, projectName string, options compose.DownOptions) error {
|
||||||
|
return progress.Run(ctx, func(ctx context.Context) error {
|
||||||
|
return s.down(ctx, projectName, options)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *composeService) down(ctx context.Context, projectName string, options compose.DownOptions) error {
|
||||||
w := progress.ContextWriter(ctx)
|
w := progress.ContextWriter(ctx)
|
||||||
resourceToRemove := false
|
resourceToRemove := false
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user