Repository navigation
feat: store full reference in ref.name during oras backup - #1904
Conversation
Signed-off-by: Austin Abro <[email protected]>
Signed-off-by: Austin Abro <[email protected]>
Signed-off-by: Austin Abro <[email protected]>
|
Hi @AustinAbro321 , This proposal from @shizhMSFT should help clarify the scenario and define the desired experience to add full image reference to anootations. Would you mind reviewing this PR? #1917 We should implement this with a more holistic design and consider multi-repo backup and restore scenario. |
|
Yup just gave it a review. It would solve what I'm looking for. Let me know you're preferred next steps. If you'd like I could implement the |
|
This PR is stale because it has been open 45 days with no activity. Remove stale label or comment or this will be closed in 30 days. |
|
This PR is stale because it has been open 45 days with no activity. Remove stale label or comment or this will be closed in 30 days. |
|
Hi Austin, nice to chat with you today. If you have the bandwidth, I think the new e2e tests threw off the indexes. I do not like they way they are fragile, but that is a topic for another PR. |
Rohilalala
left a comment
There was a problem hiding this comment.
Thanks for picking this up, Austin. Having the full reference in a backup would be really handy.
I ran it locally and hit a side effect. oras pull treats anything carrying org.opencontainers.image.title as a file to save, so pulling --oci-layout backup:v1 now also writes the manifest JSON to ./localhost:5077/demo:v1, and it overwrites whatever is already there. Released oras clients do the same with backups made this way.
The title is also used as the display name in the progress output, so the root shows up as the full ref. I think that's what's failing the 16 backup/restore e2e tests Terry listed: I ran those specs against zot and got 16 "status output doesn't match" failures with this branch and none with main. So it's the names, not the indexes.
Since this was opened, #1917 landed with a --full-reference flag that stores the ref in org.opencontainers.image.ref.name instead. Would you be up for moving this toward that, single-repo only for now like you offered? I think it sidesteps both problems.
|
Hi @AustinAbro321, thanks for sticking with this one. I'd like to get it moving again, and I think the scope can be smaller than the #1917 proposal suggests. Why not Suggested approach: One correction: #1917 only merged the proposal doc, and
Single-repo only is fine for now, like you offered. Multi-repo can build on it later. Unit tests for the reference parsing in restore would be great, along with updated e2e expectations. Does that work for you? Happy to help with the e2e side if the status matching gets annoying. |
TerryHowe
left a comment
There was a problem hiding this comment.
Thanks for sticking with this, @AustinAbro321. The agreed design in docs/proposals/backup-restore-multi.md stores the full reference in org.opencontainers.image.ref.name rather than org.opencontainers.image.title. Moving to that also fixes the two problems Rohilalala found: oras pull writing the manifest to a path named after the reference, and the 16 e2e failures caused by the title renaming the root node in the status output.
One change from the proposal: please don't add the --full-reference flag. It was never implemented, and since backup/restore are experimental, backups should always store the full reference. #2358 updates the proposal to match.
The inline suggestions cover backup and its test. oras backup already calls Tag on the OCI store with the tag, and the store writes that value into ref.name, so passing the full reference there is enough. No annotation needs to be set by hand.
Restore also needs a change (outside this diff). oras restore currently uses each ref.name value from the layout as both the source and the destination tag (oras.Copy(ctx, srcOCI, tag, trackedDst, tag, ...)), so a full reference would fail at the push. Something like:
// tagFromRefName returns the tag stored in an org.opencontainers.image.ref.name value.
// Backups made by earlier versions store only the tag.
func tagFromRefName(name string) (string, error) {
if !strings.Contains(name, "/") {
return name, nil
}
ref, err := registry.ParseReference(name)
if err != nil {
return "", err
}
if err := ref.ValidateReferenceAsTag(); err != nil {
return "", fmt.Errorf("%q does not reference a tag: %w", name, err)
}
return ref.Reference, nil
}Then in runRestore:
- List the
ref.namevalues from the source layout. Keep the full value as the source reference and usetagFromRefNamefor the destination tag:oras.Copy(ctx, srcOCI, srcRef, trackedDst, dstTag, copyOpts)andrecursiveCopy(ctx, srcOCI, trackedDst, dstTag, roots[i], ...). - When the user names tags (
oras restore --input backup localhost:5000/repo:v1), match them againsttagFromRefName(...)instead of resolving them directly. A full-reference backup has no entry stored under the bare tagv1. - Report the destination tag in the metadata/status output so it stays the same as today.
- Fail if two entries in the backup produce the same tag. That can't happen with a single-repository backup, but it guards against multi-repository backups later.
Tests:
- A unit test for
tagFromRefName: tag-only,host/repo:tag, a host with a port (localhost:5000/repo:v1), and a digest reference, which should error. - An e2e round trip: backup → restore → the tag resolves in the destination registry.
- An e2e restore from a tag-only backup, so backups made by earlier versions keep working.
The branch is also behind main, which has since moved to oras-go v3 and split the backup loop out into doBackup. It merges cleanly, but a rebase would make CI meaningful. Happy to help with any of this.
Signed-off-by: Terry Howe <[email protected]>
oras restore now parses the tag out of each org.opencontainers.image.ref.name value instead of using the value as the destination tag. Backups created by earlier versions, which store only the tag, still restore. Tags named on the command line are matched against the parsed tags. Signed-off-by: Terry Howe <[email protected]>
oras backup now stores the full reference (e.g. localhost:5000/repo:v1) in org.opencontainers.image.ref.name, as described in docs/proposals/backup-restore-multi.md, and no longer sets org.opencontainers.image.title. The title is treated as a file name by oras pull and renamed the root node in the status output. Signed-off-by: Terry Howe <[email protected]>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1904 +/- ##
==========================================
+ Coverage 90.68% 90.73% +0.04%
==========================================
Files 156 156
Lines 6625 6681 +56
==========================================
+ Hits 6008 6062 +54
+ Misses 362 360 -2
- Partials 255 259 +4 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
registry.ParseReference and Reference.Reference are deprecated in oras-go v3. Signed-off-by: Terry Howe <[email protected]>
Backups store tagged artifacts under their full reference, which the --oci-layout <path>:<tag> form cannot address. Read the backup with --oci-layout-path and the full reference instead, and look up child images and referrers by digest. Signed-off-by: Terry Howe <[email protected]>
When tags are specified, oras restore now only checks the entries it restores, so an unparsable or duplicate entry for another tag no longer fails the whole restore. Restoring all tags still rejects them. Tag-only entries are validated as tags. oras backup now removes a tag-only entry for a tag it backs up, so backing up into an output created by an earlier version does not leave two entries that restore to the same tag. Signed-off-by: Terry Howe <[email protected]>
What this PR does / why we need it:
oras backupnow stores the full reference of each artifact (e.g.localhost:5000/repo:v1) inorg.opencontainers.image.ref.namein the backup'sindex.json, instead of only the tag. Tools that read backups, such as air-gap packaging tools, can then tell what each image was named when it was backed up. This followsdocs/proposals/backup-restore-multi.md, but without the--full-referenceflag: sincebackupandrestoreare experimental, backups always store the full reference. #2358 updates the proposal to match.An earlier version of this PR put the reference in
org.opencontainers.image.title. That was dropped, becauseoras pulltreats the title as a file name and the status output uses it as the node name.Tagon the OCI store, which writes it toref.name. No title annotation is set.ref.namevalue and pushes under that tag. Backups created by earlier versions, which store only the tag, still restore. Tags given on the command line are matched against the parsed tags. Restore fails if two stored references would restore to the same tag.ref.name, for restoring full-reference and tag-only backups, and for the backup'sindex.json. The e2e backup test now checks for the full reference, and a new e2e test restores a tag-only backup.Compatibility: earlier ORAS versions cannot restore backups created with this change, because they use the
ref.namevalue as the destination tag. Backups created by earlier versions can still be restored by this version.Which issue(s) this PR fixes
Fixes #1893
Please check the following list:
backup/restoreare experimental, so no major version bump