Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,8 @@ pub fn default_applications() -> HashMap<String, ApplicationAttributes> {
// Use pre-built wheel from wheels directory to avoid rebuild on every run
// The wheel is built during installation via "flmadm install"
let flamepy_wheels_dir = "${FLAME_HOME}/wheels".to_string();
// Use the same cache directory that was populated during installation
let uv_cache_dir = "${FLAME_HOME}/data/cache/uv".to_string();

HashMap::from([
(
Expand Down Expand Up @@ -239,6 +241,7 @@ pub fn default_applications() -> HashMap<String, ApplicationAttributes> {
"-m".to_string(),
"flamepy.runner.runpy".to_string(),
],
environments: HashMap::from([("UV_CACHE_DIR".to_string(), uv_cache_dir)]),
working_directory: None,
..ApplicationAttributes::default()
},
Expand Down
7 changes: 6 additions & 1 deletion executor_manager/src/shims/host_shim.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,12 @@ impl HostShim {

let log_level = env::var(RUST_LOG).unwrap_or(String::from(DEFAULT_SVC_LOG_LEVEL));

let mut envs = app.environments.clone();
// Expand environment variables in the application's environment settings
let mut envs: HashMap<String, String> = app
.environments
.iter()
.map(|(k, v)| (k.clone(), Self::expand_env_vars(v)))
.collect();
envs.insert(RUST_LOG.to_string(), log_level.clone());
envs.insert(FLAME_LOG.to_string(), log_level);
envs.insert(FLAME_INSTANCE_ENDPOINT.to_string(), endpoint.to_string());
Expand Down
40 changes: 27 additions & 13 deletions flmadm/src/managers/installation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -236,28 +236,42 @@ impl InstallationManager {

println!(" ✓ Built wheel to: {}", paths.wheels.display());

// Pre-cache dependencies by downloading them to the wheels directory
// This way "uv run --find-links <wheels>" can use cached packages
println!(" 📥 Downloading dependencies...");
// Pre-cache dependencies using uv's cache
// Use FLAME_HOME/data/cache/uv as the cache directory so it's available at runtime
println!(" 📥 Caching dependencies...");

let output = std::process::Command::new(&uv_path)
let uv_cache_dir = paths.cache.join("uv");

// Install flamepy and dependencies to populate the cache
// Using --target to a temp directory avoids needing a venv
let cache_target = paths.work.join(".flamepy-cache-target");
fs::create_dir_all(&cache_target).context("Failed to create temporary directory for caching")?;

let install_output = std::process::Command::new(&uv_path)
.arg("pip")
.arg("download")
.arg("--dest")
.arg("install")
.arg("--target")
.arg(&cache_target)
.arg("--find-links")
.arg(&paths.wheels)
.arg(&paths.sdk_python)
.arg("flamepy")
.arg("pip") // Also cache pip as it's used by flmrun
.env("UV_CACHE_DIR", &uv_cache_dir)
.output()
.context("Failed to execute uv pip download")?;
.context("Failed to execute uv pip install")?;

if !output.status.success() {
let stderr = String::from_utf8_lossy(&output.stderr);
// Don't fail installation if download fails (might be offline)
// Clean up target directory (we only needed to populate the cache)
let _ = fs::remove_dir_all(&cache_target);

if !install_output.status.success() {
let stderr = String::from_utf8_lossy(&install_output.stderr);
// Don't fail installation if caching fails (might be offline)
println!(
" ⚠️ Failed to download dependencies (will fetch at runtime): {}",
" ⚠️ Failed to cache dependencies (will fetch at runtime): {}",
stderr.lines().next().unwrap_or(&stderr)
);
} else {
println!(" ✓ Downloaded dependencies to: {}", paths.wheels.display());
println!(" ✓ Cached dependencies to: {}", uv_cache_dir.display());
}

Ok(())
Expand Down
Loading