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

fix: update --add should add plain descriptor #1513

Merged
merged 3 commits into from
Oct 14, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
21 changes: 15 additions & 6 deletions cmd/oras/root/manifest/index/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,12 +153,9 @@
return nil, fmt.Errorf("%s is not a manifest", source)
}
opts.Println(status.IndexPromptFetched, source)
desc = descriptor.Plain(desc)
if descriptor.IsImageManifest(desc) {
desc.Platform, err = getPlatform(ctx, target, content)
if err != nil {
return nil, err
}
desc, err = enrichDescriptor(ctx, target, desc, content)
if err != nil {
wangxiaoxuan273 marked this conversation as resolved.
Show resolved Hide resolved
return nil, err

Check warning on line 158 in cmd/oras/root/manifest/index/create.go

View check run for this annotation

Codecov / codecov/patch

cmd/oras/root/manifest/index/create.go#L158

Added line #L158 was not covered by tests
}
resolved = append(resolved, desc)
}
Expand Down Expand Up @@ -209,3 +206,15 @@
}
return printer.Println("Digest:", desc.Digest)
}

func enrichDescriptor(ctx context.Context, target oras.ReadOnlyTarget, desc ocispec.Descriptor, manifestBytes []byte) (ocispec.Descriptor, error) {
desc = descriptor.Plain(desc)
if descriptor.IsImageManifest(desc) {
var err error
desc.Platform, err = getPlatform(ctx, target, manifestBytes)
if err != nil {
return ocispec.Descriptor{}, err

Check warning on line 216 in cmd/oras/root/manifest/index/create.go

View check run for this annotation

Codecov / codecov/patch

cmd/oras/root/manifest/index/create.go#L216

Added line #L216 was not covered by tests
}
}
return desc, nil
}
8 changes: 3 additions & 5 deletions cmd/oras/root/manifest/index/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,11 +181,9 @@
return nil, fmt.Errorf("%s is not a manifest", manifestRef)
}
printUpdateStatus(status.IndexPromptFetched, manifestRef, string(desc.Digest), opts.Printer)
if descriptor.IsImageManifest(desc) {
desc.Platform, err = getPlatform(ctx, target, content)
if err != nil {
return nil, err
}
desc, err = enrichDescriptor(ctx, target, desc, content)
if err != nil {
wangxiaoxuan273 marked this conversation as resolved.
Show resolved Hide resolved
return nil, err

Check warning on line 186 in cmd/oras/root/manifest/index/update.go

View check run for this annotation

Codecov / codecov/patch

cmd/oras/root/manifest/index/update.go#L186

Added line #L186 was not covered by tests
}
manifests = append(manifests, desc)
printUpdateStatus(status.IndexPromptAdded, manifestRef, string(desc.Digest), opts.Printer)
Expand Down
Loading