MCPcopy
hub / github.com/docker/compose / pullRequiredImages

Method pullRequiredImages

pkg/compose/pull.go:293–349  ·  pkg/compose/pull.go::composeService.pullRequiredImages
(ctx context.Context, project *types.Project, images map[string]api.ImageSummary, quietPull bool)

Source from the content-addressed store, hash-verified

291}
292
293func (s *composeService) pullRequiredImages(ctx context.Context, project *types.Project, images map[string]api.ImageSummary, quietPull bool) error {
294 needPull := map[string]types.ServiceConfig{}
295 for name, service := range project.Services {
296 pull, err := mustPull(service, images)
297 if err != nil {
298 return err
299 }
300 if pull {
301 needPull[name] = service
302 }
303 for i, vol := range service.Volumes {
304 if vol.Type == types.VolumeTypeImage {
305 if _, ok := images[vol.Source]; !ok {
306 // Hack: create a fake ServiceConfig so we pull missing volume image
307 n := fmt.Sprintf("%s:volume %d", name, i)
308 needPull[n] = types.ServiceConfig{
309 Name: n,
310 Image: vol.Source,
311 }
312 }
313 }
314 }
315
316 }
317 if len(needPull) == 0 {
318 return nil
319 }
320
321 eg, ctx := errgroup.WithContext(ctx)
322 eg.SetLimit(s.maxConcurrency)
323 pulledImages := map[string]api.ImageSummary{}
324 var mutex sync.Mutex
325 for name, service := range needPull {
326 eg.Go(func() error {
327 id, err := s.pullServiceImage(ctx, service, quietPull, project.Environment["DOCKER_DEFAULT_PLATFORM"])
328 mutex.Lock()
329 defer mutex.Unlock()
330 pulledImages[name] = api.ImageSummary{
331 ID: id,
332 Repository: service.Image,
333 LastTagTime: time.Now(),
334 }
335 if err != nil && isServiceImageToBuild(service, project.Services) {
336 // image can be built, so we can ignore pull failure
337 return nil
338 }
339 return err
340 })
341 }
342 err := eg.Wait()
343 for i, service := range needPull {
344 if pulledImages[i].ID != "" {
345 images[service.Image] = pulledImages[i]
346 }
347 }
348 return err
349}
350

Callers 1

ensureImagesExistsMethod · 0.95

Calls 5

pullServiceImageMethod · 0.95
mustPullFunction · 0.85
isServiceImageToBuildFunction · 0.85
WaitMethod · 0.65
LockMethod · 0.45

Tested by

no test coverage detected