(ctx context.Context, project *types.Project, buildOpts *api.BuildOptions, quietPull bool)
| 108 | } |
| 109 | |
| 110 | func (s *composeService) ensureImagesExists(ctx context.Context, project *types.Project, buildOpts *api.BuildOptions, quietPull bool) error { |
| 111 | for name, service := range project.Services { |
| 112 | if service.Provider == nil && service.Image == "" && service.Build == nil { |
| 113 | return fmt.Errorf("invalid service %q. Must specify either image or build", name) |
| 114 | } |
| 115 | } |
| 116 | |
| 117 | images, err := s.getLocalImagesDigests(ctx, project) |
| 118 | if err != nil { |
| 119 | return err |
| 120 | } |
| 121 | |
| 122 | err = tracing.SpanWrapFunc("project/pull", tracing.ProjectOptions(ctx, project), |
| 123 | func(ctx context.Context) error { |
| 124 | return s.pullRequiredImages(ctx, project, images, quietPull) |
| 125 | }, |
| 126 | )(ctx) |
| 127 | if err != nil { |
| 128 | return err |
| 129 | } |
| 130 | |
| 131 | if buildOpts != nil { |
| 132 | err = tracing.SpanWrapFunc("project/build", tracing.ProjectOptions(ctx, project), |
| 133 | func(ctx context.Context) error { |
| 134 | builtImages, err := s.build(ctx, project, *buildOpts, images) |
| 135 | if err != nil { |
| 136 | return err |
| 137 | } |
| 138 | |
| 139 | for name, digest := range builtImages { |
| 140 | images[name] = api.ImageSummary{ |
| 141 | Repository: name, |
| 142 | ID: digest, |
| 143 | LastTagTime: time.Now(), |
| 144 | } |
| 145 | } |
| 146 | return nil |
| 147 | }, |
| 148 | )(ctx) |
| 149 | if err != nil { |
| 150 | return err |
| 151 | } |
| 152 | } |
| 153 | |
| 154 | // set digest as com.docker.compose.image label so we can detect outdated containers |
| 155 | for name, service := range project.Services { |
| 156 | image := api.GetImageNameOrDefault(service, project.Name) |
| 157 | img, ok := images[image] |
| 158 | if ok { |
| 159 | service.CustomLabels.Add(api.ImageDigestLabel, img.ID) |
| 160 | } |
| 161 | |
| 162 | resolveImageVolumes(&service, images, project.Name) |
| 163 | |
| 164 | project.Services[name] = service |
| 165 | } |
| 166 | return nil |
| 167 | } |
no test coverage detected