diff --git a/pkg/compose/compose.go b/pkg/compose/compose.go index 0a7781ae8..1a8d73645 100644 --- a/pkg/compose/compose.go +++ b/pkg/compose/compose.go @@ -115,7 +115,7 @@ func (s *composeService) projectFromName(containers Containers, projectName stri if len(dependencies) > 0 { service.DependsOn = types.DependsOnConfig{} for _, d := range strings.Split(dependencies, ",") { - service.DependsOn[d] = types.ServiceDependency{} + service.DependsOn[d] = types.ServiceDependency{Condition: ServiceConditionRunningOrHealthy} } } project.Services = append(project.Services, service) diff --git a/pkg/compose/down.go b/pkg/compose/down.go index fda34fbd9..5b52e19a6 100644 --- a/pkg/compose/down.go +++ b/pkg/compose/down.go @@ -41,6 +41,7 @@ func (s *composeService) Down(ctx context.Context, projectName string, options a } func (s *composeService) down(ctx context.Context, projectName string, options api.DownOptions) error { + builtFromResources := options.Project == nil w := progress.ContextWriter(ctx) resourceToRemove := false @@ -50,8 +51,8 @@ func (s *composeService) down(ctx context.Context, projectName string, options a return err } - if options.Project == nil { - options.Project, err = s.projectFromLabels(ctx, containers.filter(isNotOneOff), projectName) + if builtFromResources { + options.Project, err = s.getProjectWithVolumes(ctx, containers, projectName) if err != nil { return err } @@ -232,34 +233,9 @@ func (s *composeService) removeContainers(ctx context.Context, w progress.Writer return eg.Wait() } -// projectFromLabels builds a types.Project based on actual resources with compose labels set -func (s *composeService) projectFromLabels(ctx context.Context, containers Containers, projectName string) (*types.Project, error) { - project := &types.Project{ - Name: projectName, - } - if len(containers) == 0 { - return project, nil - } - set := map[string]moby.Container{} - for _, c := range containers { - set[c.Labels[api.ServiceLabel]] = c - } - for s, c := range set { - service := types.ServiceConfig{ - Name: s, - Image: c.Image, - Labels: c.Labels, - } - dependencies := c.Labels[api.DependenciesLabel] - if len(dependencies) > 0 { - service.DependsOn = types.DependsOnConfig{} - for _, d := range strings.Split(dependencies, ",") { - service.DependsOn[d] = types.ServiceDependency{} - } - } - project.Services = append(project.Services, service) - } - +func (s *composeService) getProjectWithVolumes(ctx context.Context, containers Containers, projectName string) (*types.Project, error) { + containers = containers.filter(isNotOneOff) + project := s.projectFromName(containers, projectName) volumes, err := s.apiClient.VolumeList(ctx, filters.NewArgs(projectFilter(projectName))) if err != nil { return nil, err @@ -273,6 +249,5 @@ func (s *composeService) projectFromLabels(ctx context.Context, containers Conta Labels: vol.Labels, } } - return project, nil } diff --git a/pkg/compose/start.go b/pkg/compose/start.go index a42f4fcc6..3c271e33d 100644 --- a/pkg/compose/start.go +++ b/pkg/compose/start.go @@ -36,7 +36,7 @@ func (s *composeService) Start(ctx context.Context, projectName string, options func (s *composeService) start(ctx context.Context, projectName string, options api.StartOptions, listener api.ContainerEventListener) error { var containers Containers - containers, err := s.getContainers(ctx, projectName, oneOffInclude, true, options.AttachTo...) + containers, err := s.getContainers(ctx, projectName, oneOffExclude, true, options.AttachTo...) if err != nil { return err }