From d62c9fe842dc66341fe79cd63a231a46fee81ab0 Mon Sep 17 00:00:00 2001 From: Vedant Koditkar Date: Mon, 14 Feb 2022 17:15:28 +0530 Subject: [PATCH] =?UTF-8?q?Avoid=20pulling=20same=20images=20multiple=20ti?= =?UTF-8?q?mes=20=E2=9A=A1=EF=B8=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Vedant Koditkar --- pkg/compose/pull.go | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/pkg/compose/pull.go b/pkg/compose/pull.go index 950ad3378..62fddbc4b 100644 --- a/pkg/compose/pull.go +++ b/pkg/compose/pull.go @@ -21,6 +21,7 @@ import ( "encoding/base64" "encoding/json" "errors" + "fmt" "io" "strings" @@ -59,16 +60,44 @@ func (s *composeService) pull(ctx context.Context, project *types.Project, opts eg, ctx := errgroup.WithContext(ctx) var mustBuild []string + + images, err := s.getLocalImagesDigests(ctx, project) + if err != nil { + return err + } + + imagesBeingPulled := map[string]string{} + for _, service := range project.Services { service := service if service.Image == "" { w.Event(progress.Event{ ID: service.Name, Status: progress.Done, - Text: "Skipped", + Text: "Skipped - No image to be pulled", }) continue } + + if _, ok := images[service.Image]; ok { + w.Event(progress.Event{ + ID: service.Name, + Status: progress.Done, + Text: "Skipped - Image is already present locally", + }) + continue + } + + if s, ok := imagesBeingPulled[service.Image]; ok { + w.Event(progress.Event{ + ID: service.Name, + Status: progress.Done, + Text: fmt.Sprintf("Skipped - Image is already being pulled by %v", s), + }) + continue + } + + imagesBeingPulled[service.Image] = service.Name eg.Go(func() error { err := s.pullServiceImage(ctx, service, info, s.configFile, w, false) if err != nil {