-
Notifications
You must be signed in to change notification settings - Fork 99
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
feat: add WithMount
method to support cross repository blob mounting
#632
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,6 +35,7 @@ import ( | |
"oras.land/oras-go/v2/content/memory" | ||
"oras.land/oras-go/v2/content/oci" | ||
"oras.land/oras-go/v2/internal/spec" | ||
"oras.land/oras-go/v2/registry" | ||
"oras.land/oras-go/v2/registry/remote" | ||
) | ||
|
||
|
@@ -215,6 +216,37 @@ func ExampleCopy_remoteToRemote() { | |
// sha256:7cbb44b44e8ede5a89cf193db3f5f2fd019d89697e6b87e8ed2589e60649b0d1 | ||
} | ||
|
||
func ExampleCopy_remoteToRemoteWithMount() { | ||
reg, err := remote.NewRegistry(remoteHost) | ||
if err != nil { | ||
panic(err) // Handle error | ||
} | ||
ctx := context.Background() | ||
src, err := reg.Repository(ctx, "source") | ||
if err != nil { | ||
panic(err) // Handle error | ||
} | ||
dst, err := reg.Repository(ctx, "target") | ||
if err != nil { | ||
panic(err) // Handle error | ||
} | ||
|
||
tagName := "latest" | ||
|
||
opts := oras.CopyOptions{} | ||
// Enable cross-repository blob mounting | ||
opts.WithMount("source", dst.(registry.Mounter), nil) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What will happen if other target instead of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's say the true destination target is There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we avoid that situation in the first place with a better API design? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What will happen if someone call There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a fun one. I think it would work and not produce an error (but I have not tried it). Let's call the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We could add a field to |
||
|
||
desc, err := oras.Copy(ctx, src, tagName, dst, tagName, opts) | ||
if err != nil { | ||
panic(err) // Handle error | ||
} | ||
fmt.Println("Final", desc.Digest) | ||
|
||
// Output: | ||
// Final sha256:7cbb44b44e8ede5a89cf193db3f5f2fd019d89697e6b87e8ed2589e60649b0d1 | ||
} | ||
|
||
func ExampleCopy_remoteToLocal() { | ||
reg, err := remote.NewRegistry(remoteHost) | ||
if err != nil { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if someone reuse
oras.CopyOptions
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The CopyOptions after a WithMount would only be usable when the same source and destination are not changed. That is not ideal. A shallow copy of the
oras.CopyOptions
before callingWithMount()
solves this problem. That is how I use this in my code.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be ideal if we would reuse the CopyOptions. Currently, only PackOptions is not re-usable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could change the signature of the
WithMount()
to return a modified copy of the receiver. It would not modify the receiver soopts
below could be reused. It would then be used like so:I think that would reduce the misuse and make it more obvious what it does.