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

crane: add --flatten for index append #1566

Merged
merged 3 commits into from
Feb 23, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
40 changes: 36 additions & 4 deletions cmd/crane/cmd/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ func NewCmdIndexFilter(options *[]crane.Option) *cobra.Command {
func NewCmdIndexAppend(options *[]crane.Option) *cobra.Command {
var baseRef, newTag string
var newManifests []string
var dockerEmptyBase bool
var dockerEmptyBase, flatten bool

cmd := &cobra.Command{
Use: "append",
Expand Down Expand Up @@ -194,9 +194,40 @@ The platform for appended manifests is inferred from the config file or omitted
if err != nil {
return err
}
adds = append(adds, mutate.IndexAddendum{
Add: idx,
})
if flatten {
im, err := idx.IndexManifest()
if err != nil {
return err
}
for _, child := range im.Manifests {
switch {
case child.MediaType.IsImage():
img, err := idx.Image(child.Digest)
if err != nil {
return err
}
adds = append(adds, mutate.IndexAddendum{
Add: img,
Descriptor: child,
})
case child.MediaType.IsIndex():
idx, err := idx.ImageIndex(child.Digest)
if err != nil {
return err
}
adds = append(adds, mutate.IndexAddendum{
Add: idx,
Descriptor: child,
})
default:
return fmt.Errorf("unexpected child %q with media type %q", child.Digest, child.MediaType)
}
}
} else {
adds = append(adds, mutate.IndexAddendum{
Add: idx,
})
}
} else {
return fmt.Errorf("saw unexpected MediaType %q for %q", desc.MediaType, m)
}
Expand Down Expand Up @@ -229,6 +260,7 @@ The platform for appended manifests is inferred from the config file or omitted
cmd.Flags().StringVarP(&newTag, "tag", "t", "", "Tag to apply to resulting image")
cmd.Flags().StringSliceVarP(&newManifests, "manifest", "m", []string{}, "References to manifests to append to the base index")
cmd.Flags().BoolVar(&dockerEmptyBase, "docker-empty-base", false, "If true, empty base index will have Docker media types instead of OCI")
cmd.Flags().BoolVar(&flatten, "flatten", false, "If true, appending an index will append each of its children rather than the index itself")
jonjohnsonjr marked this conversation as resolved.
Show resolved Hide resolved

return cmd
}
Expand Down
1 change: 1 addition & 0 deletions cmd/crane/doc/crane_index_append.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions pkg/v1/zz_deepcopy_generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.