(ctx context.Context, projectName string, options api.DownOptions)
| 42 | } |
| 43 | |
| 44 | func (s *composeService) down(ctx context.Context, projectName string, options api.DownOptions) error { //nolint:gocyclo |
| 45 | resourceToRemove := false |
| 46 | |
| 47 | include := oneOffExclude |
| 48 | if options.RemoveOrphans { |
| 49 | include = oneOffInclude |
| 50 | } |
| 51 | containers, err := s.getContainers(ctx, projectName, include, true) |
| 52 | if err != nil { |
| 53 | return err |
| 54 | } |
| 55 | |
| 56 | project := options.Project |
| 57 | if project == nil { |
| 58 | project, err = s.getProjectWithResources(ctx, containers, projectName) |
| 59 | if err != nil { |
| 60 | return err |
| 61 | } |
| 62 | } |
| 63 | |
| 64 | // Check requested services exists in model |
| 65 | services, err := checkSelectedServices(options, project) |
| 66 | if err != nil { |
| 67 | return err |
| 68 | } |
| 69 | |
| 70 | if len(options.Services) > 0 && len(services) == 0 { |
| 71 | logrus.Infof("Any of the services %v not running in project %q", options.Services, projectName) |
| 72 | return nil |
| 73 | } |
| 74 | |
| 75 | options.Services = services |
| 76 | |
| 77 | if len(containers) > 0 { |
| 78 | resourceToRemove = true |
| 79 | } |
| 80 | |
| 81 | err = InReverseDependencyOrder(ctx, project, func(c context.Context, service string) error { |
| 82 | serv := project.Services[service] |
| 83 | if serv.Provider != nil { |
| 84 | return s.runPlugin(ctx, project, serv, "down") |
| 85 | } |
| 86 | serviceContainers := containers.filter(isService(service)) |
| 87 | err := s.removeContainers(ctx, serviceContainers, &serv, options.Timeout, options.Volumes) |
| 88 | return err |
| 89 | }, WithRootNodesAndDown(options.Services)) |
| 90 | if err != nil { |
| 91 | return err |
| 92 | } |
| 93 | |
| 94 | orphans := containers.filter(isOrphaned(project)) |
| 95 | if options.RemoveOrphans && len(orphans) > 0 { |
| 96 | err := s.removeContainers(ctx, orphans, nil, options.Timeout, false) |
| 97 | if err != nil { |
| 98 | return err |
| 99 | } |
| 100 | } |
| 101 |
no test coverage detected