canonical / rockcraft

Tool to create OCI Images using the language from Snapcraft and Charmcraft.
GNU General Public License v3.0
37 stars 44 forks source link

allow adding customized label #582

Open henrymao-zz opened 5 months ago

henrymao-zz commented 5 months ago

What needs to get done

We should be able to add a customized label to rockcraft built images.

The label I need to add is a short json string "com.azure.sonic.manifest" as in the following example, which is used to maintain docker startup dependencies, and will be eventually be used by systemd. (Same thing docker works by using LABEL instruction in Dockerfile or adding the --label flag to a docker build command.)


$ sudo skopeo inspect docker-archive:docker-teamd.gz
{
    "Digest": "sha256:cb2f3c599f2efcc3de8a2028789aa1dca789c21043496d68806d04c23737e2be",
    "RepoTags": [],
    "Created": "2024-06-08T06:56:12.6356677Z",
    "DockerVersion": "",
    "Labels": {
        "Tag": "feature_jammy_build.0-d7d4f89ec",
        "com.azure.sonic.manifest": "\n{\n    \"version\": \"1.0.0\",\n    \"package\": {\n        \"version\": \"1.0.0\",\n        \"depends\": [],\n        \"name\": \"teamd\"\n    },\n    \"service\": {\n        \"name\": \"teamd\",\n        \"requires\": [],\n        \"after\": [],\n        \"before\": [],\n        \"dependent-of\": [],\n        \"asic-service\": true,\n        \"host-service\": false,\n        \"warm-shutdown\": {\n            \"after\": [\"swss\"],\n            \"before\": [\"syncd\"]\n        },\n        \"fast-shutdown\": {\n            \"after\": [\"swss\"],\n            \"before\": [\"syncd\"]\n        },\n        \"syslog\": {\n            \"support-rate-limit\": true\n        }\n    },\n    \"container\": {\n        \"privileged\": false,\n        \"volumes\": [],\n        \"tmpfs\": []\n    },\n    \"cli\": {\n        \"config\": \"\",\n        \"show\": \"\",\n        \"clear\": \"\"\n    }\n}",
        "com.azure.sonic.versions.libsairedis": "1.0.0",
        "com.azure.sonic.versions.libswsscommon": "1.0.0",
        "org.opencontainers.image.ref.name": "ubuntu",
        "org.opencontainers.image.version": "22.04"
    },
    "Architecture": "amd64",

We do have some metadata such as version/title/licenses which are converted to label during rockcraft build phase.


dima@colima-ahh /c/h/d/b/sha256 (main) [127]> cat 2c24ed033f0bea871f6930535e2f61789840d254d0be961aa17776d797103f23| jq .
{
  "created": "2024-06-07T16:49:32.047857229+09:00",
  "architecture": "arm64",
  "os": "linux",
  "config": {
    "Entrypoint": [
      "/usr/bin/pebble",
      "enter"
    ],
    "Labels": {
      "org.opencontainers.image.base.digest": "6c78fe6c70b796b20053f9e161f401ea5f0f075eff7c09d9f491da3cff1a454e",
      "org.opencontainers.image.created": "2024-06-07T07:49:48.484220+00:00",
      "org.opencontainers.image.licenses": "Apache-2.0",
      "org.opencontainers.image.ref.name": "gubernator",
      "org.opencontainers.image.title": "gubernator",
      "org.opencontainers.image.version": "2.7.5"
    }
  },

Why it needs to get done

labels are important metadata carried by image, and are widely used.