Skip to content

Commit d62c9fe

Browse files
Avoid pulling same images multiple times ⚡️
Signed-off-by: Vedant Koditkar <[email protected]>
1 parent 10ca031 commit d62c9fe

File tree

1 file changed

+30
-1
lines changed

1 file changed

+30
-1
lines changed

pkg/compose/pull.go

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"encoding/base64"
2222
"encoding/json"
2323
"errors"
24+
"fmt"
2425
"io"
2526
"strings"
2627

@@ -59,16 +60,44 @@ func (s *composeService) pull(ctx context.Context, project *types.Project, opts
5960
eg, ctx := errgroup.WithContext(ctx)
6061

6162
var mustBuild []string
63+
64+
images, err := s.getLocalImagesDigests(ctx, project)
65+
if err != nil {
66+
return err
67+
}
68+
69+
imagesBeingPulled := map[string]string{}
70+
6271
for _, service := range project.Services {
6372
service := service
6473
if service.Image == "" {
6574
w.Event(progress.Event{
6675
ID: service.Name,
6776
Status: progress.Done,
68-
Text: "Skipped",
77+
Text: "Skipped - No image to be pulled",
6978
})
7079
continue
7180
}
81+
82+
if _, ok := images[service.Image]; ok {
83+
w.Event(progress.Event{
84+
ID: service.Name,
85+
Status: progress.Done,
86+
Text: "Skipped - Image is already present locally",
87+
})
88+
continue
89+
}
90+
91+
if s, ok := imagesBeingPulled[service.Image]; ok {
92+
w.Event(progress.Event{
93+
ID: service.Name,
94+
Status: progress.Done,
95+
Text: fmt.Sprintf("Skipped - Image is already being pulled by %v", s),
96+
})
97+
continue
98+
}
99+
100+
imagesBeingPulled[service.Image] = service.Name
72101
eg.Go(func() error {
73102
err := s.pullServiceImage(ctx, service, info, s.configFile, w, false)
74103
if err != nil {

0 commit comments

Comments
 (0)