(ctx context.Context, project *types.Project, service types.ServiceConfig, containers Containers, listener api.ContainerEventListener, timeout time.Duration, )
| 517 | } |
| 518 | |
| 519 | func (s *composeService) startService(ctx context.Context, |
| 520 | project *types.Project, service types.ServiceConfig, |
| 521 | containers Containers, listener api.ContainerEventListener, |
| 522 | timeout time.Duration, |
| 523 | ) error { |
| 524 | if service.Deploy != nil && service.Deploy.Replicas != nil && *service.Deploy.Replicas == 0 { |
| 525 | return nil |
| 526 | } |
| 527 | |
| 528 | err := s.waitDependencies(ctx, project, service.Name, service.DependsOn, containers, timeout) |
| 529 | if err != nil { |
| 530 | return err |
| 531 | } |
| 532 | |
| 533 | if len(containers) == 0 { |
| 534 | if service.GetScale() == 0 { |
| 535 | return nil |
| 536 | } |
| 537 | return fmt.Errorf("service %q has no container to start", service.Name) |
| 538 | } |
| 539 | |
| 540 | serviceContainers := containers.filter(isService(service.Name), isNotOneOff) |
| 541 | toStart := serviceContainers.filter(isNotRunning) |
| 542 | if len(toStart) == 0 { |
| 543 | return nil |
| 544 | } |
| 545 | |
| 546 | // pre_start runs once per service, only when no replica is already running |
| 547 | // (e.g. initial up, force-recreate, or spec change). per_replica: false is |
| 548 | // the only currently supported mode. Pick the replica with the lowest |
| 549 | // container-number so the choice is deterministic regardless of the order |
| 550 | // the daemon returns containers in. |
| 551 | if len(service.PreStart) > 0 && len(serviceContainers) == len(toStart) { |
| 552 | if err := s.runPreStart(ctx, project, service, lowestNumberedContainer(toStart), listener); err != nil { |
| 553 | return err |
| 554 | } |
| 555 | } |
| 556 | |
| 557 | for _, ctr := range toStart { |
| 558 | if err := s.startServiceContainer(ctx, project, service, ctr, listener); err != nil { |
| 559 | return err |
| 560 | } |
| 561 | } |
| 562 | return nil |
| 563 | } |
| 564 | |
| 565 | func (s *composeService) startServiceContainer(ctx context.Context, project *types.Project, service types.ServiceConfig, ctr container.Summary, listener api.ContainerEventListener) error { |
| 566 | if err := s.injectSecrets(ctx, project, service, ctr.ID); err != nil { |
no test coverage detected