oras-go
oras-go copied to clipboard
Push/Pull file example
Hi,
Is there an example for a simple push-pull of a single, large (can't load it's entire content to memory) file to a repository?
Thanks!
Hi @yuvalturg, can you elaborate your scenario a little bit?
- Do you want to push/pull the file as a single blob?
- Do you want to have a manifest to reference this blob (file)?
Basically, how do you want to access this file after you pushing it to a repository?
Yes a single layer is fine. Similar to what is described here https://oras.land/cli/1_pushing/
Oras push repo:tag /tmp/bigfile
@Wwwsylvia Could you write an example for @yuvalturg? Besides, we probably need content.NewDescriptorFromReader() to simplify the experience.
Thanks, I used oras-py, and it's as simple as OrasClient().push(target, filenames)
@yuvalturg OK you will need a manifest to reference your file blob if you want to access it via a tag. Can you check if this helps? https://github.com/Wwwsylvia/demo-push-file/blob/main/main/main.go Please let us know if you find any bugs or any bad user experiences.
@Wwwsylvia Could you write an example for @yuvalturg? Besides, we probably need
content.NewDescriptorFromReader()to simplify the experience.
Not really, I think a file store is needed anyway in this case. 🤔
@yuvalturg OK you will need a manifest to reference your file blob if you want to access it via a tag. Can you check if this helps? https://github.com/Wwwsylvia/demo-push-file/blob/main/main/main.go Please let us know if you find any bugs or any bad user experiences.
This is great, I tried to that exactly that but I was missing fs.Tag() so I couldn't figure out how to make this work. Thanks a lot!
@Wwwsylvia is there a way to get the local filename(s) from the filestore after pulling?
@Wwwsylvia is there a way to get the local filename(s) from the filestore after pulling?
@yuvalturg Regarding "get the local filename(s) from the filestore", my understanding is that you want to check the filenames associated with the pulled tag? Does the below code work for you?
desc, err := fs.Resolve(ctx, tag)
if err != nil {
panic(err)
}
blobs, err := content.Successors(ctx, fs, desc)
if err != nil {
panic(err)
}
for _, b := range blobs {
if name := b.Annotations[v1.AnnotationTitle]; name != "" {
fmt.Println("filename: ", name)
}
}
@Wwwsylvia is there a way to get the local filename(s) from the filestore after pulling?
@yuvalturg Regarding "get the local filename(s) from the filestore", my understanding is that you want to check the filenames associated with the pulled tag? Does the below code work for you?
desc, err := fs.Resolve(ctx, tag) if err != nil { panic(err) } blobs, err := content.Successors(ctx, fs, desc) if err != nil { panic(err) } for _, b := range blobs { if name := b.Annotations[v1.AnnotationTitle]; name != "" { fmt.Println("filename: ", name) } }
This works perfectly, thanks!
Hello @yuvalturg, do you have any feedbacks on the user experiences of oras-go?
For instance, do you think file.PackFiles() is useful? We are revisiting this function and are considering whether to keep/refactor/deprecate in the future versions.
I can simply push any file using oras cli like below
oras push file.rpm demo.goharbor.io/oras/test:latest
I can't simply find any example using oras-go.
We may want to add a few more examples into https://pkg.go.dev/oras.land/oras-go/[email protected]/content/file#pkg-examples.
The push/pull file example is now available at https://oras.land/client_libraries/0_go/#quick-start.
This is also tracked by #434
Closed by #434