Skip to content

Commit 3fba856

Browse files
committed
imagetools: avoid pushing to same repo in parallel
If multiple tags are specified for the same repo, it is wasteful to use them as separate targets and better to make them share the blob upload phase of the push. Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com> (cherry picked from commit 917d7f2)
1 parent d841330 commit 3fba856

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

commands/imagetools/create.go

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -200,27 +200,39 @@ func runCreate(ctx context.Context, dockerCli command.Cli, in createOptions, arg
200200
eg, _ := errgroup.WithContext(ctx)
201201
pw := progress.WithPrefix(printer, "internal", true)
202202

203+
tagsByRepo := map[string][]reference.Named{}
203204
for _, t := range tags {
205+
repo := t.Name()
206+
tagsByRepo[repo] = append(tagsByRepo[repo], t)
207+
}
208+
209+
for repo, repoTags := range tagsByRepo {
204210
eg.Go(func() error {
205-
return progress.Wrap(fmt.Sprintf("pushing %s", t.String()), pw.Write, func(sub progress.SubLogger) error {
211+
seed := repoTags[0]
212+
return progress.Wrap(fmt.Sprintf("pushing %s", repo), pw.Write, func(sub progress.SubLogger) error {
206213
baseCtx := ctx
207214
eg2, _ := errgroup.WithContext(ctx)
208215
for _, desc := range manifests {
209216
eg2.Go(func() error {
210217
ctx = withMediaTypeKeyPrefix(baseCtx)
211-
sub.Log(1, fmt.Appendf(nil, "copying %s from %s to %s\n", desc.Digest.String(), desc.Source.Ref.String(), t.String()))
218+
sub.Log(1, fmt.Appendf(nil, "copying %s from %s to %s\n", desc.Digest.String(), desc.Source.Ref.String(), repo))
212219
return r.Copy(ctx, &imagetools.Source{
213220
Ref: desc.Source.Ref,
214221
Desc: desc.Descriptor,
215-
}, t)
222+
}, seed)
216223
})
217224
}
218225
if err := eg2.Wait(); err != nil {
219226
return err
220227
}
221228
ctx = withMediaTypeKeyPrefix(ctx) // because of containerd bug this needs to be called separately for each ctx/goroutine pair to avoid concurrent map write
222-
sub.Log(1, fmt.Appendf(nil, "pushing %s to %s\n", desc.Digest.String(), t.String()))
223-
return r.Push(ctx, t, desc, dt)
229+
for _, t := range repoTags {
230+
sub.Log(1, fmt.Appendf(nil, "pushing %s to %s\n", desc.Digest.String(), t.String()))
231+
if err := r.Push(ctx, t, desc, dt); err != nil {
232+
return err
233+
}
234+
}
235+
return nil
224236
})
225237
})
226238
}

0 commit comments

Comments
 (0)