Skip to content

Commit a267595

Browse files
authored
Merge pull request #3632 from tonistiigi/v0.31.1-picks
[v0.31.1] cherry-picks
2 parents 44945d7 + 3fba856 commit a267595

2 files changed

Lines changed: 23 additions & 5 deletions

File tree

commands/imagetools/create.go

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -200,24 +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()))
212-
return r.Copy(ctx, desc.Source, t)
218+
sub.Log(1, fmt.Appendf(nil, "copying %s from %s to %s\n", desc.Digest.String(), desc.Source.Ref.String(), repo))
219+
return r.Copy(ctx, &imagetools.Source{
220+
Ref: desc.Source.Ref,
221+
Desc: desc.Descriptor,
222+
}, seed)
213223
})
214224
}
215225
if err := eg2.Wait(); err != nil {
216226
return err
217227
}
218228
ctx = withMediaTypeKeyPrefix(ctx) // because of containerd bug this needs to be called separately for each ctx/goroutine pair to avoid concurrent map write
219-
sub.Log(1, fmt.Appendf(nil, "pushing %s to %s\n", desc.Digest.String(), t.String()))
220-
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
221236
})
222237
})
223238
}

util/imagetools/create.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -429,6 +429,9 @@ func (r *Resolver) filterPlatforms(ctx context.Context, dt []byte, desc ocispecs
429429
// try to pull in attestation manifest via referrer if one exists
430430
addedRef := false
431431
for d := range matchedManifests {
432+
if _, ok := references[d]; ok { // manifest itself is already attestation
433+
continue
434+
}
432435
hasRef := false
433436
for _, subject := range references {
434437
if subject.Digest == d {

0 commit comments

Comments
 (0)