@@ -41,6 +41,7 @@ func (s *composeService) Down(ctx context.Context, projectName string, options a
41
41
}
42
42
43
43
func (s * composeService ) down (ctx context.Context , projectName string , options api.DownOptions ) error {
44
+ builtFromResources := options .Project == nil
44
45
w := progress .ContextWriter (ctx )
45
46
resourceToRemove := false
46
47
@@ -50,8 +51,8 @@ func (s *composeService) down(ctx context.Context, projectName string, options a
50
51
return err
51
52
}
52
53
53
- if options . Project == nil {
54
- options .Project , err = s .projectFromLabels (ctx , containers . filter ( isNotOneOff ) , projectName )
54
+ if builtFromResources {
55
+ options .Project , err = s .getProjectWithVolumes (ctx , containers , projectName )
55
56
if err != nil {
56
57
return err
57
58
}
@@ -232,34 +233,9 @@ func (s *composeService) removeContainers(ctx context.Context, w progress.Writer
232
233
return eg .Wait ()
233
234
}
234
235
235
- // projectFromLabels builds a types.Project based on actual resources with compose labels set
236
- func (s * composeService ) projectFromLabels (ctx context.Context , containers Containers , projectName string ) (* types.Project , error ) {
237
- project := & types.Project {
238
- Name : projectName ,
239
- }
240
- if len (containers ) == 0 {
241
- return project , nil
242
- }
243
- set := map [string ]moby.Container {}
244
- for _ , c := range containers {
245
- set [c.Labels [api.ServiceLabel ]] = c
246
- }
247
- for s , c := range set {
248
- service := types.ServiceConfig {
249
- Name : s ,
250
- Image : c .Image ,
251
- Labels : c .Labels ,
252
- }
253
- dependencies := c .Labels [api .DependenciesLabel ]
254
- if len (dependencies ) > 0 {
255
- service .DependsOn = types.DependsOnConfig {}
256
- for _ , d := range strings .Split (dependencies , "," ) {
257
- service .DependsOn [d ] = types.ServiceDependency {}
258
- }
259
- }
260
- project .Services = append (project .Services , service )
261
- }
262
-
236
+ func (s * composeService ) getProjectWithVolumes (ctx context.Context , containers Containers , projectName string ) (* types.Project , error ) {
237
+ containers = containers .filter (isNotOneOff )
238
+ project := s .projectFromName (containers , projectName )
263
239
volumes , err := s .apiClient .VolumeList (ctx , filters .NewArgs (projectFilter (projectName )))
264
240
if err != nil {
265
241
return nil , err
@@ -273,6 +249,5 @@ func (s *composeService) projectFromLabels(ctx context.Context, containers Conta
273
249
Labels : vol .Labels ,
274
250
}
275
251
}
276
-
277
252
return project , nil
278
253
}
0 commit comments