regclient / regclient

Docker and OCI Registry Client in Go and tooling using those libraries.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[Issue] image mod will lose io.containerd.image.name annotation

qiuchengxuan opened this issue · comments

Current Behavior

jq result is empty

Expected Behavior

jq result is expected value

Steps To Reproduce

  1. regctl image mod python:2.7-slim-buster --annotation--create ocidir://python:2.7-slim-buster
  2. jq '.manifests[-1].annotations."io.containerd.image.name"' python/index.json

Explicitly specify annotation won't work too

  1. regctl image mod python:2.7-slim-buster --annotation io.containerd.image.name="docker.io/library/python:2.7-slim-buster" --create ocidir://python:2.7-slim-buster
  2. jq '.manifests[-1].annotations."io.containerd.image.name"' python/index.json

Version

VCSTag:     v0.6.1
VCSRef:     766ee6291f882778207ff42207f9ca8b1da54e57
VCSCommit:  766ee6291f882778207ff42207f9ca8b1da54e57
VCSState:   clean
VCSDate:    2024-05-14T13:18:19Z
Platform:   linux/amd64
GoVer:      go1.22.3
GoCompiler: gc

Environment

  • Running as binary or container: binary
  • Host platform: linux/amd64
  • Registry description: docker.io

regctl image mod is modifying the image, and the index.json file is a listing of images in the OCI Layout, not the image itself.

$ regctl manifest get ocidir://python:2.7-slim-buster --format '{{jsonPretty .}}'
{
  "schemaVersion": 2,
  "mediaType": "application/vnd.docker.distribution.manifest.list.v2+json",
  "manifests": [
    {
      "mediaType": "application/vnd.docker.distribution.manifest.v2+json",
      "digest": "sha256:b68d40df862ac07e8955ea0fc0c5454cb4245b6165e79bc8ea2cc69170d9ba62",
      "size": 1163,
      "platform": {
        "architecture": "amd64",
        "os": "linux"
      }
    },
    {
...
    }
  ],
  "annotations": {
    "io.containerd.image.name": "docker.io/library/python:2.7-slim-buster"
  }
}

Note that adding annotations on Docker manifests isn't technically correct, they aren't part of the Docker manifest spec, and only included in regclient to facilitate lossless translations between OCI and Docker media types.

For this scenario, I think you want regctl image export --name ...:

$ regctl image export --name docker.io/library/python:2.7-slim-buster ocidir://python:2.7-slim-buster python.tar

$ tar -xf python.tar --to-stdout index.json | jq .
{
  "schemaVersion": 2,
  "manifests": [
    {
      "mediaType": "application/vnd.docker.distribution.manifest.list.v2+json",
      "digest": "sha256:fa5ff060bb809b4f89a554be34fe291f94b0ace44fbf1fb5055ccb7309cdcd0a",
      "size": 1939,
      "annotations": {
        "io.containerd.image.name": "docker.io/library/python:2.7-slim-buster",
        "org.opencontainers.image.ref.name": "2.7-slim-buster"
      }
    }
  ]
}

regctl image mod is modifying the image, and the index.json file is a listing of images in the OCI Layout, not the image itself.

$ regctl manifest get ocidir://python:2.7-slim-buster --format '{{jsonPretty .}}'
{
  "schemaVersion": 2,
  "mediaType": "application/vnd.docker.distribution.manifest.list.v2+json",
  "manifests": [
    {
      "mediaType": "application/vnd.docker.distribution.manifest.v2+json",
      "digest": "sha256:b68d40df862ac07e8955ea0fc0c5454cb4245b6165e79bc8ea2cc69170d9ba62",
      "size": 1163,
      "platform": {
        "architecture": "amd64",
        "os": "linux"
      }
    },
    {
...
    }
  ],
  "annotations": {
    "io.containerd.image.name": "docker.io/library/python:2.7-slim-buster"
  }
}

Note that adding annotations on Docker manifests isn't technically correct, they aren't part of the Docker manifest spec, and only included in regclient to facilitate lossless translations between OCI and Docker media types.

For this scenario, I think you want regctl image export --name ...:

$ regctl image export --name docker.io/library/python:2.7-slim-buster ocidir://python:2.7-slim-buster python.tar

$ tar -xf python.tar --to-stdout index.json | jq .
{
  "schemaVersion": 2,
  "manifests": [
    {
      "mediaType": "application/vnd.docker.distribution.manifest.list.v2+json",
      "digest": "sha256:fa5ff060bb809b4f89a554be34fe291f94b0ace44fbf1fb5055ccb7309cdcd0a",
      "size": 1939,
      "annotations": {
        "io.containerd.image.name": "docker.io/library/python:2.7-slim-buster",
        "org.opencontainers.image.ref.name": "2.7-slim-buster"
      }
    }
  ]
}

Thanks for reply

I'm not simply exporting this image, but to modify this image (change layer compress format) and make a tarball for containerd to import

I tried export first and modify second, and image name annotation is gone

I tried export first and modify second, and image name annotation is gone

Try the other way around, modify it first, to a local OCI Layout (ocidir), and then export that.

I tried export first and modify second, and image name annotation is gone

Try the other way around, modify it first, to a local OCI Layout (ocidir), and then export that.

emm ok,thanks