Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow crane to export schema 1 images #1704

Merged
merged 1 commit into from
May 18, 2023
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
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