From 28b13e7a9666bcf9a5ad285927a64963a721e01f Mon Sep 17 00:00:00 2001 From: nandithebull Date: Thu, 26 Nov 2026 20:38:29 -0800 Subject: [PATCH] Add documentation metadata for Orbit packages --- README.md | 8 ++- .../greet/files/share/doc/greet/README.md | 15 +++++ examples/greet/orbit.json | 3 +- src/main/model.mbt | 2 + src/main/ops.mbt | 1 + src/main/registry.mbt | 59 ++++++++++++++++++- 6 files changed, 84 insertions(+), 4 deletions(-) create mode 100644 examples/greet/files/share/doc/greet/README.md diff --git a/README.md b/README.md index d3cb511..3bdb268 100644 --- a/README.md +++ b/README.md @@ -30,6 +30,7 @@ mypkg/ "name": "mytool", "version": "1.4.0", "description": "Does a thing", + "documentation": "https://example.com/mytool", "bin": ["bin/mytool"], "depends": { "libfoo": "^2.1.0" } } @@ -39,9 +40,14 @@ In a channel this becomes `/mytool:1.4.0`, plus the `latest` tag: | Part | Media type | |---|---| -| config | `application/vnd.latha.orbit.config.v1+json` (the orbit.json) | +| config | `application/vnd.latha.orbit.config.v1+json` (`orbit.json`, with OCI labels for package-page metadata) | | layer `pkg.tar.gz` | `application/vnd.latha.orbit.layer.v1.tar+gzip` | +The optional `description` and `documentation` fields supply Gitea's **About** +text and **Documentation** link. Use a public or otherwise accessible HTTP(S) +URL for the link. Gitea does not render a bundled README inline, but you can +ship one under `files/share/doc//README.md`, as the `greet` example does. + Because these are ordinary OCI artifacts, you can sign them with `cosign` or `notation` and attach SBOMs using the registry's own tooling. ## Usage diff --git a/examples/greet/files/share/doc/greet/README.md b/examples/greet/files/share/doc/greet/README.md new file mode 100644 index 0000000..2ad4688 --- /dev/null +++ b/examples/greet/files/share/doc/greet/README.md @@ -0,0 +1,15 @@ +# greet + +`greet` is a small Orbit package that demonstrates installing from a custom +channel. It depends on the `hello` package from Orbit's built-in `main` +channel. + +```sh +# Add the example channel once. +orbit channel add example git.site.latha.org/nandi/example +orbit install example::greet +eval "$(orbit env)" +greet +``` + +`greet` prints `greetings from the example channel`. diff --git a/examples/greet/orbit.json b/examples/greet/orbit.json index 0429083..d7e6b44 100644 --- a/examples/greet/orbit.json +++ b/examples/greet/orbit.json @@ -1,7 +1,8 @@ { "name": "greet", - "version": "1.0.0", + "version": "1.0.1", "description": "Example package for the example channel", + "documentation": "https://git.site.latha.org/nandi/orbit/src/branch/main/examples/greet/files/share/doc/greet/README.md", "bin": ["bin/greet"], "depends": { "hello": "^1.0.0" } } diff --git a/src/main/model.mbt b/src/main/model.mbt index f8de8b1..d2a992f 100644 --- a/src/main/model.mbt +++ b/src/main/model.mbt @@ -12,6 +12,7 @@ struct Manifest { name : String version : String description : String + documentation : String depends : Map[String, String] bins : Array[String] } @@ -179,6 +180,7 @@ fn parse_manifest(text : String) -> Manifest raise OrbitError { name: jstr(o, "name", ""), version: jstr(o, "version", ""), description: jstr(o, "description", ""), + documentation: jstr(o, "documentation", ""), depends: jmap(o, "depends"), bins: jstrs(o, "bin"), } diff --git a/src/main/ops.mbt b/src/main/ops.mbt index e63433b..c601f32 100644 --- a/src/main/ops.mbt +++ b/src/main/ops.mbt @@ -27,6 +27,7 @@ fn manifest_of_installed(p : Installed) -> Manifest { name: p.name, version: p.version, description: "", + documentation: "", depends: p.depends, bins: p.bins, } diff --git a/src/main/registry.mbt b/src/main/registry.mbt index 2350650..5744b30 100644 --- a/src/main/registry.mbt +++ b/src/main/registry.mbt @@ -121,7 +121,61 @@ fn fetch_into_store( } ///| -/// Pack `/files` and push it with `/orbit.json` as the config blob. +/// Gitea reads package-page metadata from OCI image config labels, not +/// manifest annotations. Keep the Orbit manifest at the top level for pulls. +fn package_config(text : String, m : Manifest) -> String raise OrbitError { + if m.description == "" && m.documentation == "" { + return text + } + let config = parse_object(text, "orbit.json") + let image = match config.get("config") { + Some(Json::Object(image)) => image + None => Map([]) + _ => raise OrbitError("orbit.json: config must be an object") + } + let labels = match image.get("Labels") { + Some(Json::Object(labels)) => labels + None => Map([]) + _ => raise OrbitError("orbit.json: config.Labels must be an object") + } + if m.description != "" { + labels["org.opencontainers.image.description"] = Json::string(m.description) + } + if m.documentation != "" { + labels["org.opencontainers.image.documentation"] = Json::string( + m.documentation, + ) + } + image["Labels"] = Json::object(labels) + config["config"] = Json::object(image) + Json::object(config).stringify(indent=2) + "\n" +} + +///| +test "package config exposes Gitea labels and preserves Orbit metadata" { + let text = + #|{"name":"greet","version":"1.0.1","description":"A greeting","documentation":"https://example.com/greet","depends":{"hello":"^1"},"config":{"Labels":{"custom":"keep"}}} + let published = package_config(text, parse_manifest(text)) + let m = parse_manifest(published) + assert_eq(m.name, "greet") + assert_eq(m.depends.get("hello"), Some("^1")) + let config = parse_object(published, "orbit.json") + guard config.get("config") is Some(Json::Object(image)) else { + fail("missing OCI config") + } + guard image.get("Labels") is Some(Json::Object(labels)) else { + fail("missing OCI labels") + } + assert_eq(jstr(labels, "custom", ""), "keep") + assert_eq(jstr(labels, "org.opencontainers.image.description", ""), "A greeting") + assert_eq( + jstr(labels, "org.opencontainers.image.documentation", ""), + "https://example.com/greet", + ) +} + +///| +/// Pack `/files` and push it with the enriched Orbit config blob. fn publish( ch : Channel, dir : String, @@ -132,6 +186,7 @@ fn publish( None => raise OrbitError("\{dir}/orbit.json not found") } let m = parse_manifest(text) + let config = package_config(text, m) let files = dir + "/files" if !exists(files) { raise OrbitError("\{files} not found (package contents go in files/)") @@ -149,7 +204,7 @@ fn publish( sq(files) + " .", ) - sh_ok("cp " + sq(dir + "/orbit.json") + " " + sq(tmp + "/orbit.json")) + write_text_atomic(tmp + "/orbit.json", config) let tags = if also_latest { m.version + ",latest" } else { m.version } let push = oras( ch,