@@ -33,7 +33,6 @@ import (
33
33
)
34
34
35
35
func (s * composeService ) Down (ctx context.Context , projectName string , options compose.DownOptions ) error {
36
- eg , _ := errgroup .WithContext (ctx )
37
36
w := progress .ContextWriter (ctx )
38
37
39
38
if options .Project == nil {
@@ -55,25 +54,21 @@ func (s *composeService) Down(ctx context.Context, projectName string, options c
55
54
56
55
err = InReverseDependencyOrder (ctx , options .Project , func (c context.Context , service types.ServiceConfig ) error {
57
56
serviceContainers , others := containers .split (isService (service .Name ))
58
- err := s .removeContainers (ctx , w , eg , serviceContainers )
57
+ err := s .removeContainers (ctx , w , serviceContainers )
59
58
containers = others
60
59
return err
61
60
})
61
+ if err != nil {
62
+ return err
63
+ }
62
64
63
- if options .RemoveOrphans {
64
- err := s .removeContainers (ctx , w , eg , containers )
65
+ if options .RemoveOrphans && len ( containers ) > 0 {
66
+ err := s .removeContainers (ctx , w , containers )
65
67
if err != nil {
66
68
return err
67
69
}
68
70
}
69
71
70
- if err != nil {
71
- return err
72
- }
73
- err = eg .Wait ()
74
- if err != nil {
75
- return err
76
- }
77
72
networks , err := s .apiClient .NetworkList (ctx , moby.NetworkListOptions {
78
73
Filters : filters .NewArgs (
79
74
projectFilter (projectName ),
@@ -82,14 +77,15 @@ func (s *composeService) Down(ctx context.Context, projectName string, options c
82
77
if err != nil {
83
78
return err
84
79
}
80
+
81
+ eg , _ := errgroup .WithContext (ctx )
85
82
for _ , n := range networks {
86
83
networkID := n .ID
87
84
networkName := n .Name
88
85
eg .Go (func () error {
89
86
return s .ensureNetworkDown (ctx , networkID , networkName )
90
87
})
91
88
}
92
-
93
89
return eg .Wait ()
94
90
}
95
91
@@ -108,15 +104,14 @@ func (s *composeService) stopContainers(ctx context.Context, w progress.Writer,
108
104
return nil
109
105
}
110
106
111
- func (s * composeService ) removeContainers (ctx context.Context , w progress.Writer , eg * errgroup.Group , containers []moby.Container ) error {
107
+ func (s * composeService ) removeContainers (ctx context.Context , w progress.Writer , containers []moby.Container ) error {
108
+ eg , _ := errgroup .WithContext (ctx )
112
109
for _ , container := range containers {
113
110
toDelete := container
114
111
eg .Go (func () error {
115
112
eventName := "Container " + getCanonicalContainerName (toDelete )
116
- w .Event (progress .StoppingEvent (eventName ))
117
113
err := s .stopContainers (ctx , w , []moby.Container {container })
118
114
if err != nil {
119
- w .Event (progress .ErrorMessageEvent (eventName , "Error while Stopping" ))
120
115
return err
121
116
}
122
117
w .Event (progress .RemovingEvent (eventName ))
0 commit comments