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

RFE: Make 'skopeo inspect' provide the size of the OCI image #641

Closed
debarshiray opened this issue Apr 26, 2019 · 18 comments
Closed

RFE: Make 'skopeo inspect' provide the size of the OCI image #641

debarshiray opened this issue Apr 26, 2019 · 18 comments
Labels
help wanted kind/feature A request for, or a PR adding, new functionality locked - please file new issue/PR volunteers-wanted Issues good for community/volunteer contributions

Comments

@debarshiray
Copy link
Member

debarshiray commented Apr 26, 2019

It would be nice if 'skopeo inspect' provided the size of the OCI image. It seems like useful information that one might want to have before pulling an image to avoid blowing the data cap or interfering with other network activity.

eg., it could be useful to implement containers/toolbox#134, but it's a different question whether one wants to add a dependency on another 20+ MB binary just for a bit of UI niceness. :)

@TomSweeneyRedHat
Copy link
Member

Thanks @debarshiray for the RFE.

debarshiray added a commit to containers/toolbox that referenced this issue Apr 26, 2019
Currently, there's no easy way to get the size of the impending
download. Skopeo doesn't offer the size of the OCI image [1] and it's
debatable whether another 23 MB binary ought to be pulled in as a
dependency just for this.

Given that the default fedora-toolbox images are the only base images
available via a public repository, the size of the download is hard
coded to reflect the approximate size of the fedora-toolbox images.
These images are between 451 MB and 483 MB, so 500 MB should be a
reasonably suggestive approximate that shouldn't negatively surprise
users.

[1] containers/skopeo#641

https://github.com/debarshiray/toolbox/issues/134
@TomSweeneyRedHat TomSweeneyRedHat changed the title Make 'skopeo inspect' provide the size of the OCI image RFE: Make 'skopeo inspect' provide the size of the OCI image Oct 7, 2020
@TomSweeneyRedHat TomSweeneyRedHat added the kind/feature A request for, or a PR adding, new functionality label Oct 7, 2020
@github-actions
Copy link

github-actions bot commented Jun 6, 2021

A friendly reminder that this issue had no activity for 30 days.

@infiniteregrets
Copy link

Any progress on this issue?
I think this would be a really nice feature to have! I tried skopeo using the following command:
skopeo inspect --override-os linux docker://registry.fedoraproject.org/fedora:latest

{
    "Name": "registry.fedoraproject.org/fedora",
    "Digest": "sha256:8b01cffca564ca914d5d3c8dc8c6eca12a755ee4d1d898e22e83ad7128fae256",
    "RepoTags": [
        "34-aarch64",
        "34-ppc64le",
        "34-x86_64",
        "34",
        "34-s390x",
        "34-armhfp",
        "33-armhfp",
        "32-armhfp",
        "35-aarch64",
        "35-ppc64le",
        "35-s390x",
        "35-x86_64",
        "35",
        "35-armhfp",
        "30-aarch64",
        "30-ppc64le",
        "30-s390x",
        "30-x86_64",
        "30",
        "latest",
        "rawhide",
        "30-armhfp",
        "31-aarch64",
        "31-x86_64",
        "31",
        "31-armhfp",
        "31-s390x",
        "31-ppc64le",
        "32-aarch64",
        "32-ppc64le",
        "32-s390x",
        "32-x86_64",
        "32",
        "33-aarch64",
        "33-ppc64le",
        "33-s390x",
        "33-x86_64",
        "33"
    ],
    "Created": "2021-06-11T05:48:31Z",
    "DockerVersion": "1.10.1",
    "Labels": {
        "license": "MIT",
        "name": "fedora",
        "vendor": "Fedora Project",
        "version": "34"
    },
    "Architecture": "amd64",
    "Os": "linux",
    "Layers": [
        "sha256:ca594071dfff2c0e563feabb63b1df444a7b76eac5be65103e6c047cec6eee3f"
    ],
    "Env": [
        "DISTTAG=f34container",
        "FGC=f34",
        "container=oci"
    ]
}

This does not render the size...
I tried looking at the source code but kinda got confused
But I think this is definitely possible. I tried to do this using the docker hub API using a script I wrote:

import asyncio
import aiohttp
import json

async def fetch(name=None):
    async with aiohttp.ClientSession() as session:
        async with session.get(f"https://hub.docker.com/v2/repositories/library/{name}/tags") as response:
            if response.status != 200:
                print('`Falied to fetch data | Try again later`')
                exit(1)
            data = await response.text()
            json_data = json.loads(str(data))
            for result in json_data["results"][:10]:
                print(name+':'+result["name"], round(result["full_size"]/(1048576),2))

asyncio.run(fetch(name="fedora"))

Results:

fedora:latest 61.92
fedora:rawhide 62.04
fedora:35 62.04
fedora:34 61.92
fedora:33 59.0
fedora:32 67.84
fedora:31 58.58
fedora:30 67.54
fedora:29 85.81
fedora:28 85.49

I am not completely sure how skopeo is doing it sorry, but having this would be very useful!

@mtrmac
Copy link
Contributor

mtrmac commented Jun 17, 2021

        async with session.get(f"https://hub.docker.com/v2/repositories/library/{name}/tags") as response:

That’s not a documented Registry API per https://github.com/distribution/distribution/blob/main/docs/spec/api.md . (But with new enough images we can get sizes of individual blobs, and sum that up.)


Overall, sure, a reasonable RFE.

Note: Compare also #1309 requesting sizes of individual layers, a rather more invasive output format change.

@infiniteregrets
Copy link

@mtrmac are you working on this? If not, could you please point me in the right direction where I will have to make changes?

@mtrmac
Copy link
Contributor

mtrmac commented Jun 25, 2021

I’m not working on this, PRs would be welcome.

There are two parts to this:

  • In containers/image, extend types.Image.Inspect to also provide sizes if known (without breaking API, otherwise should be trivial).
  • Design how to output this in skopeo inspect output, without breaking existing users and without repetition in the default format. This is the harder part. One alternative would be to make this data only available to the --format option, though that’s pretty ugly and hard to find. An extra option to output both the existing layer IDs and something with sizes? An extra option to report layer ID+sizes instead of the existing field?

@lsm5
Copy link
Member

lsm5 commented Sep 14, 2021

@infiniteregrets are you working on this?

@infiniteregrets
Copy link

@lsm5 I tried working on this, but got stuck so I just didnt try again. I would love to give it another try, but busy with school ): Sorry

@lsm5
Copy link
Member

lsm5 commented Sep 14, 2021

@infiniteregrets thanks and no worries. I'll assign a volunteers wanted but feel free to pick this up whenever you can.

@lsm5 lsm5 added the volunteers-wanted Issues good for community/volunteer contributions label Sep 14, 2021
@WarheadsSE
Copy link

A simple method of fetching this information (when the data is present) is with skopeo inspect --raw IMAGE | jq '[ .layers[].size ] | add'

Be aware that this will not work on a "mediaType": "application/vnd.docker.distribution.manifest.list.v2+json", such as docker://registry.docker.com/library/alpine:latest. For that, you will need to pull out the image manifest appropriate for you before performing the above query for that image.

$ skopeo inspect --raw docker://registry.docker.com/library/alpine:latest \
  | jq -r '.manifests[] | select(.platform.architecture == "amd64" and .platform.os == "linux") | .digest'
sha256:e7d88de73db3d3fd9b2d63aa7f447a10fd0220b7cbf39803c803f2af9ba256b3
$ skopeo inspect --raw docker://registry.docker.com/library/alpine@sha256:e7d88de73db3d3fd9b2d63aa7f447a10fd0220b7cbf39803c803f2af9ba256b3 \
  | jq -r '[ .layers[].size ] | add'
2818413

@github-actions
Copy link

A friendly reminder that this issue had no activity for 30 days.

@rhatdan
Copy link
Member

rhatdan commented Jul 28, 2022

Is the solution by @WarheadsSE Enough to close this?

@mtrmac
Copy link
Contributor

mtrmac commented Jul 28, 2022

No, why would it be?

containers/image#1608 is a possible first step.

@rhatdan
Copy link
Member

rhatdan commented Jul 28, 2022

I was asking the reporter. If you think it is important to implement then fine.

@mtrmac
Copy link
Contributor

mtrmac commented Aug 25, 2022

#1738 (see #1738 (comment) for an example) now provides individual layer sizes, if known.

@debarshiray
Copy link
Member Author

Is the solution by @WarheadsSE Enough to close this?

Yeah, the solution by @WarheadsSE might have been enough to improve Toolbx's UI. However, I am delighted that @ningmingxiao made it easier by removing one step because most of the images Toolbx deals with are application/vnd.docker.distribution.manifest.list.v2+json.

@debarshiray
Copy link
Member Author

#1738 (see #1738 (comment) for an example) now provides individual layer sizes, if known.

That's wonderful! I suppose this issue can now be closed, yes.

@mtrmac
Copy link
Contributor

mtrmac commented Aug 25, 2022

Thanks! Note that the individual layer size can be -1 if unknown (schema1 images)

@mtrmac mtrmac closed this as completed Aug 25, 2022
debarshiray pushed a commit to nievesmontero/toolbox that referenced this issue Mar 13, 2023
This uses 'skopeo inspect' to get the size of the image on the registry,
which is usually less than the size of the image in a local
containers/storage image store after download (eg., 'podman images'),
because they are kept compressed on the registry.  Skopeo >= 1.10.0 is
needed to retrieve the sizes [1].

However, this doesn't add a hard dependency on Skopeo to accommodate
size-constrained operating systems like Fedora CoreOS.  If skopeo(1) is
missing or too old, then the size of the image won't be shown, but
everything else would continue to work as before.

Some changes by Debarshi Ray.

[1] Skopeo commit d9dfc44888ff71a6
    containers/skopeo@d9dfc44888ff71a6
    containers/skopeo#641

containers#752

Signed-off-by: Nieves Montero <[email protected]>
debarshiray pushed a commit to nievesmontero/toolbox that referenced this issue Mar 14, 2023
This uses 'skopeo inspect' to get the size of the image on the registry,
which is usually less than the size of the image in a local
containers/storage image store after download (eg., 'podman images'),
because they are kept compressed on the registry.  Skopeo >= 1.10.0 is
needed to retrieve the sizes [1].

However, this doesn't add a hard dependency on Skopeo to accommodate
size-constrained operating systems like Fedora CoreOS.  If skopeo(1) is
missing or too old, then the size of the image won't be shown, but
everything else would continue to work as before.

Some changes by Debarshi Ray.

[1] Skopeo commit d9dfc44888ff71a6
    containers/skopeo@d9dfc44888ff71a6
    containers/skopeo#641

containers#752

Signed-off-by: Nieves Montero <[email protected]>
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 16, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
help wanted kind/feature A request for, or a PR adding, new functionality locked - please file new issue/PR volunteers-wanted Issues good for community/volunteer contributions
Projects
None yet
Development

No branches or pull requests

8 participants