|
|
@@ -169,6 +169,27 @@ pub fn preflight_cmd(config: &Config, controller: bool) -> String {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+/// Mirror a package's files into the controller's local dir and return the
|
|
|
+/// local primary path.
|
|
|
+///
|
|
|
+/// FLARE names every companion by its sha256, so "present and the same size"
|
|
|
+/// is a sound consistency check — a truncated or stale file re-copies, and an
|
|
|
+/// unchanged package costs a `stat` per file. The primary (metadata) is tiny
|
|
|
+/// and always refreshed.
|
|
|
+pub fn mirror_cmd(local_dir: &str, remote_pkg: &str) -> String {
|
|
|
+ let dir = shq(local_dir);
|
|
|
+ let pkg = shq(remote_pkg);
|
|
|
+ format!(
|
|
|
+ "set -e; src=$(dirname {pkg}); dst={dir}; base=$(basename {pkg}); \
|
|
|
+ mkdir -p \"$dst\"; \
|
|
|
+ cp -f {pkg} \"$dst/$base\"; \
|
|
|
+ for f in \"$src\"/*; do b=$(basename \"$f\"); [ \"$b\" = \"$base\" ] && continue; \
|
|
|
+ if [ ! -f \"$dst/$b\" ] || [ \"$(stat -c%s \"$f\")\" != \"$(stat -c%s \"$dst/$b\")\" ]; then \
|
|
|
+ cp -f \"$f\" \"$dst/$b\" || exit 1; fi; done; \
|
|
|
+ echo \"$dst/$base\""
|
|
|
+ )
|
|
|
+}
|
|
|
+
|
|
|
/// Pick the package path out of `flare download` output: it prints progress
|
|
|
/// lines ("Downloading model file: …") and finally the resolved package path
|
|
|
/// ending in `.safetensors`. Taking the last line blindly handed `orbit run`
|
|
|
@@ -227,6 +248,22 @@ pub async fn serve(
|
|
|
controller.name
|
|
|
);
|
|
|
}
|
|
|
+ // Local mirror: launch from the controller's own disk when configured —
|
|
|
+ // engram rows are read at request time, so a shared mount is the wrong
|
|
|
+ // place for the package even with a RAM row cache.
|
|
|
+ let mut package = package;
|
|
|
+ if let Some(dir) = config.flare.as_ref().and_then(|f| f.local_dir.clone()) {
|
|
|
+ let dir = dir.replace('~', "$HOME");
|
|
|
+ let cmd = mirror_cmd(&dir, &package);
|
|
|
+ let out = crate::ssh::run_ssh(config, controller, cmd, dry_run).await?;
|
|
|
+ if !dry_run {
|
|
|
+ let local = out.lines().last().unwrap_or_default().trim().to_string();
|
|
|
+ if local.is_empty() {
|
|
|
+ bail!("flare local mirror produced no path on {}", controller.name);
|
|
|
+ }
|
|
|
+ package = local;
|
|
|
+ }
|
|
|
+ }
|
|
|
let orbit_name = orbit_node_name(config, controller);
|
|
|
let run = run_cmd(config, recipe, &orbit_name, &package)?;
|
|
|
crate::ssh::run_ssh(config, controller, run.clone(), dry_run).await?;
|