oras-go icon indicating copy to clipboard operation
oras-go copied to clipboard

Push/Pull file example

Open yuvalturg opened this issue 3 years ago • 11 comments
trafficstars

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!

yuvalturg avatar Oct 09 '22 14:10 yuvalturg

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?

Wwwsylvia avatar Oct 11 '22 09:10 Wwwsylvia

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

Oras push repo:tag /tmp/bigfile

yuvalturg avatar Oct 11 '22 15:10 yuvalturg

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

shizhMSFT avatar Oct 13 '22 01:10 shizhMSFT

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

yuvalturg avatar Oct 13 '22 06:10 yuvalturg

@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 avatar Oct 13 '22 10:10 Wwwsylvia

@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. 🤔

Wwwsylvia avatar Oct 13 '22 10:10 Wwwsylvia

@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 avatar Oct 13 '22 14:10 yuvalturg

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

yuvalturg avatar Oct 16 '22 10:10 yuvalturg

@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 avatar Oct 17 '22 03:10 Wwwsylvia

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

yuvalturg avatar Oct 17 '22 13:10 yuvalturg

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.

Wwwsylvia avatar Oct 18 '22 12:10 Wwwsylvia

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.

alishah730 avatar Jan 29 '23 18:01 alishah730

We may want to add a few more examples into https://pkg.go.dev/oras.land/oras-go/[email protected]/content/file#pkg-examples.

Wwwsylvia avatar Jan 31 '23 08:01 Wwwsylvia

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

Wwwsylvia avatar Mar 02 '23 07:03 Wwwsylvia

This is also tracked by #434

Wwwsylvia avatar Mar 02 '23 07:03 Wwwsylvia

Closed by #434

shizhMSFT avatar Mar 22 '23 08:03 shizhMSFT