Browse Source

Avoid pulling same images multiple times ⚡️

Signed-off-by: Vedant Koditkar <[email protected]>
Vedant Koditkar 3 years ago
parent
commit
d62c9fe842
1 changed files with 30 additions and 1 deletions
  1. 30 1
      pkg/compose/pull.go

+ 30 - 1
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 {