Skip to content

Commit

Permalink
Allow crane to export schema 1 images (#1704)
Browse files Browse the repository at this point in the history
  • Loading branch information
jonjohnsonjr committed May 18, 2023
1 parent b7ad3f1 commit 0ec36ad
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
13 changes: 12 additions & 1 deletion cmd/crane/cmd/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,21 @@ func NewCmdExport(options *[]crane.Option) *cobra.Command {
return fmt.Errorf("reading tarball from stdin: %w", err)
}
} else {
img, err = crane.Pull(src, *options...)
desc, err := crane.Get(src, *options...)
if err != nil {
return fmt.Errorf("pulling %s: %w", src, err)
}
if desc.MediaType.IsSchema1() {
img, err = desc.Schema1()
if err != nil {
return fmt.Errorf("pulling schema 1 image %s: %w", src, err)
}
} else {
img, err = desc.Image()
if err != nil {
return fmt.Errorf("pulling Image %s: %w", src, err)
}
}
}

return crane.Export(img, f)
Expand Down
5 changes: 5 additions & 0 deletions pkg/crane/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ func getManifest(r string, opt ...Option) (*remote.Descriptor, error) {
return remote.Get(ref, o.Remote...)
}

// Get calls remote.Get and returns an uninterpreted response.
func Get(r string, opt ...Option) (*remote.Descriptor, error) {
return getManifest(r, opt...)
}

// Head performs a HEAD request for a manifest and returns a content descriptor
// based on the registry's response.
func Head(r string, opt ...Option) (*v1.Descriptor, error) {
Expand Down

0 comments on commit 0ec36ad

Please sign in to comment.