-
Notifications
You must be signed in to change notification settings - Fork 5.7k
introduce up --wait condition #8777
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -261,18 +261,28 @@ func getContainerProgressName(container moby.Container) string { | |
| return "Container " + getCanonicalContainerName(container) | ||
| } | ||
|
|
||
| func (s *composeService) waitDependencies(ctx context.Context, project *types.Project, service types.ServiceConfig) error { | ||
| const ServiceConditionRuningOrHealthy = "running_or_healthy" | ||
|
|
||
| func (s *composeService) waitDependencies(ctx context.Context, project *types.Project, dependencies types.DependsOnConfig) error { | ||
| eg, _ := errgroup.WithContext(ctx) | ||
| for dep, config := range service.DependsOn { | ||
| for dep, config := range dependencies { | ||
| dep, config := dep, config | ||
| eg.Go(func() error { | ||
| ticker := time.NewTicker(500 * time.Millisecond) | ||
| defer ticker.Stop() | ||
| for { | ||
| <-ticker.C | ||
| switch config.Condition { | ||
| case ServiceConditionRuningOrHealthy: | ||
| healthy, err := s.isServiceHealthy(ctx, project, dep, true) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (just thinking out loud); perhaps we need to have a look at the events API, and see if we can improve it enough so that compose can (more easily) use that. We already have a
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. would ne a nice addition to the event stream indeed |
||
| if err != nil { | ||
| return err | ||
| } | ||
| if healthy { | ||
| return nil | ||
| } | ||
| case types.ServiceConditionHealthy: | ||
| healthy, err := s.isServiceHealthy(ctx, project, dep) | ||
| healthy, err := s.isServiceHealthy(ctx, project, dep, false) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
@@ -502,7 +512,7 @@ func (s *composeService) connectContainerToNetwork(ctx context.Context, id strin | |
| return nil | ||
| } | ||
|
|
||
| func (s *composeService) isServiceHealthy(ctx context.Context, project *types.Project, service string) (bool, error) { | ||
| func (s *composeService) isServiceHealthy(ctx context.Context, project *types.Project, service string, fallbackRunning bool) (bool, error) { | ||
| containers, err := s.getContainers(ctx, project.Name, oneOffExclude, false, service) | ||
| if err != nil { | ||
| return false, err | ||
|
|
@@ -516,6 +526,11 @@ func (s *composeService) isServiceHealthy(ctx context.Context, project *types.Pr | |
| if err != nil { | ||
| return false, err | ||
| } | ||
| if container.Config.Healthcheck == nil && fallbackRunning { | ||
| // Container does not define a health check, but we can fall back to "running" state | ||
| return container.State != nil && container.State.Status == "running", nil | ||
| } | ||
|
|
||
| if container.State == nil || container.State.Health == nil { | ||
| return false, fmt.Errorf("container for service %q has no healthcheck configured", service) | ||
| } | ||
|
|
@@ -544,7 +559,7 @@ func (s *composeService) isServiceCompleted(ctx context.Context, project *types. | |
| } | ||
|
|
||
| func (s *composeService) startService(ctx context.Context, project *types.Project, service types.ServiceConfig) error { | ||
| err := s.waitDependencies(ctx, project, service) | ||
| err := s.waitDependencies(ctx, project, service.DependsOn) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.