Skip to content

feat(cp): support multiple platforms - #2191

Merged
TerryHowe merged 14 commits into
oras-project:mainfrom
Soundcreates:feat/cp-multiple-platforms
Sep 30, 2026
Merged

TerryHowe merged 14 commits into
oras-project:mainfrom
Soundcreates:feat/cp-multiple-platforms

Conversation

@Soundcreates

Copy link
Copy Markdown
Contributor

What this PR does / why we need it:

Add multi-platform selection to oras cp by accepting repeated or comma-separated --platform values. Single-platform behavior stays unchanged. Multiple selections require an OCI image index or Docker manifest list, preserve the original digest when every platform is selected, and create a filtered index for subsets. Variant and OS version matching is exact when specified, while omitted values act as wildcards. Recursive copies retain selected child referrers.

Which issue(s) this PR fixes:
Fixes #2163

Please check the following list:

  • Does the affected code have corresponding tests, e.g. unit test, E2E test?
  • Does this change require a documentation update? The CLI help now includes the multiple-platform form; no separate docs page was needed.
  • Does this introduce breaking changes that would require an announcement or bumping the major version?
  • Do all new files have an appropriate license header?

Testing:

  • go test ./...
  • go test -race ./...
  • go vet ./...
  • make check-encoding
  • cd test/e2e && go test -run '^$' ./suite/command
  • git diff --check

Signed-off-by: Shantanav Mukherjee <[email protected]>
@codecov

codecov Bot commented Sep 24, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 95.94096% with 11 lines in your changes missing coverage. Please review.
✅ Project coverage is 88.14%. Comparing base (a0cd4de) to head (a550283).
⚠️ Report is 7 commits behind head on main.

Files with missing lines Patch % Lines
cmd/oras/root/cp.go 95.33% 6 Missing and 5 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2191      +/-   ##
==========================================
+ Coverage   87.78%   88.14%   +0.36%     
==========================================
  Files         139      139              
  Lines        5714     6015     +301     
==========================================
+ Hits         5016     5302     +286     
- Misses        417      425       +8     
- Partials      281      288       +7     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Comment thread cmd/oras/root/cp.go Resolved
Comment thread cmd/oras/root/cp.go Resolved
Comment thread cmd/oras/root/cp.go Resolved
Comment thread cmd/oras/root/cp.go Resolved
Comment thread cmd/oras/root/cp.go Resolved
Comment thread cmd/oras/internal/option/platform.go Resolved
@TerryHowe

Copy link
Copy Markdown
Member

And the codecov I'm afraid.

@Soundcreates

Copy link
Copy Markdown
Contributor Author

I'll address all these changes and fix the reason codecov is failing

@Soundcreates

Copy link
Copy Markdown
Contributor Author

Addressed the maintainer feedback in commit c52e3ca:

  • improved the plain-manifest error and recommendation
  • preserved platform-less entries and associated attestations
  • preserved unknown index and descriptor fields
  • restored source unwrapping for cross-registry mounts and the Referrers API
  • made recursive subset referrer loss explicit with a warning
  • deduplicated repeated platform values

Focused tests, the full Go suite, race tests, vet, encoding validation, and the E2E command-package compile all pass. The refreshed GitHub checks are running now. Please take another look when you have time.

@Soundcreates
Soundcreates force-pushed the feat/cp-multiple-platforms branch from c78fe6e to c89e736 Compare September 25, 2026 03:18
@Soundcreates

Copy link
Copy Markdown
Contributor Author

Updated the branch to c89e736 with signed-off history, and the DCO check is now passing. The maintainer fixes and added coverage are preserved in this head. Please review the latest commit when convenient; the remaining GitHub checks are still running.

@TerryHowe TerryHowe left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the quick turnaround on the last round — the Unwrap hook, the conditional ReferrerLister wrapper, the raw-JSON index rewrite and the parse-time de-duplication all landed as discussed, and I've resolved those threads.

Re-reviewing the result at c89e736, the attestation carry-over added in c52e3ca interacts badly with the preserve-the-root fast path, so the digest guarantee in the PR description doesn't hold for buildx images. That plus a second digest issue are below, along with a handful of smaller things. I built the branch and ran the unit suite locally (green) before writing this.

The -r referrer thread stays open — the warning landed, but the e2e point in it hasn't been picked up yet.

Comment thread cmd/oras/root/cp.go Resolved
Comment thread cmd/oras/root/cp.go Resolved
Comment thread cmd/oras/root/cp.go Resolved
Comment thread cmd/oras/root/cp.go Resolved
Comment thread cmd/oras/root/cp.go Resolved
Comment thread cmd/oras/root/cp.go Resolved
Address the maintainer review and retain regression coverage.

Signed-off-by: Shantanav Mukherjee <[email protected]>
Refactor tests to use logrus for logging and update function signatures to include additional parameters.Add regression coverage for filtered indexes and recursive child referrers.

Signed-off-by: Shantanav Mukherjee <[email protected]>
Refactor ORAS command to match keywords for Linux AMD64 referrer.

Signed-off-by: Shantanav Mukherjee <[email protected]>
@Soundcreates

Copy link
Copy Markdown
Contributor Author

Thanks for the detailed review. I’ve pushed the fixes through 0d805fa: subset copies warn on stderr about source-index referrers, BuildKit attestations follow selected children, the original digest is preserved when no entries are removed, synthetic digests no longer rewrite the source reference, and the JSON rewrite preserves field order while reusing the fetched index. I also added the child-referrer e2e assertion and the unmatched-platform recommendation. Local full and race tests, vet, encoding checks, and e2e package compilation pass. CI is still running on the new head. Could you take another look once those checks finish?

Query the selected linux/amd64 manifest digest so discovery checks the child-level referrer copied by recursive multi-platform cp.

Signed-off-by: Shantanav Mukherjee <[email protected]>
Signed-off-by: Shantanav Mukherjee <[email protected]>
Signed-off-by: Shantanav Mukherjee <[email protected]>
@Soundcreates

Copy link
Copy Markdown
Contributor Author

Added regression coverage in 881d3e8 and 979812c for platform parsing errors, CLI selection, malformed and duplicate index entries, copy error paths, and the filtered-index path. go test ./..., go test -race ./..., go vet ./..., make check-encoding, and E2E command package compilation passed locally. On 979812c, Vulnerability Check, License Checker, and golangci-lint are green; build, e2e-k8s, and CodeQL are still running. I will verify the Codecov patch-coverage report when CI finishes.

@Soundcreates

Copy link
Copy Markdown
Contributor Author

Update: CI is now green on 979812c, including build, e2e-k8s, CodeQL, lint, license, and vulnerability checks. Codecov reports 95.70% patch coverage against an 80% target and 88.13% project coverage against a 75% target. The added regression tests brought patch coverage above the threshold. Could you take another look?

@TerryHowe TerryHowe left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-reviewed at 979812c. Everything from the previous two rounds landed and I verified each one empirically against hand-built OCI layouts: raw-JSON field and key-order preservation, buildx attestation carry-over, digest preservation on full selection, rootInSource=false, the stderr warning, Unwrap, the oerrors.Error on unmatched platforms, and parse-time de-duplication. I also built the branch and ran the unit suite, go vet and golangci-lint — all green.

One new correctness bug, with a ready-to-apply fix in the suggestions below: platform filtering matches index entries by descriptor equality, so an index that lists one manifest under several platforms copies platforms the user did not select. The suggestions are one patch split across hunks — applying all of them together compiles; applying a subset will not.

Two smaller things that are not blocking:

  • cp.go:207 — fmt.Errorf("failed to resolve %s: %w", opts.From.Reference, err) drops the source attribution every other cp path gives, and prints the parsed reference rather than what the user typed. Same layout, same missing tag, only the platform count differs:

    $ oras cp … src:nope dst:v1 --platform linux/amd64             # today
    Error from source oci-layout for "src:nope": not found
    $ oras cp … src:nope dst:v1 --platform linux/amd64,linux/arm64  # this PR
    Error: failed to resolve nope: not found
    

    oras.Copy returns an *oras.CopyError with Origin: Source, which is what BinaryTarget.ModifyError keys on for that prefix. Returning err unwrapped, or wrapping in an *oras.CopyError with Origin: oras.CopyErrorOriginSource, restores it. (doCopy's -r branch has the same wart today, but that one is pre-existing and -r is Preview; this regresses the default path.)

  • cp.go:259 — availablePlatforms includes buildx attestation entries, so the recommendation advertises pseudo-platforms, once per attestation:

    Error: unmatched platforms: [linux/s390x]
    available platforms in index: [linux/amd64, linux/arm64, linux/arm/v7, unknown/unknown, unknown/unknown]
    

    Skipping entries carrying dockerReferenceDigestAnnotation, and de-duplicating, keeps the list to things worth typing.

The raw-JSON rewrite is holding up well — I confirmed source key order, platform.features, descriptor urls and an unknown top-level x-vendor-extension all survive byte-identically into the filtered index. Nice work on that one.

Comment thread cmd/oras/root/cp.go Resolved
Comment thread cmd/oras/root/cp.go Resolved
Comment thread cmd/oras/root/cp.go Resolved
Comment thread cmd/oras/root/cp.go Resolved
Comment thread cmd/oras/root/cp.go Resolved
Comment thread cmd/oras/root/cp.go Resolved
Comment thread cmd/oras/root/cp.go Resolved
Comment thread cmd/oras/root/cp.go Resolved

@TerryHowe TerryHowe left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-reviewed at 12a3028. Position-based filtering, the de-duplicated recommendation list and the *oras.CopyError on resolve all landed — I built the branch, ran the unit suites (green) and re-verified each fix empirically against hand-built OCI layouts, including kept = [0 2] for an index that lists one manifest under two variants.

Requesting changes for one leftover from the last round (cp.go:246, a one-line fix), plus a few smaller notes inline. Nothing here is a correctness bug in the filtering itself; the recursive-subset behavior is exactly as documented — with referrers on the amd64 child, the s390x child and the index, cp -r --platform linux/amd64,linux/arm64 copied the amd64 referrer and dropped the other two.

Comment thread cmd/oras/root/cp.go Resolved
Comment thread cmd/oras/root/cp.go Resolved
Comment thread cmd/oras/root/cp.go Resolved
Comment thread cmd/oras/root/cp.go Resolved
Comment thread cmd/oras/internal/option/platform.go Resolved

@TerryHowe TerryHowe left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-reviewed at 12a3028. All three points from the last round landed and I verified each empirically against hand-built OCI layouts: positional filtering now drops the unselected entry when one manifest digest is listed under two platforms, the source-origin prefix is back on the resolve error, and the recommendation no longer advertises attestation pseudo-platforms. The raw-JSON rewrite continues to reproduce the source digest byte-for-byte on full selection.

Three things below. The e2e gap on -r and the always-on warning are two halves of the same problem: referrer loss on a subset copy is real, and right now it is neither tested nor honestly reported.

Unit suite, go vet and a build are green on this head.

Comment thread cmd/oras/root/cp.go Resolved
Comment thread cmd/oras/root/cp.go Resolved
Comment thread cmd/oras/root/cp.go Resolved
Comment thread cmd/oras/root/cp.go Resolved
Comment thread cmd/oras/root/cp.go Resolved

@TerryHowe TerryHowe left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/lgtm

@TerryHowe
TerryHowe merged commit 715917d into oras-project:main Sep 30, 2026
10 checks passed
@TerryHowe

Copy link
Copy Markdown
Member

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support copying artifacts across multiple platforms (pick up stale PR #1954)

2 participants