Mark Orbit packages with artifactType and filter search by it
orbit publish sets the manifest artifactType to application/vnd.latha.orbit.v1. orbit search checks each matching repository's latest manifest in parallel and lists only Orbit packages, so Helm charts and other OCI artifacts no longer appear. Packages published earlier are recognised by their config media type. Co-Authored-By: Claude Haiku 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
a999db54a8
commit
6a369dfa5e
4 files changed
+121
-17
No files matched your search
+114
-16
@@ -218,9 +218,7 @@ fn owner_of_bin(ctx : Ctx, bin : String) -> String? {
|
||||
async fn unlink_bins(ctx : Ctx, bins : Array[String]) -> Unit noraise {
|
||||
for b in bins {
|
||||
let path = bin_dir(ctx) + "/" + basename(b)
|
||||
try {
|
||||
@fs.remove(path)
|
||||
} catch {
|
||||
@fs.remove(path) catch {
|
||||
_ => ()
|
||||
}
|
||||
}
|
||||
@@ -232,9 +230,7 @@ async fn link_bins(
|
||||
dir : String,
|
||||
bins : Array[String],
|
||||
) -> Unit raise OrbitError {
|
||||
try {
|
||||
@fs.mkdir(bin_dir(ctx), recursive=true)
|
||||
} catch {
|
||||
@fs.mkdir(bin_dir(ctx), recursive=true) catch {
|
||||
e => raise OrbitError("cannot create bin dir: " + e.to_string())
|
||||
}
|
||||
for b in bins {
|
||||
@@ -534,11 +530,7 @@ async fn cmd_gc(ctx : Ctx) -> Unit raise OrbitError {
|
||||
return
|
||||
}
|
||||
let mut freed = 0
|
||||
let pkgs = try {
|
||||
@fs.readdir(store)
|
||||
} catch {
|
||||
_ => []
|
||||
}
|
||||
let pkgs = @fs.readdir(store) catch { _ => [] }
|
||||
for pkg in pkgs {
|
||||
match ctx.state.get(pkg) {
|
||||
None => {
|
||||
@@ -550,11 +542,7 @@ async fn cmd_gc(ctx : Ctx) -> Unit raise OrbitError {
|
||||
for g in inst.history {
|
||||
keep.push(store_id(g.digest))
|
||||
}
|
||||
let ids = try {
|
||||
@fs.readdir(store + "/" + pkg)
|
||||
} catch {
|
||||
_ => []
|
||||
}
|
||||
let ids = @fs.readdir(store + "/" + pkg) catch { _ => [] }
|
||||
for id in ids {
|
||||
if !keep.contains(id) {
|
||||
sh_ok("rm -rf " + sq(store + "/" + pkg + "/" + id))
|
||||
@@ -642,6 +630,88 @@ async fn cmd_versions(ctx : Ctx, spec : String) -> Unit raise OrbitError {
|
||||
}
|
||||
}
|
||||
|
||||
///|
|
||||
/// Whether a manifest is an Orbit package: its artifactType says so, or, for
|
||||
/// packages published before artifactType was set, its config has the Orbit
|
||||
/// config media type.
|
||||
fn is_orbit_manifest(text : String) -> Bool {
|
||||
let parsed : Map[String, Json]? = Some(parse_object(text, "manifest")) catch {
|
||||
_ => None
|
||||
}
|
||||
match parsed {
|
||||
Some(o) =>
|
||||
if jstr(o, "artifactType", "") == ORBIT_ARTIFACT_TYPE {
|
||||
true
|
||||
} else {
|
||||
match o.get("config") {
|
||||
Some(Json::Object(c)) => jstr(c, "mediaType", "") == CONFIG_MEDIA_TYPE
|
||||
_ => false
|
||||
}
|
||||
}
|
||||
None => false
|
||||
}
|
||||
}
|
||||
|
||||
///|
|
||||
/// Look at one repository's latest manifest (or any tag if there is no latest).
|
||||
/// Any failure counts as "not an Orbit package", so one broken repo can't hide
|
||||
/// the others.
|
||||
async fn is_orbit_repo(ch : Channel, repo : String) -> Bool noraise {
|
||||
let tags = lines(capture(oras(ch, "repo tags " + sq(repo_of(ch, repo))))) catch {
|
||||
_ => return false
|
||||
}
|
||||
if tags.length() == 0 {
|
||||
return false
|
||||
}
|
||||
let tag = if tags.contains("latest") { "latest" } else { tags[0] }
|
||||
let text = capture(
|
||||
oras(ch, "manifest fetch " + sq(repo_of(ch, repo) + ":" + tag)),
|
||||
) catch {
|
||||
_ => return false
|
||||
}
|
||||
is_orbit_manifest(text)
|
||||
}
|
||||
|
||||
///|
|
||||
/// Check many repositories at once, with one spinner for the whole batch.
|
||||
async fn find_orbit_repos(
|
||||
ch : Channel,
|
||||
repos : Array[String],
|
||||
) -> Array[Bool] raise OrbitError {
|
||||
if repos.length() == 0 {
|
||||
return []
|
||||
}
|
||||
let label = "Checking \{repos.length()} repositories in \{ch.name}"
|
||||
let is_tty = c_isatty(2) != 0 && getenv("TERM") != "dumb"
|
||||
@async.with_task_group(group => {
|
||||
let spinner = if is_tty {
|
||||
Some(
|
||||
group.spawn(() => ignore(@async.handle_cancellation(() => spin(label)))),
|
||||
)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
let tasks : Array[@async.Task[Bool]] = []
|
||||
for r in repos {
|
||||
tasks.push(group.spawn(() => is_orbit_repo(ch, r)))
|
||||
}
|
||||
let results : Array[Bool] = []
|
||||
for t in tasks {
|
||||
results.push(t.wait())
|
||||
}
|
||||
match spinner {
|
||||
Some(s) => s.cancel()
|
||||
None => ()
|
||||
}
|
||||
if is_tty {
|
||||
c_print_err(utf8_encode("\r\u001B[2K"))
|
||||
}
|
||||
results
|
||||
}) catch {
|
||||
e => raise OrbitError(e.to_string())
|
||||
}
|
||||
}
|
||||
|
||||
///|
|
||||
async fn cmd_search(ctx : Ctx, term : String) -> Unit raise OrbitError {
|
||||
let mut listed = 0
|
||||
@@ -656,8 +726,15 @@ async fn cmd_search(ctx : Ctx, term : String) -> Unit raise OrbitError {
|
||||
}
|
||||
}
|
||||
listed = listed + 1
|
||||
let candidates : Array[String] = []
|
||||
for r in lines(out) {
|
||||
if contains_str(r, term) {
|
||||
candidates.push(r)
|
||||
}
|
||||
}
|
||||
let orbit = find_orbit_repos(ch, candidates)
|
||||
for i, r in candidates {
|
||||
if orbit[i] {
|
||||
println("\{ch.name}::\{r}")
|
||||
}
|
||||
}
|
||||
@@ -668,3 +745,24 @@ async fn cmd_search(ctx : Ctx, term : String) -> Unit raise OrbitError {
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
///|
|
||||
test "orbit manifests are recognised by artifactType or config media type" {
|
||||
assert_true(
|
||||
is_orbit_manifest(
|
||||
"{\"artifactType\":\"application/vnd.latha.orbit.v1\",\"config\":{\"mediaType\":\"x\"}}",
|
||||
),
|
||||
)
|
||||
assert_true(
|
||||
is_orbit_manifest(
|
||||
"{\"artifactType\":null,\"config\":{\"mediaType\":\"application/vnd.latha.orbit.config.v1+json\"}}",
|
||||
),
|
||||
)
|
||||
assert_false(
|
||||
is_orbit_manifest(
|
||||
"{\"artifactType\":\"application/vnd.cncf.helm.chart.content.v1.tar+gzip\",\"config\":{\"mediaType\":\"application/vnd.cncf.helm.config.v1+json\"}}",
|
||||
),
|
||||
)
|
||||
assert_false(is_orbit_manifest("not json"))
|
||||
assert_false(is_orbit_manifest("{\"config\":\"string\"}"))
|
||||
}
|
||||
Reference in new issue
Block a user