@@ -135,35 +135,46 @@ func (s *composeService) start(ctx context.Context, projectName string, options
135135 return err
136136 }
137137
138- if options .Wait || len (options .WaitServices ) != 0 {
139- depends := types.DependsOnConfig {}
140- for _ , s := range project .Services {
141- if len (options .WaitServices ) > 0 && ! utils .Contains (options .WaitServices , s .Name ) {
142- continue
143- }
138+ err = s .waitIfNeeded (ctx , project , options , containers )
139+ if err != nil {
140+ return err
141+ }
144142
145- depends [s .Name ] = types.ServiceDependency {
146- Condition : getDependencyCondition (s , project ),
147- Required : true ,
148- }
143+ return eg .Wait ()
144+ }
145+
146+ func (s * composeService ) waitIfNeeded (ctx context.Context , project * types.Project , options api.StartOptions , containers Containers ) error {
147+ if ! options .Wait && len (options .WaitServices ) == 0 {
148+ return nil
149+ }
150+
151+ depends := types.DependsOnConfig {}
152+ for _ , s := range project .Services {
153+ if len (options .WaitServices ) > 0 && ! utils .Contains (options .WaitServices , s .Name ) {
154+ continue
149155 }
150156
151- if options .WaitTimeout > 0 {
152- withTimeout , cancel := context .WithTimeout (ctx , options .WaitTimeout )
153- ctx = withTimeout
154- defer cancel ()
157+ depends [s .Name ] = types.ServiceDependency {
158+ Condition : getDependencyCondition (s , project ),
159+ Required : true ,
155160 }
161+ }
156162
157- err = s .waitDependencies (ctx , project , project .Name , depends , containers , 0 )
158- if err != nil {
159- if errors .Is (ctx .Err (), context .DeadlineExceeded ) {
160- return fmt .Errorf ("application not healthy after %s" , options .WaitTimeout )
161- }
162- return err
163+ if options .WaitTimeout > 0 {
164+ withTimeout , cancel := context .WithTimeout (ctx , options .WaitTimeout )
165+ ctx = withTimeout
166+ defer cancel ()
167+ }
168+
169+ err := s .waitDependencies (ctx , project , project .Name , depends , containers , 0 )
170+ if err != nil {
171+ if errors .Is (ctx .Err (), context .DeadlineExceeded ) {
172+ return fmt .Errorf ("application not healthy after %s" , options .WaitTimeout )
163173 }
174+ return err
164175 }
165176
166- return eg . Wait ()
177+ return nil
167178}
168179
169180// getDependencyCondition checks if service is depended on by other services
0 commit comments