Code Monkey home page Code Monkey logo

aioregistry's Introduction

AIORegistry

aioregistry is a Python library and CLI tool for inspecting and copying container image data from and between registries.

This library primarily focuses on being a useful tool for dealing with container image registries. It has very limited support for interpretation of the objects stored within.

Library usage

Find sub-manifest based on platform.

async with AsyncRegistryClient() as client:
    manifest_ref = parse_image_name("alpine")
    manifest = await client.manifest_download(manifest_ref)

    if isinstance(manifest, ManifestListV2S2):
        for sub_manifest in manifest.manifests:
            if sub_manifest.platform.architecture == "amd64":
                manifest_ref.ref = sub_manifest.digest
                manifest = await client.manifest_download(manifest_ref)
                break
        else:
            raise Exception("Found no matching platform")
    else:
        print("Not a manifest list")

Download layers of an image

for layer in manifest.layers:
    assert layer.media_type == "application/vnd.docker.image.rootfs.diff.tar.gzip"
    blob_ref = RegistryBlobRef(manifest_ref.registry, manifest_ref.repo, layer.digest)

    # For example we just download into memory. In practice don't do this.
    blob_data = io.BytesIO(
        b"".join([chunk async for chunk in client.ref_content_stream(blob_ref)])
    )
    with tarfile.open(mode="r|*", fileobj=blob_data) as tar:
        for tarinfo in tar.getmembers():
            print(tarinfo.name)

CLI copy tool

# By default it will pull credentials based on ~/.docker/config.json 
python -m aioregistry ubuntu:18.04 my.private.registry/my-repo:my-tag
# Copy all tags matching regex
python -m aioregistry ubuntu my.private.registry/my-repo --tag-pattern '18\..*'

aioregistry's People

Contributors

msg555 avatar

Stargazers

 avatar

aioregistry's Issues

Add support

If a registry presents a manifest in a non-canonical format we should still support correctly copying data. We'll need to do one of the following:

  • Store the original manifest encoding when parsing from an encoded version
  • Dynamically adjust the written manifest based on the updated digests of sub-objects

My preference is probably to do the former. We maybe should still support the latter, however, in case the destination registry attempts to reformat the digest.

Accessing images from AWS' public registry fails

Attempting to access any image stored on AWS' public registry fails attempting to acquire an access token.

Reproduce:

$ aioregistry public.ecr.aws/lambda/python:3.10
Traceback (most recent call last):
  File "/home/msg/proj/aioregistry/.venv/bin/aioregistry", line 8, in <module>
    sys.exit(sync_main())
  File "/home/msg/proj/aioregistry/aioregistry/cli.py", line 249, in sync_main
    return asyncio.run(main())
  File "/usr/lib/python3.10/asyncio/runners.py", line 44, in run
    return loop.run_until_complete(main)
  File "/usr/lib/python3.10/asyncio/base_events.py", line 649, in run_until_complete
    return future.result()
  File "/home/msg/proj/aioregistry/aioregistry/cli.py", line 133, in main
    return await _main(args)
  File "/home/msg/proj/aioregistry/aioregistry/cli.py", line 219, in _main
    result = _convert_object(await get_object(src_ref))
  File "/home/msg/proj/aioregistry/aioregistry/client.py", line 305, in manifest_download
    async with await self._request("GET", registry, ref.url) as response:
  File "/home/msg/proj/aioregistry/aioregistry/client.py", line 217, in _request
    self.access_tokens[auth_key] = (await auth_resp.json())["access_token"]
KeyError: 'access_token'

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.