(ctx context.Context, projectName string, options api.StartOptions, listener api.ContainerEventListener)
| 35 | } |
| 36 | |
| 37 | func (s *composeService) start(ctx context.Context, projectName string, options api.StartOptions, listener api.ContainerEventListener) error { |
| 38 | project := options.Project |
| 39 | if project == nil { |
| 40 | var containers Containers |
| 41 | containers, err := s.getContainers(ctx, projectName, oneOffExclude, true) |
| 42 | if err != nil { |
| 43 | return err |
| 44 | } |
| 45 | |
| 46 | project, err = s.projectFromName(containers, projectName, options.AttachTo...) |
| 47 | if err != nil { |
| 48 | return err |
| 49 | } |
| 50 | } |
| 51 | |
| 52 | res, err := s.apiClient().ContainerList(ctx, client.ContainerListOptions{ |
| 53 | Filters: projectFilter(project.Name).Add("label", oneOffFilter(false)), |
| 54 | All: true, |
| 55 | }) |
| 56 | if err != nil { |
| 57 | return err |
| 58 | } |
| 59 | containers := Containers(res.Items) |
| 60 | |
| 61 | err = InDependencyOrder(ctx, project, func(c context.Context, name string) error { |
| 62 | service, err := project.GetService(name) |
| 63 | if err != nil { |
| 64 | return err |
| 65 | } |
| 66 | |
| 67 | return s.startService(ctx, project, service, containers, listener, options.WaitTimeout) |
| 68 | }) |
| 69 | if err != nil { |
| 70 | return err |
| 71 | } |
| 72 | |
| 73 | if options.Wait { |
| 74 | depends := types.DependsOnConfig{} |
| 75 | for _, s := range project.Services { |
| 76 | depends[s.Name] = types.ServiceDependency{ |
| 77 | Condition: getDependencyCondition(s, project), |
| 78 | Required: true, |
| 79 | } |
| 80 | } |
| 81 | if options.WaitTimeout > 0 { |
| 82 | withTimeout, cancel := context.WithTimeout(ctx, options.WaitTimeout) |
| 83 | ctx = withTimeout |
| 84 | defer cancel() |
| 85 | } |
| 86 | |
| 87 | err = s.waitDependencies(ctx, project, project.Name, depends, containers, 0) |
| 88 | if err != nil { |
| 89 | if errors.Is(ctx.Err(), context.DeadlineExceeded) { |
| 90 | return fmt.Errorf("application not healthy after %s", options.WaitTimeout) |
| 91 | } |
| 92 | return err |
| 93 | } |
| 94 | } |
no test coverage detected