|
|
@@ -41,7 +41,8 @@ func (s *composeService) Down(ctx context.Context, projectName string, options c
|
|
|
return err
|
|
|
}
|
|
|
|
|
|
- containers, err := s.apiClient.ContainerList(ctx, moby.ContainerListOptions{
|
|
|
+ var containers Containers
|
|
|
+ containers, err = s.apiClient.ContainerList(ctx, moby.ContainerListOptions{
|
|
|
Filters: filters.NewArgs(projectFilter(project.Name)),
|
|
|
All: true,
|
|
|
})
|
|
|
@@ -50,14 +51,14 @@ func (s *composeService) Down(ctx context.Context, projectName string, options c
|
|
|
}
|
|
|
|
|
|
err = InReverseDependencyOrder(ctx, project, func(c context.Context, service types.ServiceConfig) error {
|
|
|
- serviceContainers, others := split(containers, isService(service.Name))
|
|
|
- err := s.removeContainers(ctx, w, eg, serviceContainers)
|
|
|
+ serviceContainers, others := containers.split(isService(service.Name))
|
|
|
+ s.removeContainers(ctx, w, eg, serviceContainers)
|
|
|
containers = others
|
|
|
return err
|
|
|
})
|
|
|
|
|
|
if options.RemoveOrphans {
|
|
|
- err := s.removeContainers(ctx, w, eg, containers)
|
|
|
+ s.removeContainers(ctx, w, eg, containers)
|
|
|
if err != nil {
|
|
|
return err
|
|
|
}
|
|
|
@@ -89,7 +90,7 @@ func (s *composeService) Down(ctx context.Context, projectName string, options c
|
|
|
return eg.Wait()
|
|
|
}
|
|
|
|
|
|
-func (s *composeService) removeContainers(ctx context.Context, w progress.Writer, eg *errgroup.Group, containers []moby.Container) error {
|
|
|
+func (s *composeService) removeContainers(ctx context.Context, w progress.Writer, eg *errgroup.Group, containers []moby.Container) {
|
|
|
for _, container := range containers {
|
|
|
toDelete := container
|
|
|
eg.Go(func() error {
|
|
|
@@ -110,7 +111,6 @@ func (s *composeService) removeContainers(ctx context.Context, w progress.Writer
|
|
|
return nil
|
|
|
})
|
|
|
}
|
|
|
- return nil
|
|
|
}
|
|
|
|
|
|
func (s *composeService) projectFromContainerLabels(ctx context.Context, projectName string) (*types.Project, error) {
|
|
|
@@ -160,25 +160,3 @@ func loadProjectOptionsFromLabels(c moby.Container) (*cli.ProjectOptions, error)
|
|
|
cli.WithWorkingDirectory(c.Labels[workingDirLabel]),
|
|
|
cli.WithName(c.Labels[projectLabel]))
|
|
|
}
|
|
|
-
|
|
|
-type containerPredicate func(c moby.Container) bool
|
|
|
-
|
|
|
-func isService(service string) containerPredicate {
|
|
|
- return func(c moby.Container) bool {
|
|
|
- return c.Labels[serviceLabel] == service
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-// split return a container slice with elements to match predicate
|
|
|
-func split(containers []moby.Container, predicate containerPredicate) ([]moby.Container, []moby.Container) {
|
|
|
- var right []moby.Container
|
|
|
- var left []moby.Container
|
|
|
- for _, c := range containers {
|
|
|
- if predicate(c) {
|
|
|
- right = append(right, c)
|
|
|
- } else {
|
|
|
- left = append(left, c)
|
|
|
- }
|
|
|
- }
|
|
|
- return right, left
|
|
|
-}
|