Skip to content

Commit

Permalink
Preserve descriptors when writing to layout (#1400)
Browse files Browse the repository at this point in the history
We currently compute these manually, but that drops platform information
and annotations. Keep these instead so it's easy to put together an
index using crane pull.
  • Loading branch information
jonjohnsonjr committed Jun 29, 2022
1 parent 2b1087a commit 03194c5
Showing 1 changed file with 14 additions and 43 deletions.
57 changes: 14 additions & 43 deletions pkg/v1/layout/write.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,33 +45,17 @@ func (l Path) AppendImage(img v1.Image, options ...Option) error {
return err
}

mt, err := img.MediaType()
desc, err := partial.Descriptor(img)
if err != nil {
return err
}

d, err := img.Digest()
if err != nil {
return err
}

manifest, err := img.RawManifest()
if err != nil {
return err
}

desc := v1.Descriptor{
MediaType: mt,
Size: int64(len(manifest)),
Digest: d,
}

o := makeOptions(options...)
for _, opt := range o.descOpts {
opt(&desc)
opt(desc)
}

return l.AppendDescriptor(desc)
return l.AppendDescriptor(*desc)
}

// AppendIndex writes a v1.ImageIndex to the Path and updates
Expand All @@ -81,33 +65,17 @@ func (l Path) AppendIndex(ii v1.ImageIndex, options ...Option) error {
return err
}

mt, err := ii.MediaType()
desc, err := partial.Descriptor(ii)
if err != nil {
return err
}

d, err := ii.Digest()
if err != nil {
return err
}

manifest, err := ii.RawManifest()
if err != nil {
return err
}

desc := v1.Descriptor{
MediaType: mt,
Size: int64(len(manifest)),
Digest: d,
}

o := makeOptions(options...)
for _, opt := range o.descOpts {
opt(&desc)
opt(desc)
}

return l.AppendDescriptor(desc)
return l.AppendDescriptor(*desc)
}

// AppendDescriptor adds a descriptor to the index.json of the Path.
Expand Down Expand Up @@ -492,12 +460,15 @@ func (l Path) WriteIndex(ii v1.ImageIndex) error {
//
// The contents are written in the following format:
// At the top level, there is:
// One oci-layout file containing the version of this image-layout.
// One index.json file listing descriptors for the contained images.
//
// One oci-layout file containing the version of this image-layout.
// One index.json file listing descriptors for the contained images.
//
// Under blobs/, there is, for each image:
// One file for each layer, named after the layer's SHA.
// One file for each config blob, named after its SHA.
// One file for each manifest blob, named after its SHA.
//
// One file for each layer, named after the layer's SHA.
// One file for each config blob, named after its SHA.
// One file for each manifest blob, named after its SHA.
func Write(path string, ii v1.ImageIndex) (Path, error) {
lp := Path(path)
// Always just write oci-layout file, since it's small.
Expand Down

0 comments on commit 03194c5

Please sign in to comment.