@@ -294,7 +294,7 @@ func containerEvents(containers Containers, eventFunc func(string) progress.Even
294
294
return events
295
295
}
296
296
297
- func containerSkippedEvents (containers Containers , eventFunc func (string , string ) progress.Event , reason string ) []progress.Event {
297
+ func containerReasonEvents (containers Containers , eventFunc func (string , string ) progress.Event , reason string ) []progress.Event {
298
298
events := []progress.Event {}
299
299
for _ , container := range containers {
300
300
events = append (events , eventFunc (getContainerProgressName (container ), reason ))
@@ -334,7 +334,7 @@ func (s *composeService) waitDependencies(ctx context.Context, project *types.Pr
334
334
healthy , err := s .isServiceHealthy (ctx , waitingFor , true )
335
335
if err != nil {
336
336
if ! config .Required {
337
- w .Events (containerSkippedEvents (waitingFor , progress .SkippedEvent , fmt .Sprintf ("optional dependency %q is not running or is unhealthy" , dep )))
337
+ w .Events (containerReasonEvents (waitingFor , progress .SkippedEvent , fmt .Sprintf ("optional dependency %q is not running or is unhealthy" , dep )))
338
338
logrus .Warnf ("optional dependency %q is not running or is unhealthy: %s" , dep , err .Error ())
339
339
return nil
340
340
}
@@ -348,7 +348,7 @@ func (s *composeService) waitDependencies(ctx context.Context, project *types.Pr
348
348
healthy , err := s .isServiceHealthy (ctx , waitingFor , false )
349
349
if err != nil {
350
350
if ! config .Required {
351
- w .Events (containerSkippedEvents (waitingFor , progress .SkippedEvent , fmt .Sprintf ("optional dependency %q failed to start" , dep )))
351
+ w .Events (containerReasonEvents (waitingFor , progress .SkippedEvent , fmt .Sprintf ("optional dependency %q failed to start" , dep )))
352
352
logrus .Warnf ("optional dependency %q failed to start: %s" , dep , err .Error ())
353
353
return nil
354
354
}
@@ -365,17 +365,22 @@ func (s *composeService) waitDependencies(ctx context.Context, project *types.Pr
365
365
return err
366
366
}
367
367
if exited {
368
- logMessageSuffix := fmt .Sprintf ("%q didn't complete successfully: exit %d" , dep , code )
369
- if ! config .Required {
370
- w .Events (containerSkippedEvents (waitingFor , progress .SkippedEvent , fmt .Sprintf ("optional dependency %s" , logMessageSuffix )))
371
- logrus .Warnf ("optional dependency %s" , logMessageSuffix )
368
+ if code == 0 {
369
+ w .Events (containerEvents (waitingFor , progress .Exited ))
372
370
return nil
373
371
}
374
- w .Events (containerEvents (waitingFor , progress .Exited ))
375
- if code != 0 {
376
- return fmt .Errorf ("service %q didn't complete successfully: exit %d" , dep , code )
372
+
373
+ messageSuffix := fmt .Sprintf ("%q didn't complete successfully: exit %d" , dep , code )
374
+ if ! config .Required {
375
+ // optional -> mark as skipped & don't propagate error
376
+ w .Events (containerReasonEvents (waitingFor , progress .SkippedEvent , fmt .Sprintf ("optional dependency %s" , messageSuffix )))
377
+ logrus .Warnf ("optional dependency %s" , messageSuffix )
378
+ return nil
377
379
}
378
- return nil
380
+
381
+ msg := fmt .Sprintf ("service %s" , messageSuffix )
382
+ w .Events (containerReasonEvents (waitingFor , progress .ErrorMessageEvent , msg ))
383
+ return errors .New (msg )
379
384
}
380
385
default :
381
386
logrus .Warnf ("unsupported depends_on condition: %s" , config .Condition )
0 commit comments