Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 21 additions & 4 deletions commands/imagetools/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,13 +240,12 @@ type descWithSource struct {
}

func filterPlatforms(dt []byte, desc ocispecs.Descriptor, srcMap map[digest.Digest]*imagetools.Source, plats []ocispecs.Platform) ([]byte, ocispecs.Descriptor, []descWithSource, error) {
if len(plats) == 0 {
return dt, desc, nil, nil
}

matcher := platforms.Any(plats...)

if !images.IsIndexType(desc.MediaType) {
if len(plats) == 0 {
return dt, desc, nil, nil
}
var mfst ocispecs.Manifest
if err := json.Unmarshal(dt, &mfst); err != nil {
return nil, ocispecs.Descriptor{}, nil, errors.Wrapf(err, "failed to parse manifest")
Expand All @@ -264,6 +263,24 @@ func filterPlatforms(dt []byte, desc ocispecs.Descriptor, srcMap map[digest.Dige
if err := json.Unmarshal(dt, &idx); err != nil {
return nil, ocispecs.Descriptor{}, nil, errors.Wrapf(err, "failed to parse index")
}
if len(plats) == 0 {
mfsts := make([]descWithSource, len(idx.Manifests))
for i, m := range idx.Manifests {
src, ok := srcMap[m.Digest]
if !ok {
defaultSource, ok := srcMap[desc.Digest]
if !ok {
return nil, ocispecs.Descriptor{}, nil, errors.Errorf("internal error: no source found for %s", m.Digest)
}
src = defaultSource
}
mfsts[i] = descWithSource{
Descriptor: m,
Source: src,
}
}
return dt, desc, mfsts, nil
}

manifestMap := map[digest.Digest]ocispecs.Descriptor{}
for _, m := range idx.Manifests {
Expand Down
1 change: 1 addition & 0 deletions util/imagetools/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ func (r *Resolver) Push(ctx context.Context, ref reference.Named, desc ocispecs.

func (r *Resolver) Copy(ctx context.Context, src *Source, dest reference.Named) error {
ctx = remotes.WithMediaTypeKeyPrefix(ctx, "application/vnd.in-toto+json", "intoto")
ctx = remotes.WithMediaTypeKeyPrefix(ctx, "application/vnd.oci.empty.v1+json", "empty")
Comment on lines 224 to +225
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to raise awareness, and in case it's relevant here and/or at some point; compose also defines a couple of media types for its artifacts, including an "empty" one; see https://github.com/docker/compose/blob/d9423f6872586c5cd9e1dd761bd5a8f02113a93c/internal/oci/push.go#L38-L60


// push by digest
p, err := r.resolver().Pusher(ctx, dest.Name())
Expand Down