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

Push/Pull file example #341

Closed
yuvalturg opened this issue Oct 9, 2022 · 16 comments
Closed

Push/Pull file example #341

yuvalturg opened this issue Oct 9, 2022 · 16 comments
Labels
documentation Improvements or additions to documentation

Comments

@yuvalturg
Copy link

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!

@Wwwsylvia
Copy link
Member

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?

@yuvalturg
Copy link
Author

Yes a single layer is fine. Similar to what is described here https://oras.land/cli/1_pushing/

Oras push repo:tag /tmp/bigfile

@shizhMSFT shizhMSFT added the documentation Improvements or additions to documentation label Oct 13, 2022
@shizhMSFT
Copy link
Contributor

shizhMSFT commented Oct 13, 2022

@Wwwsylvia Could you write an example for @yuvalturg? Besides, we probably need content.NewDescriptorFromReader() to simplify the experience.

@yuvalturg
Copy link
Author

Thanks, I used oras-py, and it's as simple as
OrasClient().push(target, filenames)

@Wwwsylvia
Copy link
Member

@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
Copy link
Member

Wwwsylvia commented Oct 13, 2022

@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
Copy link
Author

@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!

@yuvalturg
Copy link
Author

@Wwwsylvia is there a way to get the local filename(s) from the filestore after pulling?

@Wwwsylvia
Copy link
Member

@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)
		}
	}

@yuvalturg
Copy link
Author

@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!

@Wwwsylvia
Copy link
Member

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.

@alishah730
Copy link

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.

@Wwwsylvia
Copy link
Member

We may want to add a few more examples into https://pkg.go.dev/oras.land/oras-go/v2@v2.0.0/content/file#pkg-examples.

@Wwwsylvia
Copy link
Member

The push/pull file example is now available at https://oras.land/client_libraries/0_go/#quick-start.

@Wwwsylvia
Copy link
Member

This is also tracked by #434

@shizhMSFT
Copy link
Contributor

Closed by #434

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

4 participants