Created
July 24, 2018 06:49
-
-
Save kunalkushwaha/7acb88cab7d2d1864fc1dac17b9c1aa9 to your computer and use it in GitHub Desktop.
Test program to content service.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package main | |
| import ( | |
| "context" | |
| "fmt" | |
| "github.com/containerd/containerd" | |
| "github.com/containerd/containerd/images" | |
| "github.com/containerd/containerd/namespaces" | |
| ) | |
| func main() { | |
| var ( | |
| ctx = context.Background() | |
| background = namespaces.WithNamespace(ctx, "background") | |
| address = "/run/containerd/containerd.sock" | |
| ) | |
| client, err := containerd.New(address) | |
| if err != nil { | |
| fmt.Println(err) | |
| return | |
| } | |
| cs := client.ContentStore() | |
| //Pull Image | |
| image, err := client.Pull(background, "docker.io/library/redis:alpine", containerd.WithPullUnpack) | |
| if err != nil { | |
| fmt.Println(err) | |
| return | |
| } | |
| index := image.Target() | |
| manifiests, err := images.Children(background, cs, index) | |
| if err != nil { | |
| fmt.Println(err) | |
| return | |
| } | |
| for _, manifest := range manifiests { | |
| Children, err := images.Children(background, cs, manifest) | |
| if err != nil { | |
| fmt.Println(err) | |
| return | |
| } | |
| for _, desc := range Children { | |
| ra, err := cs.ReaderAt(background, desc) | |
| if err != nil { | |
| fmt.Println(err) | |
| return | |
| } | |
| //Allocate more then size of data | |
| p := make([]byte, ra.Size()+int64(10)) | |
| readData, err := ra.ReadAt(p, 0) | |
| if err != nil { | |
| fmt.Println("Blob read error ", err) | |
| } | |
| fmt.Println(readData, p[:10]) | |
| ra.Close() | |
| } | |
| } | |
| return | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment