Add pixi-style channels configured in config.toml
The built-in main channel is always included. Priority is strict, packages remember their channel, and only a missing repository falls through to the next channel. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
32714325a7
commit
61ebc21fce
11 files changed
+639
-164
No files matched your search
+22
-66
@@ -3,9 +3,6 @@
|
||||
///|
|
||||
const CONFIG_MEDIA_TYPE : String = "application/vnd.latha.orbit.config.v1+json"
|
||||
|
||||
///|
|
||||
const DEFAULT_REGISTRY : String = "git.site.latha.org/nandi"
|
||||
|
||||
///|
|
||||
const LAYER_MEDIA_TYPE : String = "application/vnd.latha.orbit.layer.v1.tar+gzip"
|
||||
|
||||
@@ -22,6 +19,7 @@ struct Manifest {
|
||||
///|
|
||||
/// A previously installed build, kept for rollback.
|
||||
struct Gen {
|
||||
channel : String
|
||||
version : String
|
||||
digest : String
|
||||
bins : Array[String]
|
||||
@@ -31,6 +29,7 @@ struct Gen {
|
||||
///|
|
||||
struct Installed {
|
||||
name : String
|
||||
mut channel : String
|
||||
mut version : String
|
||||
mut digest : String
|
||||
mut explicit : Bool
|
||||
@@ -40,16 +39,10 @@ struct Installed {
|
||||
history : Array[Gen]
|
||||
}
|
||||
|
||||
///|
|
||||
struct Config {
|
||||
registry : String
|
||||
plain_http : Bool
|
||||
}
|
||||
|
||||
///|
|
||||
struct Ctx {
|
||||
root : String
|
||||
cfg : Config
|
||||
channels : Array[Channel] // highest priority first
|
||||
state : Map[String, Installed]
|
||||
}
|
||||
|
||||
@@ -158,11 +151,11 @@ fn valid_name(s : String) -> Bool {
|
||||
c == '-' ||
|
||||
c == '_' ||
|
||||
c == '.'
|
||||
if !(ok) {
|
||||
if !ok {
|
||||
return false
|
||||
}
|
||||
}
|
||||
!(has_prefix(s, "."))
|
||||
!has_prefix(s, ".")
|
||||
}
|
||||
|
||||
///|
|
||||
@@ -189,21 +182,21 @@ fn parse_manifest(text : String) -> Manifest raise OrbitError {
|
||||
depends: jmap(o, "depends"),
|
||||
bins: jstrs(o, "bin"),
|
||||
}
|
||||
if !(valid_name(m.name)) {
|
||||
if !valid_name(m.name) {
|
||||
raise OrbitError(
|
||||
"orbit.json: invalid name '\{m.name}' (use a-z, 0-9, '-', '_', '.')",
|
||||
)
|
||||
}
|
||||
if !(is_ver(m.version)) {
|
||||
if !is_ver(m.version) {
|
||||
raise OrbitError("orbit.json: version '\{m.version}' is not semver")
|
||||
}
|
||||
for b in m.bins {
|
||||
if !(valid_rel_path(b)) {
|
||||
if !valid_rel_path(b) {
|
||||
raise OrbitError("orbit.json: bin path '\{b}' must be relative")
|
||||
}
|
||||
}
|
||||
for dep, _ in m.depends {
|
||||
if !(valid_name(dep)) {
|
||||
if !valid_name(dep) {
|
||||
raise OrbitError("orbit.json: invalid dependency name '\{dep}'")
|
||||
}
|
||||
}
|
||||
@@ -215,6 +208,7 @@ fn parse_manifest(text : String) -> Manifest raise OrbitError {
|
||||
///|
|
||||
fn gen_json(g : Gen) -> Json {
|
||||
let o : Map[String, Json] = Map([])
|
||||
o["channel"] = Json::string(g.channel)
|
||||
o["version"] = Json::string(g.version)
|
||||
o["digest"] = Json::string(g.digest)
|
||||
o["bin"] = strs_json(g.bins)
|
||||
@@ -225,6 +219,7 @@ fn gen_json(g : Gen) -> Json {
|
||||
///|
|
||||
fn installed_json(p : Installed) -> Json {
|
||||
let o : Map[String, Json] = Map([])
|
||||
o["channel"] = Json::string(p.channel)
|
||||
o["version"] = Json::string(p.version)
|
||||
o["digest"] = Json::string(p.digest)
|
||||
o["explicit"] = bool_json(p.explicit)
|
||||
@@ -267,6 +262,7 @@ fn state_from_text(text : String) -> Map[String, Installed] raise OrbitError {
|
||||
match hj {
|
||||
Json::Object(h) =>
|
||||
history.push(Gen::{
|
||||
channel: jstr(h, "channel", MAIN_CHANNEL),
|
||||
version: jstr(h, "version", ""),
|
||||
digest: jstr(h, "digest", ""),
|
||||
bins: jstrs(h, "bin"),
|
||||
@@ -279,6 +275,7 @@ fn state_from_text(text : String) -> Map[String, Installed] raise OrbitError {
|
||||
}
|
||||
out[name] = Installed::{
|
||||
name,
|
||||
channel: jstr(o, "channel", MAIN_CHANNEL),
|
||||
version: jstr(o, "version", ""),
|
||||
digest: jstr(o, "digest", ""),
|
||||
explicit: jbool(o, "explicit", false),
|
||||
@@ -296,25 +293,6 @@ fn state_from_text(text : String) -> Map[String, Installed] raise OrbitError {
|
||||
out
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------- config
|
||||
|
||||
///|
|
||||
fn config_to_text(c : Config) -> String {
|
||||
let o : Map[String, Json] = Map([])
|
||||
o["registry"] = Json::string(c.registry)
|
||||
o["plain_http"] = bool_json(c.plain_http)
|
||||
Json::object(o).stringify(indent=2) + "\n"
|
||||
}
|
||||
|
||||
///|
|
||||
fn config_from_text(text : String) -> Config raise OrbitError {
|
||||
let o = parse_object(text, "config.json")
|
||||
Config::{
|
||||
registry: jstr(o, "registry", ""),
|
||||
plain_http: jbool(o, "plain_http", false),
|
||||
}
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------- context
|
||||
|
||||
///|
|
||||
@@ -328,34 +306,19 @@ fn orbit_root() -> String {
|
||||
}
|
||||
|
||||
///|
|
||||
/// ORBIT_REGISTRY wins, then config.json, then the built-in default.
|
||||
fn pick_registry(env : String, file : String) -> String {
|
||||
if env != "" {
|
||||
env
|
||||
} else if file != "" {
|
||||
file
|
||||
} else {
|
||||
DEFAULT_REGISTRY
|
||||
}
|
||||
}
|
||||
|
||||
///|
|
||||
/// Load config and state. ORBIT_REGISTRY / ORBIT_PLAIN_HTTP override the file.
|
||||
/// Load channels and state.
|
||||
fn load_ctx() -> Ctx raise OrbitError {
|
||||
let root = orbit_root()
|
||||
let file_cfg = match read_text(root + "/config.json") {
|
||||
Some(t) => config_from_text(t)
|
||||
None => Config::{ registry: "", plain_http: false, }
|
||||
}
|
||||
let cfg = Config::{
|
||||
registry: pick_registry(getenv("ORBIT_REGISTRY"), file_cfg.registry),
|
||||
plain_http: file_cfg.plain_http || getenv("ORBIT_PLAIN_HTTP") == "1",
|
||||
}
|
||||
let channels = resolve_channels(
|
||||
load_listed_channels(root),
|
||||
getenv("ORBIT_REGISTRY"),
|
||||
getenv("ORBIT_PLAIN_HTTP") == "1",
|
||||
)
|
||||
let state = match read_text(root + "/state.json") {
|
||||
Some(t) => state_from_text(t)
|
||||
None => Map([])
|
||||
}
|
||||
Ctx::{ root, cfg, state, }
|
||||
Ctx::{ root, channels, state, }
|
||||
}
|
||||
|
||||
///|
|
||||
@@ -389,14 +352,7 @@ test "manifest roundtrip" {
|
||||
assert_eq(m.name, "hello")
|
||||
assert_eq(m.bins, ["bin/hello"])
|
||||
assert_eq(m.depends.get("lib"), Some("^1"))
|
||||
assert_true(!(valid_rel_path("../x")))
|
||||
assert_true(!(valid_rel_path("/bin/sh")))
|
||||
assert_true(!valid_rel_path("../x"))
|
||||
assert_true(!valid_rel_path("/bin/sh"))
|
||||
assert_eq(store_id("sha256:0123456789abcdef0123"), "0123456789abcdef")
|
||||
}
|
||||
|
||||
///|
|
||||
test "registry precedence" {
|
||||
assert_eq(pick_registry("env/r", "file/r"), "env/r")
|
||||
assert_eq(pick_registry("", "file/r"), "file/r")
|
||||
assert_eq(pick_registry("", ""), DEFAULT_REGISTRY)
|
||||
}
|
||||
Reference in new issue
Block a user