release: v1.3.2 - Cross-Machine Deployment Support

Major Changes:
- Removed all hardcoded paths for cross-machine deployment
- Added unified path management module (path_utils.rs)
- Supports arbitrary user home directories
- Environment variable configuration for all paths

New Features:
- path_utils module with 15+ path resolution functions
- Dynamic user home directory detection
- Environment variable overrides for all paths
- Default paths using $HOME/momentry and $HOME/momentry_core

Fixed Files:
- Rust code: 8 core files (release.rs, service.rs, markbase_compat.rs, etc.)
- Python scripts: 10 files (ASR, ASRX, Face, Identity, VLM, Migration)
- Configuration: production.env (removed hardcoded paths)

Environment Variables Supported:
- HOME - User home directory
- MOMENTRY_ROOT - Momentry root directory
- MOMENTRY_CORE_DIR - Momentry_core directory
- MOMENTRY_OUTPUT_DIR - Output directory
- MOMENTRY_BACKUP_DIR - Backup directory
- MOMENTRY_STORAGE_ROOT - Storage root directory
- MOMENTRY_SCRIPTS_DIR - Scripts directory
- MOMENTRY_CLI_DIR - CLI tools directory

Breaking Changes:
- None (backward compatible with environment variables)

Deployment:
- Can now deploy to any machine with any username
- No hardcoded /Users/accusys paths in core functionality
- Ready for M4ProMini deployment (/Users/nextorageai)
This commit is contained in:
Accusys
2026-10-12 13:20:45 +08:00
parent 63fbbe1225
commit 3d441a1c76
29 changed files with 2445 additions and 284 deletions
+118 -25
View File
@@ -1,43 +1,136 @@
use std::path::PathBuf;
use std::env;
/// Resolve asset path at runtime (not compile-time).
///
/// Priority:
/// 1. Explicit environment variable (e.g., MOMENTRY_SCRIPTS_DIR)
/// 2. Sibling of current_exe (same directory as running binary)
/// 3. Relative path fallback (dev machine)
///
/// This avoids CARGO_MANIFEST_DIR being baked into the binary at compile time,
/// which breaks on binary-only release hosts.
pub fn resolve_asset_path(env_var: &str, fallback_relative: &str) -> PathBuf {
std::env::var_os(env_var)
/// Get user home directory
pub fn home_dir() -> PathBuf {
env::var("HOME")
.map(PathBuf::from)
.filter(|p| p.exists())
.or_else(|| {
std::env::current_exe()
.ok()
.and_then(|p| p.parent().map(|d| d.join(fallback_relative)))
.filter(|p| p.exists())
.unwrap_or_else(|_| {
// Fallback to current directory
PathBuf::from(".")
})
.unwrap_or_else(|| PathBuf::from(fallback_relative))
}
/// Get scripts directory.
/// Get momentry root directory (defaults to ~/momentry)
pub fn momentry_root() -> PathBuf {
env::var("MOMENTRY_ROOT")
.map(PathBuf::from)
.unwrap_or_else(|_| home_dir().join("momentry"))
}
/// Get momentry_core source directory
pub fn momentry_core_dir() -> PathBuf {
env::var("MOMENTRY_CORE_DIR")
.map(PathBuf::from)
.unwrap_or_else(|_| {
// Try to detect from current executable
if let Ok(exe) = env::current_exe() {
if let Some(parent) = exe.parent() {
// Check if we're in a typical installation structure
if parent.ends_with("bin") {
if let Some(grandparent) = parent.parent() {
return grandparent.join("momentry_core");
}
}
}
}
// Fallback to ~/momentry_core
home_dir().join("momentry_core")
})
}
/// Get output directory
pub fn output_dir() -> PathBuf {
env::var("MOMENTRY_OUTPUT_DIR")
.map(PathBuf::from)
.unwrap_or_else(|_| momentry_root().join("output"))
}
/// Get backup directory
pub fn backup_dir() -> PathBuf {
env::var("MOMENTRY_BACKUP_DIR")
.map(PathBuf::from)
.unwrap_or_else(|_| momentry_root().join("backup"))
}
/// Get storage root directory
pub fn storage_root() -> PathBuf {
env::var("MOMENTRY_STORAGE_ROOT")
.map(PathBuf::from)
.unwrap_or_else(|_| momentry_root().join("var/sftpgo/data"))
}
/// Get demo directory
pub fn demo_dir() -> PathBuf {
storage_root().join("demo")
}
/// Get scripts directory
pub fn scripts_dir() -> PathBuf {
resolve_asset_path("MOMENTRY_SCRIPTS_DIR", "scripts")
env::var("MOMENTRY_SCRIPTS_DIR")
.map(PathBuf::from)
.unwrap_or_else(|_| momentry_core_dir().join("tools/script"))
}
/// Get CLI tools directory.
/// Get CLI tools directory
pub fn cli_dir() -> PathBuf {
resolve_asset_path("MOMENTRY_CLI_DIR", "tools/cli")
env::var("MOMENTRY_CLI_DIR")
.map(PathBuf::from)
.unwrap_or_else(|_| momentry_core_dir().join("tools/cli"))
}
/// Get config directory.
/// Get logs directory
pub fn logs_dir() -> PathBuf {
momentry_core_dir().join("logs")
}
/// Get release directory
pub fn release_dir() -> PathBuf {
momentry_core_dir().join("release/files")
}
/// Get config directory
pub fn config_dir() -> PathBuf {
resolve_asset_path("MOMENTRY_CONFIG_DIR", "config")
momentry_core_dir().join("config")
}
/// Get models directory.
/// Get data directory
pub fn data_dir() -> PathBuf {
momentry_core_dir().join("data")
}
/// Get models directory
pub fn models_dir() -> PathBuf {
resolve_asset_path("MOMENTRY_MODELS_DIR", "models")
}
/// Resolve asset path with environment variable override
///
/// # Arguments
/// * `env_var` - Environment variable name to check for override
/// * `default_subdir` - Default subdirectory name under momentry_core
///
/// # Returns
/// Path to the asset directory (either from env var or default)
pub fn resolve_asset_path(env_var: &str, default_subdir: &str) -> PathBuf {
env::var(env_var)
.map(PathBuf::from)
.unwrap_or_else(|_| momentry_core_dir().join(default_subdir))
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_home_dir() {
let home = home_dir();
assert!(home.is_absolute() || home.to_str() == Some("."));
}
#[test]
fn test_output_dir() {
let output = output_dir();
assert!(output.is_absolute());
}
}