Skip to content

Image metadata

Labels and annotations are separate string-to-string maps:

Setting OCI location Inherited from base?
labels Image config config.Labels Yes
manifest_annotations Image manifest annotations No
index_annotations Local layout index.json and multi-platform image index annotations No

Annotations describe the newly built object, so base manifest, index, and descriptor annotations are not copied. The builder retains its own org.opencontainers.image.ref.name in the local index independently of user annotations. On the existing single-image path, a registry push sends the image manifest and config, not the local layout index. Manifest annotations therefore travel with that push; index annotations remain in the local layout. A multi-platform push sends the annotated image index as well as each annotated platform manifest; the layout wrapper keeps the same user index annotations.

Use the corresponding TOML tables:

[build.labels]
framework = "custom"
"example.team" = "platform"
[build.manifest_annotations]
"org.opencontainers.image.title" = "myapp"
[build.index_annotations]
"example.layout" = "production"

Or use BuildConfig(labels=..., manifest_annotations=..., index_annotations=...). The repeatable CLI options override individual keys from the file:

Terminal window
pycontainer build --config pycontainer.toml --label example.team=runtime \
--manifest-annotation org.opencontainers.image.title=myapp \
--index-annotation example.layout=production

For each label key, precedence is explicit CLI, configuration file, framework-derived default, then base image. Repeating a CLI key uses its last value. An explicit empty string is a value, not a deletion. Framework detection previously overwrote an explicitly configured framework label; it now fills that label only when the user has not supplied it.

Manifest and index annotation maps merge CLI over file independently; they do not inherit base annotations or copy values between each other or into labels. Keys must be strings containing at least one non-whitespace character, and values must be strings; empty values are allowed. CLI arguments split on the first =. Invalid maps are rejected even when another source would otherwise overwrite them.

org.opencontainers.image.ref.name is protected in both user annotation maps: the builder owns reference metadata, so even supplying the same value is an error. This restriction does not apply to a config label with that key.

Release notes are opt-in. Set release_notes_file (release-notes-file in TOML, --release-notes FILE on the CLI) to embed a file’s text as one image-config label. The key defaults to io.github.spboyer.pycontainer.release-notes, a stable reverse-DNS key in this project’s namespace; set release_notes_label (--release-notes-label KEY) to use another. CLI options override the configuration-file settings. Without a notes file, no label is added and the key setting has no effect.

  • A relative path is resolved against context_dir, like requirements_file; absolute paths are accepted. A file inside the context is still selected for the application layer by the normal include and exclude rules.
  • The file must be UTF-8. One leading UTF-8 byte-order mark is removed. CRLF and lone CR line endings are converted to LF; no other whitespace changes.
  • After normalization, the UTF-8 value may be at most 8 KiB (8,192 bytes); 8,193 bytes is an error. Content is never truncated. An empty file produces an empty label value.
  • A missing, unreadable, non-UTF-8 or oversized file is a configuration error. So is an explicit CLI or file label with the same key, checked through the generated-label guard below rather than resolved by precedence.
  • The release-notes label overrides a base-image label with the same key. When the key is framework, it replaces the detected framework default unless framework is explicitly labeled, which is a collision error.
  • The file is read once when the builder is created; Python matrix versions share that snapshot. Repeated build() calls on that builder reuse the same text. Line-ending normalization makes CRLF and LF copies produce identical config and manifest digests.

Read errors report the path; dry-run plans report only the key and normalized byte count. Neither errors nor logs include the contents. Like all labels, the release notes are visible to anyone who can pull the image or read registry metadata: never put secrets in release notes.

Metadata is distributed with images or layouts and may be visible through registries. Never put secrets in labels or annotations. CLI arguments can also appear in shell history and process listings. Dry-run diagnostics show counts rather than metadata values, and registry errors omit response bodies that could echo metadata.

Label and annotation keys are serialized in sorted order. Consequently, builds with the same metadata produce the same metadata bytes regardless of input-map order. Canonicalizing inherited labels may change config and manifest digests relative to older versions even when label values are unchanged. Manifest annotations are serialized before the manifest digest and size are calculated; changing a label or manifest annotation changes the corresponding content digests. On the single-image path, changing only an index annotation changes index.json, not the manifest digest.

  • #140 adds the release-notes label above. Before framework defaults are applied, it uses merge_image_labels(labels=explicit, generated_labels=generated) to reject generated keys that collide with explicit CLI or file labels; do not silently resolve those collisions by precedence. Reuse this guard for other generated labels.
  • Multi-platform builds serialize the annotated image index before calculating its digest and size for the layout descriptors and push. Each platform manifest carries the configured manifest annotations independently.
  • #185 adds one layout descriptor per tag. Keep user index annotations on the index, preserve each descriptor’s independent internal reference annotation, and use the final manifest or image-index digest and size for every descriptor. Pass the primary reference through OCIIndex.reference_name, not in its user annotation map, which rejects protected keys.
  • #207 covers #159 and #160. Its runtime config changes must preserve StopSignal and Volumes alongside inherited and overridden labels; keep a combined regression when those changes meet.