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

New OCIStore #108

Merged
merged 6 commits into from
Aug 9, 2019
Merged

New OCIStore #108

merged 6 commits into from
Aug 9, 2019

Conversation

shizhMSFT
Copy link
Contributor

Resolves #107

Example usage:

func demo() error {
	ref := "localhost:5000/oras:test"
	ctx := context.Background()
	resolver := docker.NewResolver(docker.ResolverOptions{})

	store, err := content.NewOCIStore("store")
	if err != nil {
		return err
	}
	desc, _, err := oras.Pull(ctx, resolver, ref, nil,
		oras.WithContentProvideIngester(store),
		oras.WithPullEmptyNameAllowed(),
	)
	if err != nil {
		return err
	}

	store.AddReference(ref, desc)
	return store.SaveIndex()
}

It stores pulled content in the store folder as

store
├── blobs
│   └── sha256
│       ├── 03ba204e50d126e4674c005e04d82e84c21366780af1f43bd54a37816b6ab340
│       ├── 130c6b42d2ea0bbf0cc727aa2c2c193d1550e84b62202efbc1f24b5adddebd30
│       └── 44136fa355b3678a1146ad16f7e8649e94fb4fc21fe77e8310c060f61caaff8a
├── index.json
├── ingest
└── oci-layout

where ingest is a folder generated by containerd.

The file contents are shown as follows:

  • oci-layout after formatting:
{
    "imageLayoutVersion": "1.0.0"
}
  • index.json after formatting:
{
    "schemaVersion": 2,
    "manifests": [
        {
            "mediaType": "application/vnd.oci.image.manifest.v1+json",
            "digest": "sha256:130c6b42d2ea0bbf0cc727aa2c2c193d1550e84b62202efbc1f24b5adddebd30",
            "size": 397,
            "annotations": {
                "org.opencontainers.image.ref.name": "localhost:5000/oras:test"
            }
        }
    ]
}
  • The manifest blobs/sha256/130c6b42d2ea0bbf0cc727aa2c2c193d1550e84b62202efbc1f24b5adddebd30 after formatting:
{
    "schemaVersion": 2,
    "config": {
        "mediaType": "application/vnd.oci.image.config.v1+json",
        "digest": "sha256:44136fa355b3678a1146ad16f7e8649e94fb4fc21fe77e8310c060f61caaff8a",
        "size": 2
    },
    "layers": [
        {
            "mediaType": "application/vnd.oci.image.layer.v1.tar",
            "digest": "sha256:03ba204e50d126e4674c005e04d82e84c21366780af1f43bd54a37816b6ab340",
            "size": 13,
            "annotations": {
                "org.opencontainers.image.title": "hello.txt"
            }
        }
    ]
}
  • The manifest config blobs/sha256/44136fa355b3678a1146ad16f7e8649e94fb4fc21fe77e8310c060f61caaff8a:
{}
  • The actual content blobs/sha256/03ba204e50d126e4674c005e04d82e84c21366780af1f43bd54a37816b6ab340:
Hello World!

The options

  • oras.WithContentProvideIngester(store) allows pulling manifest or manifest index.
  • oras.WithPullEmptyNameAllowed() allows pulling unnamed blobs.

If the option oras.WithAllowedMediaType() is not specified, setting both options basically dumps the remote image to the local file system. Try pull docker.io/library/hello-world:latest if interested.

@jdolitsky
Copy link
Contributor

/test

Copy link
Contributor

@jdolitsky jdolitsky left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

excellent shiwei!

@jdolitsky jdolitsky merged commit b285197 into master Aug 9, 2019
@shizhMSFT shizhMSFT deleted the shizh/oci_store branch August 26, 2019 06:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add new store that complies with OCI Image Layout Spec
2 participants