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

Image Index support #108

Open
miker985 opened this issue Oct 5, 2023 · 3 comments
Open

Image Index support #108

miker985 opened this issue Oct 5, 2023 · 3 comments

Comments

@miker985
Copy link
Contributor

miker985 commented Oct 5, 2023

As of 0.1.25 it doesn't appear to me this supports Image Indexes.

The lift looks small - maybe as little as adding a media type to defaults.py, a schemas.py definition, and minor work to support it in the Registry object

Sample code might be

class Registry(oras.provider.Registry):
    """
    Oras registry with support for image indexes.
    """

    @decorator.ensure_container
    def get_image_index(self, container, allowed_media_type=None):
        """
        Get an image index as a manifest.

        This is basically Registry.get_manifest with the following changes

        - different default allowed_media_type
        - no JSON schema validation
        """
        if not allowed_media_type:
            default_image_index_media_type = "application/vnd.oci.image.index.v1+json"  # TODO: need this in defaults.py
            allowed_media_type = [default_image_index_media_type]

        headers = {"Accept": ";".join(allowed_media_type)}

        manifest_url = f"{self.prefix}://{container.manifest_url()}"
        response = self.do_request(manifest_url, "GET", headers=headers)
        self._check_200_response(response)
        manifest = response.json()
        # TODO: jsonschema.validate(manifest, schema=...)
        return manifest

If there's interest please let me know and I can put in a PR. In that case I ask if a new method like get_image_index is desired or if something else would be preferred.

In any case, thank you for the project!

@vsoch
Copy link
Contributor

vsoch commented Oct 5, 2023

Perhaps under examples https://github.com/oras-project/oras-py/tree/main/examples would suffice? Can you give me the use case of doing this?

@miker985
Copy link
Contributor Author

miker985 commented Oct 5, 2023

My use case is downloading an image index, selecting a platform-compatible manifest, and then following that to ultimately download a platform-specific artifact.

@vsoch
Copy link
Contributor

vsoch commented Oct 5, 2023

That would be a great (full) example script if you are up for it!

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

No branches or pull requests

2 participants