Compare commits
7
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ec64fb07cf | ||
|
|
44d7ac2346 | ||
|
|
984494f556 | ||
|
|
8eadda5815 | ||
|
|
6a369dfa5e | ||
|
|
a999db54a8 | ||
|
|
83a1784fca |
No files matched your search
@@ -36,7 +36,7 @@ mypkg/
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
In a channel this becomes `<channel url>/mytool:1.4.0`, plus the `latest` tag:
|
In a channel this becomes `<channel url>/mytool:1.4.0`, plus the `latest` tag. The manifest sets `artifactType` to `application/vnd.latha.orbit.v1`, which is how `orbit search` tells Orbit packages apart from other OCI artifacts such as Helm charts. Packages published before this have no `artifactType`, so search also recognises the Orbit config media type:
|
||||||
|
|
||||||
| Part | Media type |
|
| Part | Media type |
|
||||||
|---|---|
|
|---|---|
|
||||||
|
|||||||
@@ -3,6 +3,10 @@
|
|||||||
///|
|
///|
|
||||||
const CONFIG_MEDIA_TYPE : String = "application/vnd.latha.orbit.config.v1+json"
|
const CONFIG_MEDIA_TYPE : String = "application/vnd.latha.orbit.config.v1+json"
|
||||||
|
|
||||||
|
///|
|
||||||
|
/// Manifest artifactType that marks a repository as an Orbit package.
|
||||||
|
const ORBIT_ARTIFACT_TYPE : String = "application/vnd.latha.orbit.v1"
|
||||||
|
|
||||||
///|
|
///|
|
||||||
const LAYER_MEDIA_TYPE : String = "application/vnd.latha.orbit.layer.v1.tar+gzip"
|
const LAYER_MEDIA_TYPE : String = "application/vnd.latha.orbit.layer.v1.tar+gzip"
|
||||||
|
|
||||||
|
|||||||
+252
-19
@@ -148,8 +148,17 @@ async fn visit(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
let digest = resolve_digest(ch, name, tag)
|
let digest = resolve_digest(ch, name, tag)
|
||||||
let m = fetch_manifest(ch, name, digest)
|
|
||||||
let prev = p.ctx.state.get(name)
|
let prev = p.ctx.state.get(name)
|
||||||
|
// An unchanged build with a saved description needs no metadata fetch.
|
||||||
|
let m = match prev {
|
||||||
|
Some(i) =>
|
||||||
|
if i.digest == digest && i.description != "" {
|
||||||
|
manifest_of_installed(i)
|
||||||
|
} else {
|
||||||
|
fetch_manifest(ch, name, digest)
|
||||||
|
}
|
||||||
|
None => fetch_manifest(ch, name, digest)
|
||||||
|
}
|
||||||
let st = Step::{
|
let st = Step::{
|
||||||
name,
|
name,
|
||||||
channel: ch.name,
|
channel: ch.name,
|
||||||
@@ -209,9 +218,7 @@ fn owner_of_bin(ctx : Ctx, bin : String) -> String? {
|
|||||||
async fn unlink_bins(ctx : Ctx, bins : Array[String]) -> Unit noraise {
|
async fn unlink_bins(ctx : Ctx, bins : Array[String]) -> Unit noraise {
|
||||||
for b in bins {
|
for b in bins {
|
||||||
let path = bin_dir(ctx) + "/" + basename(b)
|
let path = bin_dir(ctx) + "/" + basename(b)
|
||||||
try {
|
@fs.remove(path) catch {
|
||||||
@fs.remove(path)
|
|
||||||
} catch {
|
|
||||||
_ => ()
|
_ => ()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -223,9 +230,7 @@ async fn link_bins(
|
|||||||
dir : String,
|
dir : String,
|
||||||
bins : Array[String],
|
bins : Array[String],
|
||||||
) -> Unit raise OrbitError {
|
) -> 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())
|
e => raise OrbitError("cannot create bin dir: " + e.to_string())
|
||||||
}
|
}
|
||||||
for b in bins {
|
for b in bins {
|
||||||
@@ -525,11 +530,7 @@ async fn cmd_gc(ctx : Ctx) -> Unit raise OrbitError {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
let mut freed = 0
|
let mut freed = 0
|
||||||
let pkgs = try {
|
let pkgs = @fs.readdir(store) catch { _ => [] }
|
||||||
@fs.readdir(store)
|
|
||||||
} catch {
|
|
||||||
_ => []
|
|
||||||
}
|
|
||||||
for pkg in pkgs {
|
for pkg in pkgs {
|
||||||
match ctx.state.get(pkg) {
|
match ctx.state.get(pkg) {
|
||||||
None => {
|
None => {
|
||||||
@@ -541,11 +542,7 @@ async fn cmd_gc(ctx : Ctx) -> Unit raise OrbitError {
|
|||||||
for g in inst.history {
|
for g in inst.history {
|
||||||
keep.push(store_id(g.digest))
|
keep.push(store_id(g.digest))
|
||||||
}
|
}
|
||||||
let ids = try {
|
let ids = @fs.readdir(store + "/" + pkg) catch { _ => [] }
|
||||||
@fs.readdir(store + "/" + pkg)
|
|
||||||
} catch {
|
|
||||||
_ => []
|
|
||||||
}
|
|
||||||
for id in ids {
|
for id in ids {
|
||||||
if !keep.contains(id) {
|
if !keep.contains(id) {
|
||||||
sh_ok("rm -rf " + sq(store + "/" + pkg + "/" + id))
|
sh_ok("rm -rf " + sq(store + "/" + pkg + "/" + id))
|
||||||
@@ -633,8 +630,163 @@ async fn cmd_versions(ctx : Ctx, spec : String) -> Unit raise OrbitError {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
///|
|
||||||
|
/// What search shows about one Orbit package, read from its manifest.
|
||||||
|
struct RepoInfo {
|
||||||
|
version : String
|
||||||
|
description : String
|
||||||
|
}
|
||||||
|
|
||||||
|
///|
|
||||||
|
fn is_orbit_object(o : Map[String, Json]) -> Bool {
|
||||||
|
if jstr(o, "artifactType", "") == ORBIT_ARTIFACT_TYPE {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
match o.get("config") {
|
||||||
|
Some(Json::Object(c)) => jstr(c, "mediaType", "") == CONFIG_MEDIA_TYPE
|
||||||
|
_ => false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
///|
|
||||||
|
/// The package info from a manifest, or None if it isn't an Orbit package.
|
||||||
|
/// Version and description come from the standard OCI annotations that publish
|
||||||
|
/// writes, so no extra request is needed.
|
||||||
|
fn orbit_info(text : String) -> RepoInfo? {
|
||||||
|
let parsed : Map[String, Json]? = Some(parse_object(text, "manifest")) catch {
|
||||||
|
_ => None
|
||||||
|
}
|
||||||
|
match parsed {
|
||||||
|
Some(o) =>
|
||||||
|
if is_orbit_object(o) {
|
||||||
|
let annotations : Map[String, Json] = match o.get("annotations") {
|
||||||
|
Some(Json::Object(a)) => a
|
||||||
|
_ => Map([])
|
||||||
|
}
|
||||||
|
Some(RepoInfo::{
|
||||||
|
version: jstr(annotations, "org.opencontainers.image.version", ""),
|
||||||
|
description: jstr(
|
||||||
|
annotations, "org.opencontainers.image.description", "",
|
||||||
|
),
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
None => None
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
///|
|
||||||
|
/// 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 orbit_repo_info(ch : Channel, repo : String) -> RepoInfo? noraise {
|
||||||
|
let tags = lines(capture(oras(ch, "repo tags " + sq(repo_of(ch, repo))))) catch {
|
||||||
|
_ => return None
|
||||||
|
}
|
||||||
|
if tags.length() == 0 {
|
||||||
|
return None
|
||||||
|
}
|
||||||
|
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 None
|
||||||
|
}
|
||||||
|
orbit_info(text)
|
||||||
|
}
|
||||||
|
|
||||||
|
///|
|
||||||
|
/// Check many repositories at once, with one spinner for the whole batch.
|
||||||
|
async fn find_orbit_repos(
|
||||||
|
ch : Channel,
|
||||||
|
repos : Array[String],
|
||||||
|
) -> Array[RepoInfo?] 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[RepoInfo?]] = []
|
||||||
|
for r in repos {
|
||||||
|
tasks.push(group.spawn(() => orbit_repo_info(ch, r)))
|
||||||
|
}
|
||||||
|
let results : Array[RepoInfo?] = []
|
||||||
|
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())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
///|
|
||||||
|
/// Pad on the right to `width` characters, for the table columns.
|
||||||
|
fn pad_right(s : String, width : Int32) -> String {
|
||||||
|
let sb = StringBuilder()
|
||||||
|
sb.write_string(s)
|
||||||
|
let mut n = chars(s).length()
|
||||||
|
while n < width {
|
||||||
|
sb.write_char(' ')
|
||||||
|
n = n + 1
|
||||||
|
}
|
||||||
|
sb.to_string()
|
||||||
|
}
|
||||||
|
|
||||||
|
///|
|
||||||
|
/// Print rows as a table. The first row is the header. The last column is not
|
||||||
|
/// padded, so long descriptions don't leave trailing spaces.
|
||||||
|
fn print_table(rows : Array[Array[String]]) -> Unit {
|
||||||
|
let ncols = rows[0].length()
|
||||||
|
let widths : Array[Int32] = []
|
||||||
|
for c = 0; c < ncols; c = c + 1 {
|
||||||
|
widths.push(0)
|
||||||
|
}
|
||||||
|
for row in rows {
|
||||||
|
for c = 0; c < ncols; c = c + 1 {
|
||||||
|
let n = chars(row[c]).length()
|
||||||
|
if n > widths[c] {
|
||||||
|
widths[c] = n
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for row in rows {
|
||||||
|
let sb = StringBuilder()
|
||||||
|
for c = 0; c < ncols; c = c + 1 {
|
||||||
|
if c > 0 {
|
||||||
|
sb.write_string(" ")
|
||||||
|
}
|
||||||
|
if c < ncols - 1 {
|
||||||
|
sb.write_string(pad_right(row[c], widths[c]))
|
||||||
|
} else {
|
||||||
|
sb.write_string(row[c])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
println(sb.to_string())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
///|
|
///|
|
||||||
async fn cmd_search(ctx : Ctx, term : String) -> Unit raise OrbitError {
|
async fn cmd_search(ctx : Ctx, term : String) -> Unit raise OrbitError {
|
||||||
|
let rows : Array[Array[String]] = [
|
||||||
|
["PACKAGE", "CHANNEL", "VERSION", "DESCRIPTION"],
|
||||||
|
]
|
||||||
let mut listed = 0
|
let mut listed = 0
|
||||||
for ch in ctx.channels {
|
for ch in ctx.channels {
|
||||||
let out = capture(
|
let out = capture(
|
||||||
@@ -647,9 +799,33 @@ async fn cmd_search(ctx : Ctx, term : String) -> Unit raise OrbitError {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
listed = listed + 1
|
listed = listed + 1
|
||||||
|
let candidates : Array[String] = []
|
||||||
for r in lines(out) {
|
for r in lines(out) {
|
||||||
if contains_str(r, term) {
|
// A name with "/" is a nested channel namespace (e.g. example/greet under
|
||||||
println("\{ch.name}::\{r}")
|
// main), not a package name that `orbit install` could use.
|
||||||
|
if valid_name(r) && contains_str(r, term) {
|
||||||
|
candidates.push(r)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
let found = find_orbit_repos(ch, candidates)
|
||||||
|
for i, r in candidates {
|
||||||
|
match found[i] {
|
||||||
|
Some(info) =>
|
||||||
|
rows.push([
|
||||||
|
r,
|
||||||
|
ch.name,
|
||||||
|
if info.version == "" {
|
||||||
|
"-"
|
||||||
|
} else {
|
||||||
|
info.version
|
||||||
|
},
|
||||||
|
if info.description == "" {
|
||||||
|
"-"
|
||||||
|
} else {
|
||||||
|
info.description
|
||||||
|
},
|
||||||
|
])
|
||||||
|
None => ()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -658,4 +834,61 @@ async fn cmd_search(ctx : Ctx, term : String) -> Unit raise OrbitError {
|
|||||||
"no channel allows listing packages (catalog API); try `orbit versions <name>`",
|
"no channel allows listing packages (catalog API); try `orbit versions <name>`",
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
if rows.length() == 1 {
|
||||||
|
if term == "" {
|
||||||
|
println("no packages found")
|
||||||
|
} else {
|
||||||
|
println("no packages match '\{term}'")
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
print_table(rows)
|
||||||
|
}
|
||||||
|
|
||||||
|
///|
|
||||||
|
test "orbit manifests are recognised by artifactType or config media type" {
|
||||||
|
assert_true(
|
||||||
|
orbit_info(
|
||||||
|
"{\"artifactType\":\"application/vnd.latha.orbit.v1\",\"config\":{\"mediaType\":\"x\"}}",
|
||||||
|
)
|
||||||
|
is Some(_),
|
||||||
|
)
|
||||||
|
assert_true(
|
||||||
|
orbit_info(
|
||||||
|
"{\"artifactType\":null,\"config\":{\"mediaType\":\"application/vnd.latha.orbit.config.v1+json\"}}",
|
||||||
|
)
|
||||||
|
is Some(_),
|
||||||
|
)
|
||||||
|
assert_true(
|
||||||
|
orbit_info(
|
||||||
|
"{\"artifactType\":\"application/vnd.cncf.helm.chart.content.v1.tar+gzip\",\"config\":{\"mediaType\":\"application/vnd.cncf.helm.config.v1+json\"}}",
|
||||||
|
)
|
||||||
|
is None,
|
||||||
|
)
|
||||||
|
assert_true(orbit_info("not json") is None)
|
||||||
|
assert_true(orbit_info("{\"config\":\"string\"}") is None)
|
||||||
|
}
|
||||||
|
|
||||||
|
///|
|
||||||
|
test "search info comes from OCI annotations" {
|
||||||
|
let info = orbit_info(
|
||||||
|
"{\"artifactType\":\"application/vnd.latha.orbit.v1\",\"annotations\":{\"org.opencontainers.image.version\":\"1.2.3\",\"org.opencontainers.image.description\":\"A tool\"}}",
|
||||||
|
).unwrap()
|
||||||
|
assert_eq(info.version, "1.2.3")
|
||||||
|
assert_eq(info.description, "A tool")
|
||||||
|
let bare = orbit_info("{\"artifactType\":\"application/vnd.latha.orbit.v1\"}").unwrap()
|
||||||
|
assert_eq(bare.version, "")
|
||||||
|
assert_eq(bare.description, "")
|
||||||
|
}
|
||||||
|
|
||||||
|
///|
|
||||||
|
test "search skips nested channel namespaces" {
|
||||||
|
assert_true(valid_name("greet"))
|
||||||
|
assert_true(!valid_name("example/greet"))
|
||||||
|
}
|
||||||
|
|
||||||
|
///|
|
||||||
|
test "table columns line up" {
|
||||||
|
assert_eq(pad_right("ab", 4), "ab ")
|
||||||
|
assert_eq(pad_right("abcd", 2), "abcd")
|
||||||
}
|
}
|
||||||
@@ -218,6 +218,8 @@ async fn publish(
|
|||||||
ch,
|
ch,
|
||||||
"push " +
|
"push " +
|
||||||
sq(repo_of(ch, m.name) + ":" + tags) +
|
sq(repo_of(ch, m.name) + ":" + tags) +
|
||||||
|
" --artifact-type " +
|
||||||
|
sq(ORBIT_ARTIFACT_TYPE) +
|
||||||
" --config " +
|
" --config " +
|
||||||
sq("orbit.json:" + CONFIG_MEDIA_TYPE) +
|
sq("orbit.json:" + CONFIG_MEDIA_TYPE) +
|
||||||
" --annotation " +
|
" --annotation " +
|
||||||
|
|||||||
+30
-15
@@ -276,25 +276,40 @@ async fn sh_ok(cmd : String) -> Unit raise OrbitError {
|
|||||||
}
|
}
|
||||||
|
|
||||||
///|
|
///|
|
||||||
/// Return stdout; stderr goes to the terminal unless captured. A label enables delayed progress spinner.
|
/// Braille spinner on stderr until cancelled.
|
||||||
async fn capture(cmd : String, progress? : String = "") -> String raise OrbitError {
|
async fn spin(label : String) -> Unit noraise {
|
||||||
|
let frames = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"]
|
||||||
|
let mut i = 0
|
||||||
|
while true {
|
||||||
|
c_print_err(utf8_encode("\r\u001B[2K" + frames[i % 10] + " " + label))
|
||||||
|
i = i + 1
|
||||||
|
@async.sleep(80)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
///|
|
||||||
|
/// Return stdout; stderr goes to the terminal unless captured. A label shows a
|
||||||
|
/// braille spinner on a terminal while the command runs. The spinner is a child
|
||||||
|
/// task that is cancelled as soon as the command finishes, so nothing keeps the
|
||||||
|
/// group alive.
|
||||||
|
async fn capture(cmd : String, progress~ : String = "") -> String raise OrbitError {
|
||||||
let is_tty = c_isatty(2) != 0 && getenv("TERM") != "dumb"
|
let is_tty = c_isatty(2) != 0 && getenv("TERM") != "dumb"
|
||||||
|
let spinning = is_tty && progress != ""
|
||||||
let res : Result[String, Error] = try {
|
let res : Result[String, Error] = try {
|
||||||
let out = @async.with_task_group((group) => {
|
let out = @async.with_task_group(group => {
|
||||||
if is_tty && progress != "" {
|
let spinner = if spinning {
|
||||||
group.spawn_bg(async fn() {
|
Some(group.spawn(() => {
|
||||||
@async.sleep(250)
|
ignore(@async.handle_cancellation(() => spin(progress)))
|
||||||
let frames = ["|", "/", "-", "\\"]
|
}))
|
||||||
let mut i = 0
|
} else {
|
||||||
while true {
|
None
|
||||||
c_print_err(utf8_encode("\r\u001B[2K" + frames[i % 4] + " " + progress))
|
|
||||||
i = i + 1
|
|
||||||
@async.sleep(100)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
let (code, stdout, _) = @process.collect_output("sh", ["-c", cmd])
|
let (code, stdout, _) = @process.collect_output("sh", ["-c", cmd])
|
||||||
if is_tty && progress != "" {
|
match spinner {
|
||||||
|
Some(task) => task.cancel()
|
||||||
|
None => ()
|
||||||
|
}
|
||||||
|
if spinning {
|
||||||
c_print_err(utf8_encode("\r\u001B[2K"))
|
c_print_err(utf8_encode("\r\u001B[2K"))
|
||||||
}
|
}
|
||||||
if code != 0 {
|
if code != 0 {
|
||||||
|
|||||||
Reference in new issue
Block a user