feat: add data download list to ComponentConfig and implement file downloading

- Added `data_download_list` field to `ComponentConfig` struct in `component.rs`.
- Implemented processing of `data_download_list` in the `PackageManager` to download files asynchronously in `facade.rs`.
- Updated `installer.rs` to initialize `data_download_list` for various components.
- Refactored `download_file` function in `utils.rs` to return `anyhow::Error` for better error handling.
This commit is contained in:
Rodrigo Rodriguez (Pragmatismo) 2025-10-26 18:26:19 -03:00
parent 6ad29634ea
commit 8bcaadd970
5 changed files with 416 additions and 359 deletions

View file

@ -235,7 +235,7 @@ impl AppConfig {
}
pub fn from_env() -> Self {
warn!("Loading configuration from environment variables");
info!("Loading configuration from environment variables");
let stack_path =
std::env::var("STACK_PATH").unwrap_or_else(|_| "./botserver-stack".to_string());

View file

@ -18,5 +18,6 @@ pub struct ComponentConfig {
pub pre_install_cmds_windows: Vec<String>,
pub post_install_cmds_windows: Vec<String>,
pub env_vars: HashMap<String, String>,
pub data_download_list: Vec<String>,
pub exec_cmd: String,
}

View file

@ -77,6 +77,15 @@ impl PackageManager {
.await?;
}
// Process additional data downloads with progress bar
if !component.data_download_list.is_empty() {
for url in &component.data_download_list {
let filename = url.split('/').last().unwrap_or("download.tmp");
let output_path = self.base_path.join("data").join(&component.name).join(filename);
utils::download_file(url, output_path.to_str().unwrap()).await?;
}
}
self.run_commands(post_cmds, "local", &component.name)?;
trace!(
"Component '{}' installation completed successfully",

View file

@ -61,53 +61,55 @@ impl PackageManager {
}
fn register_drive(&mut self) {
// Generate a random password for the drive user
let drive_password = self.generate_secure_password(16);
let drive_user = "gbdriveuser".to_string();
// FARM_PASSWORD may already exist; otherwise generate a new one
let farm_password =
std::env::var("FARM_PASSWORD").unwrap_or_else(|_| self.generate_secure_password(32));
// Encrypt the drive password for optional storage in the DB
let farm_password = std::env::var("FARM_PASSWORD")
.unwrap_or_else(|_| self.generate_secure_password(32));
let encrypted_drive_password = self.encrypt_password(&drive_password, &farm_password);
// Write credentials to a .env file at the base path
let env_path = self.base_path.join(".env");
let env_content = format!(
"DRIVE_USER={}\nDRIVE_PASSWORD={}\nFARM_PASSWORD={}\nDRIVE_ROOT_USER={}\nDRIVE_ROOT_PASSWORD={}\n",
drive_user, drive_password, farm_password, drive_user, drive_password
);
let env_content = format!(
"DRIVE_USER={}\nDRIVE_PASSWORD={}\nFARM_PASSWORD={}\nDRIVE_ROOT_USER={}\nDRIVE_ROOT_PASSWORD={}\n",
drive_user, drive_password, farm_password, drive_user, drive_password
);
let _ = std::fs::write(&env_path, env_content);
self.components.insert("drive".to_string(), ComponentConfig {
name: "drive".to_string(),
required: true,
ports: vec![9000, 9001],
dependencies: vec![],
linux_packages: vec![],
macos_packages: vec![],
windows_packages: vec![],
download_url: Some("https://dl.min.io/server/minio/release/linux-amd64/minio".to_string()),
binary_name: Some("minio".to_string()),
pre_install_cmds_linux: vec![],
post_install_cmds_linux: vec![
"wget https://dl.min.io/client/mc/release/linux-amd64/mc -O {{BIN_PATH}}/mc".to_string(),
"chmod +x {{BIN_PATH}}/mc".to_string(),
],
pre_install_cmds_macos: vec![],
post_install_cmds_macos: vec![
"wget https://dl.min.io/client/mc/release/darwin-amd64/mc -O {{BIN_PATH}}/mc".to_string(),
"chmod +x {{BIN_PATH}}/mc".to_string()
],
pre_install_cmds_windows: vec![],
post_install_cmds_windows: vec![],
// No env vars here; credentials are read from .env at runtime
// Provide drive root credentials via environment variables
env_vars: HashMap::from([
("DRIVE_ROOT_USER".to_string(), drive_user.clone()),
("DRIVE_ROOT_PASSWORD".to_string(), drive_password.clone())
]),
exec_cmd: "nohup {{BIN_PATH}}/minio server {{DATA_PATH}} --address :9000 --console-address :9001 > {{LOGS_PATH}}/minio.log 2>&1 & sleep 5 && {{BIN_PATH}}/mc alias set drive http://localhost:9000 $DRIVE_ROOT_USER $DRIVE_ROOT_PASSWORD && {{BIN_PATH}}/mc mb drive/default.gbai || true".to_string(),
});
self.components.insert(
"drive".to_string(),
ComponentConfig {
name: "drive".to_string(),
required: true,
ports: vec![9000, 9001],
dependencies: vec![],
linux_packages: vec![],
macos_packages: vec![],
windows_packages: vec![],
download_url: Some(
"https://dl.min.io/server/minio/release/linux-amd64/minio".to_string(),
),
binary_name: Some("minio".to_string()),
pre_install_cmds_linux: vec![],
post_install_cmds_linux: vec![
"wget https://dl.min.io/client/mc/release/linux-amd64/mc -O {{BIN_PATH}}/mc"
.to_string(),
"chmod +x {{BIN_PATH}}/mc".to_string(),
],
pre_install_cmds_macos: vec![],
post_install_cmds_macos: vec![
"wget https://dl.min.io/client/mc/release/darwin-amd64/mc -O {{BIN_PATH}}/mc"
.to_string(),
"chmod +x {{BIN_PATH}}/mc".to_string(),
],
pre_install_cmds_windows: vec![],
post_install_cmds_windows: vec![],
env_vars: HashMap::from([
("DRIVE_ROOT_USER".to_string(), drive_user.clone()),
("DRIVE_ROOT_PASSWORD".to_string(), drive_password.clone()),
]),
data_download_list: Vec::new(),
exec_cmd: "nohup {{BIN_PATH}}/minio server {{DATA_PATH}} --address :9000 --console-address :9001 > {{LOGS_PATH}}/minio.log 2>&1 & sleep 5 && {{BIN_PATH}}/mc alias set drive http://localhost:9000 $DRIVE_ROOT_USER $DRIVE_ROOT_PASSWORD && {{BIN_PATH}}/mc mb drive/default.gbai || true".to_string(),
},
);
self.update_drive_credentials_in_database(&encrypted_drive_password)
.ok();
@ -140,318 +142,368 @@ env_vars: HashMap::from([
.ok()
.and_then(|url| {
if let Some(stripped) = url.strip_prefix("postgres://gbuser:") {
if let Some(at_pos) = stripped.find('@') {
Some(stripped[..at_pos].to_string())
} else {
None
}
stripped.split('@').next().map(|s| s.to_string())
} else {
None
}
})
.unwrap_or_else(|| self.generate_secure_password(16));
self.components.insert("tables".to_string(), ComponentConfig {
name: "tables".to_string(),
required: true,
ports: vec![5432],
dependencies: vec![],
linux_packages: vec![],
macos_packages: vec![],
windows_packages: vec![],
download_url: Some("https://github.com/theseus-rs/postgresql-binaries/releases/download/18.0.0/postgresql-18.0.0-x86_64-unknown-linux-gnu.tar.gz".to_string()),
binary_name: Some("postgres".to_string()),
pre_install_cmds_linux: vec![],
post_install_cmds_linux: vec![
"chmod +x ./bin/*".to_string(),
format!("if [ ! -d \"{{{{DATA_PATH}}}}/pgdata\" ]; then PG_PASSWORD={} ./bin/initdb -D {{{{DATA_PATH}}}}/pgdata -U gbuser --pwfile=<(echo $PG_PASSWORD); fi", db_password).to_string(),
"echo \"data_directory = '{{DATA_PATH}}/pgdata'\" > {{CONF_PATH}}/postgresql.conf".to_string(),
"echo \"ident_file = '{{CONF_PATH}}/pg_ident.conf'\" >> {{CONF_PATH}}/postgresql.conf".to_string(),
"echo \"port = 5432\" >> {{CONF_PATH}}/postgresql.conf".to_string(),
"echo \"listen_addresses = '*'\" >> {{CONF_PATH}}/postgresql.conf".to_string(),
"echo \"log_directory = '{{LOGS_PATH}}'\" >> {{CONF_PATH}}/postgresql.conf".to_string(),
"echo \"logging_collector = on\" >> {{CONF_PATH}}/postgresql.conf".to_string(),
"echo \"host all all all md5\" > {{CONF_PATH}}/pg_hba.conf".to_string(),
"touch {{CONF_PATH}}/pg_ident.conf".to_string(),
// Start PostgreSQL with wait flag
"./bin/pg_ctl -D {{DATA_PATH}}/pgdata -l {{LOGS_PATH}}/postgres.log start -w -t 30".to_string(),
// Wait for PostgreSQL to be fully ready
"sleep 5".to_string(),
// Check if PostgreSQL is accepting connections with retries
"for i in $(seq 1 30); do ./bin/pg_isready -h localhost -p 5432 -U gbuser >/dev/null 2>&1 && echo 'PostgreSQL is ready' && break || echo \"Waiting for PostgreSQL... attempt $i/30\" >&2; sleep 2; done".to_string(),
// Final verification
"./bin/pg_isready -h localhost -p 5432 -U gbuser || { echo 'ERROR: PostgreSQL failed to start properly' >&2; cat {{LOGS_PATH}}/postgres.log >&2; exit 1; }".to_string(),
// Create database (separate command to ensure previous steps completed)
format!("PGPASSWORD={} ./bin/psql -h localhost -p 5432 -U gbuser -d postgres -c \"CREATE DATABASE botserver WITH OWNER gbuser\" 2>&1 | grep -v 'already exists' || true", db_password)
],
pre_install_cmds_macos: vec![],
post_install_cmds_macos: vec![
"chmod +x ./bin/*".to_string(),
"if [ ! -d \"{{DATA_PATH}}/pgdata\" ]; then ./bin/initdb -D {{DATA_PATH}}/pgdata -U postgres; fi".to_string(),
],
pre_install_cmds_windows: vec![],
post_install_cmds_windows: vec![],
env_vars: HashMap::new(),
exec_cmd: "./bin/pg_ctl -D {{DATA_PATH}}/pgdata -l {{LOGS_PATH}}/postgres.log start -w -t 30".to_string(),
});
self.components.insert(
"tables".to_string(),
ComponentConfig {
name: "tables".to_string(),
required: true,
ports: vec![5432],
dependencies: vec![],
linux_packages: vec![],
macos_packages: vec![],
windows_packages: vec![],
download_url: Some(
"https://github.com/theseus-rs/postgresql-binaries/releases/download/18.0.0/postgresql-18.0.0-x86_64-unknown-linux-gnu.tar.gz".to_string(),
),
binary_name: Some("postgres".to_string()),
pre_install_cmds_linux: vec![],
post_install_cmds_linux: vec![
"chmod +x ./bin/*".to_string(),
format!("if [ ! -d \"{{{{DATA_PATH}}}}/pgdata\" ]; then PG_PASSWORD={} ./bin/initdb -D {{{{DATA_PATH}}}}/pgdata -U gbuser --pwfile=<(echo $PG_PASSWORD); fi", db_password),
"echo \"data_directory = '{{DATA_PATH}}/pgdata'\" > {{CONF_PATH}}/postgresql.conf".to_string(),
"echo \"ident_file = '{{CONF_PATH}}/pg_ident.conf'\" >> {{CONF_PATH}}/postgresql.conf".to_string(),
"echo \"port = 5432\" >> {{CONF_PATH}}/postgresql.conf".to_string(),
"echo \"listen_addresses = '*'\" >> {{CONF_PATH}}/postgresql.conf".to_string(),
"echo \"log_directory = '{{LOGS_PATH}}'\" >> {{CONF_PATH}}/postgresql.conf".to_string(),
"echo \"logging_collector = on\" >> {{CONF_PATH}}/postgresql.conf".to_string(),
"echo \"host all all all md5\" > {{CONF_PATH}}/pg_hba.conf".to_string(),
"touch {{CONF_PATH}}/pg_ident.conf".to_string(),
"./bin/pg_ctl -D {{DATA_PATH}}/pgdata -l {{LOGS_PATH}}/postgres.log start -w -t 30".to_string(),
"sleep 5".to_string(),
"for i in $(seq 1 30); do ./bin/pg_isready -h localhost -p 5432 -U gbuser >/dev/null 2>&1 && echo 'PostgreSQL is ready' && break || echo \"Waiting for PostgreSQL... attempt $i/30\" >&2; sleep 2; done".to_string(),
"./bin/pg_isready -h localhost -p 5432 -U gbuser || { echo 'ERROR: PostgreSQL failed to start properly' >&2; cat {{LOGS_PATH}}/postgres.log >&2; exit 1; }".to_string(),
format!("PGPASSWORD={} ./bin/psql -h localhost -p 5432 -U gbuser -d postgres -c \"CREATE DATABASE botserver WITH OWNER gbuser\" 2>&1 | grep -v 'already exists' || true", db_password),
],
pre_install_cmds_macos: vec![],
post_install_cmds_macos: vec![
"chmod +x ./bin/*".to_string(),
"if [ ! -d \"{{DATA_PATH}}/pgdata\" ]; then ./bin/initdb -D {{DATA_PATH}}/pgdata -U postgres; fi".to_string(),
],
pre_install_cmds_windows: vec![],
post_install_cmds_windows: vec![],
env_vars: HashMap::new(),
data_download_list: Vec::new(),
exec_cmd: "./bin/pg_ctl -D {{DATA_PATH}}/pgdata -l {{LOGS_PATH}}/postgres.log start -w -t 30".to_string(),
},
);
}
fn register_cache(&mut self) {
self.components.insert(
"cache".to_string(),
ComponentConfig {
name: "cache".to_string(),
required: true,
ports: vec![6379],
dependencies: vec![],
linux_packages: vec![],
macos_packages: vec![],
windows_packages: vec![],
download_url: Some("https://download.valkey.io/releases/valkey-9.0.0-jammy-x86_64.tar.gz".to_string()),
binary_name: Some("valkey-server".to_string()),
pre_install_cmds_linux: vec![],
post_install_cmds_linux: vec![
"tar -xzf {{BIN_PATH}}/valkey-9.0.0-jammy-x86_64.tar.gz -C {{BIN_PATH}}".to_string(),
"mv {{BIN_PATH}}/valkey-9.0.0-jammy-x86_64/valkey-server {{BIN_PATH}}/valkey-server".to_string(),
],
pre_install_cmds_macos: vec![],
post_install_cmds_macos: vec![],
pre_install_cmds_windows: vec![],
post_install_cmds_windows: vec![],
env_vars: HashMap::new(),
exec_cmd: "{{BIN_PATH}}/valkey-server --port 6379 --dir {{DATA_PATH}}".to_string(),
},
);
self.components.insert(
"cache".to_string(),
ComponentConfig {
name: "cache".to_string(),
required: true,
ports: vec![6379],
dependencies: vec![],
linux_packages: vec![],
macos_packages: vec![],
windows_packages: vec![],
download_url: Some(
"https://download.valkey.io/releases/valkey-9.0.0-jammy-x86_64.tar.gz".to_string(),
),
binary_name: Some("valkey-server".to_string()),
pre_install_cmds_linux: vec![],
post_install_cmds_linux: vec![
"tar -xzf {{BIN_PATH}}/valkey-9.0.0-jammy-x86_64.tar.gz -C {{BIN_PATH}}".to_string(),
"mv {{BIN_PATH}}/valkey-9.0.0-jammy-x86_64/valkey-server {{BIN_PATH}}/valkey-server".to_string(),
],
pre_install_cmds_macos: vec![],
post_install_cmds_macos: vec![],
pre_install_cmds_windows: vec![],
post_install_cmds_windows: vec![],
env_vars: HashMap::new(),
data_download_list: Vec::new(),
exec_cmd: "{{BIN_PATH}}/valkey-server --port 6379 --dir {{DATA_PATH}}".to_string(),
},
);
}
fn register_llm(&mut self) {
self.components.insert("llm".to_string(), ComponentConfig {
name: "llm".to_string(),
required: true,
ports: vec![8081, 8082],
dependencies: vec![],
linux_packages: vec!["unzip".to_string()],
macos_packages: vec!["unzip".to_string()],
windows_packages: vec![],
download_url: Some("https://github.com/ggml-org/llama.cpp/releases/download/b6148/llama-b6148-bin-ubuntu-x64.zip".to_string()),
binary_name: Some("llama-server".to_string()),
pre_install_cmds_linux: vec![],
post_install_cmds_linux: vec![
"wget -q https://huggingface.co/bartowski/DeepSeek-R1-Distill-Qwen-1.5B-GGUF/resolve/main/DeepSeek-R1-Distill-Qwen-1.5B-Q3_K_M.gguf -P {{DATA_PATH}}".to_string(),
"wget -q https://huggingface.co/CompendiumLabs/bge-small-en-v1.5-gguf/resolve/main/bge-small-en-v1.5-f32.gguf -P {{DATA_PATH}}".to_string()
],
pre_install_cmds_macos: vec![],
post_install_cmds_macos: vec![
"wget -q https://huggingface.co/bartowski/DeepSeek-R1-Distill-Qwen-1.5B-GGUF/resolve/main/DeepSeek-R1-Distill-Qwen-1.5B-Q3_K_M.gguf -P {{DATA_PATH}}".to_string(),
"wget -q https://huggingface.co/CompendiumLabs/bge-small-en-v1.5-gguf/resolve/main/bge-small-en-v1.5-f32.gguf -P {{DATA_PATH}}".to_string()
],
pre_install_cmds_windows: vec![],
post_install_cmds_windows: vec![],
env_vars: HashMap::new(),
exec_cmd: "nohup {{BIN_PATH}}/llama-server -m {{DATA_PATH}}/DeepSeek-R1-Distill-Qwen-1.5B-Q3_K_M.gguf --port 8081 > {{LOGS_PATH}}/llm-main.log 2>&1 & nohup {{BIN_PATH}}/llama-server -m {{DATA_PATH}}/bge-small-en-v1.5-f32.gguf --port 8082 --embedding > {{LOGS_PATH}}/llm-embed.log 2>&1 &".to_string(),
});
self.components.insert(
"llm".to_string(),
ComponentConfig {
name: "llm".to_string(),
required: true,
ports: vec![8081, 8082],
dependencies: vec![],
linux_packages: vec!["unzip".to_string()],
macos_packages: vec!["unzip".to_string()],
windows_packages: vec![],
download_url: Some(
"https://github.com/ggml-org/llama.cpp/releases/download/b6148/llama-b6148-bin-ubuntu-x64.zip".to_string(),
),
binary_name: Some("llama-server".to_string()),
pre_install_cmds_linux: vec![],
post_install_cmds_linux: vec![],
pre_install_cmds_macos: vec![],
post_install_cmds_macos: vec![],
pre_install_cmds_windows: vec![],
post_install_cmds_windows: vec![],
env_vars: HashMap::new(),
data_download_list: vec![
"https://huggingface.co/bartowski/DeepSeek-R1-Distill-Qwen-1.5B-GGUF/resolve/main/DeepSeek-R1-Distill-Qwen-1.5B-Q3_K_M.gguf".to_string(),
"https://huggingface.co/CompendiumLabs/bge-small-en-v1.5-gguf/resolve/main/bge-small-en-v1.5-f32.gguf".to_string(),
],
exec_cmd: "nohup {{BIN_PATH}}/llama-server -m {{DATA_PATH}}/DeepSeek-R1-Distill-Qwen-1.5B-Q3_K_M.gguf --port 8081 > {{LOGS_PATH}}/llm-main.log 2>&1 & nohup {{BIN_PATH}}/llama-server -m {{DATA_PATH}}/bge-small-en-v1.5-f32.gguf --port 8082 --embedding > {{LOGS_PATH}}/llm-embed.log 2>&1 &".to_string(),
},
);
}
fn register_email(&mut self) {
self.components.insert("email".to_string(), ComponentConfig {
name: "email".to_string(),
required: false,
ports: vec![25, 80, 110, 143, 465, 587, 993, 995, 4190],
dependencies: vec![],
linux_packages: vec!["libcap2-bin".to_string(), "resolvconf".to_string()],
macos_packages: vec![],
windows_packages: vec![],
download_url: Some("https://github.com/stalwartlabs/stalwart/releases/download/v0.13.1/stalwart-x86_64-unknown-linux-gnu.tar.gz".to_string()),
binary_name: Some("stalwart".to_string()),
pre_install_cmds_linux: vec![],
post_install_cmds_linux: vec![
"setcap 'cap_net_bind_service=+ep' {{BIN_PATH}}/stalwart".to_string()
],
pre_install_cmds_macos: vec![],
post_install_cmds_macos: vec![],
pre_install_cmds_windows: vec![],
post_install_cmds_windows: vec![],
env_vars: HashMap::new(),
exec_cmd: "{{BIN_PATH}}/stalwart --config {{CONF_PATH}}/config.toml".to_string(),
});
self.components.insert(
"email".to_string(),
ComponentConfig {
name: "email".to_string(),
required: false,
ports: vec![25, 80, 110, 143, 465, 587, 993, 995, 4190],
dependencies: vec![],
linux_packages: vec!["libcap2-bin".to_string(), "resolvconf".to_string()],
macos_packages: vec![],
windows_packages: vec![],
download_url: Some(
"https://github.com/stalwartlabs/stalwart/releases/download/v0.13.1/stalwart-x86_64-unknown-linux-gnu.tar.gz".to_string(),
),
binary_name: Some("stalwart".to_string()),
pre_install_cmds_linux: vec![],
post_install_cmds_linux: vec![
"setcap 'cap_net_bind_service=+ep' {{BIN_PATH}}/stalwart".to_string(),
],
pre_install_cmds_macos: vec![],
post_install_cmds_macos: vec![],
pre_install_cmds_windows: vec![],
post_install_cmds_windows: vec![],
env_vars: HashMap::new(),
data_download_list: Vec::new(),
exec_cmd: "{{BIN_PATH}}/stalwart --config {{CONF_PATH}}/config.toml".to_string(),
},
);
}
fn register_proxy(&mut self) {
self.components.insert("proxy".to_string(), ComponentConfig {
name: "proxy".to_string(),
required: false,
ports: vec![80, 443],
dependencies: vec![],
linux_packages: vec!["libcap2-bin".to_string()],
macos_packages: vec![],
windows_packages: vec![],
download_url: Some("https://github.com/caddyserver/caddy/releases/download/v2.10.0-beta.3/caddy_2.10.0-beta.3_linux_amd64.tar.gz".to_string()),
binary_name: Some("caddy".to_string()),
pre_install_cmds_linux: vec![],
post_install_cmds_linux: vec![
"setcap 'cap_net_bind_service=+ep' {{BIN_PATH}}/caddy".to_string()
],
pre_install_cmds_macos: vec![],
post_install_cmds_macos: vec![],
pre_install_cmds_windows: vec![],
post_install_cmds_windows: vec![],
env_vars: HashMap::from([
("XDG_DATA_HOME".to_string(), "{{DATA_PATH}}".to_string())
]),
exec_cmd: "{{BIN_PATH}}/caddy run --config {{CONF_PATH}}/Caddyfile".to_string(),
});
self.components.insert(
"proxy".to_string(),
ComponentConfig {
name: "proxy".to_string(),
required: false,
ports: vec![80, 443],
dependencies: vec![],
linux_packages: vec!["libcap2-bin".to_string()],
macos_packages: vec![],
windows_packages: vec![],
download_url: Some(
"https://github.com/caddyserver/caddy/releases/download/v2.10.0-beta.3/caddy_2.10.0-beta.3_linux_amd64.tar.gz".to_string(),
),
binary_name: Some("caddy".to_string()),
pre_install_cmds_linux: vec![],
post_install_cmds_linux: vec![
"setcap 'cap_net_bind_service=+ep' {{BIN_PATH}}/caddy".to_string(),
],
pre_install_cmds_macos: vec![],
post_install_cmds_macos: vec![],
pre_install_cmds_windows: vec![],
post_install_cmds_windows: vec![],
env_vars: HashMap::from([("XDG_DATA_HOME".to_string(), "{{DATA_PATH}}".to_string())]),
data_download_list: Vec::new(),
exec_cmd: "{{BIN_PATH}}/caddy run --config {{CONF_PATH}}/Caddyfile".to_string(),
},
);
}
fn register_directory(&mut self) {
self.components.insert("directory".to_string(), ComponentConfig {
name: "directory".to_string(),
required: false,
ports: vec![8080],
dependencies: vec![],
linux_packages: vec!["libcap2-bin".to_string()],
macos_packages: vec![],
windows_packages: vec![],
download_url: Some("https://github.com/zitadel/zitadel/releases/download/v2.71.2/zitadel-linux-amd64.tar.gz".to_string()),
binary_name: Some("zitadel".to_string()),
pre_install_cmds_linux: vec![],
post_install_cmds_linux: vec![
"setcap 'cap_net_bind_service=+ep' {{BIN_PATH}}/zitadel".to_string()
],
pre_install_cmds_macos: vec![],
post_install_cmds_macos: vec![],
pre_install_cmds_windows: vec![],
post_install_cmds_windows: vec![],
env_vars: HashMap::new(),
exec_cmd: "{{BIN_PATH}}/zitadel start --config {{CONF_PATH}}/zitadel.yaml".to_string(),
});
self.components.insert(
"directory".to_string(),
ComponentConfig {
name: "directory".to_string(),
required: false,
ports: vec![8080],
dependencies: vec![],
linux_packages: vec!["libcap2-bin".to_string()],
macos_packages: vec![],
windows_packages: vec![],
download_url: Some(
"https://github.com/zitadel/zitadel/releases/download/v2.71.2/zitadel-linux-amd64.tar.gz".to_string(),
),
binary_name: Some("zitadel".to_string()),
pre_install_cmds_linux: vec![],
post_install_cmds_linux: vec![
"setcap 'cap_net_bind_service=+ep' {{BIN_PATH}}/zitadel".to_string(),
],
pre_install_cmds_macos: vec![],
post_install_cmds_macos: vec![],
pre_install_cmds_windows: vec![],
post_install_cmds_windows: vec![],
env_vars: HashMap::new(),
data_download_list: Vec::new(),
exec_cmd: "{{BIN_PATH}}/zitadel start --config {{CONF_PATH}}/zitadel.yaml".to_string(),
},
);
}
fn register_alm(&mut self) {
self.components.insert("alm".to_string(), ComponentConfig {
name: "alm".to_string(),
required: false,
ports: vec![3000],
dependencies: vec![],
linux_packages: vec!["git".to_string(), "git-lfs".to_string()],
macos_packages: vec!["git".to_string(), "git-lfs".to_string()],
windows_packages: vec![],
download_url: Some("https://codeberg.org/forgejo/forgejo/releases/download/v10.0.2/forgejo-10.0.2-linux-amd64".to_string()),
binary_name: Some("forgejo".to_string()),
pre_install_cmds_linux: vec![],
post_install_cmds_linux: vec![],
pre_install_cmds_macos: vec![],
post_install_cmds_macos: vec![],
pre_install_cmds_windows: vec![],
post_install_cmds_windows: vec![],
env_vars: HashMap::from([
("USER".to_string(), "alm".to_string()),
("HOME".to_string(), "{{DATA_PATH}}".to_string())
]),
exec_cmd: "{{BIN_PATH}}/forgejo web --work-path {{DATA_PATH}}".to_string(),
});
self.components.insert(
"alm".to_string(),
ComponentConfig {
name: "alm".to_string(),
required: false,
ports: vec![3000],
dependencies: vec![],
linux_packages: vec!["git".to_string(), "git-lfs".to_string()],
macos_packages: vec!["git".to_string(), "git-lfs".to_string()],
windows_packages: vec![],
download_url: Some(
"https://codeberg.org/forgejo/forgejo/releases/download/v10.0.2/forgejo-10.0.2-linux-amd64".to_string(),
),
binary_name: Some("forgejo".to_string()),
pre_install_cmds_linux: vec![],
post_install_cmds_linux: vec![],
pre_install_cmds_macos: vec![],
post_install_cmds_macos: vec![],
pre_install_cmds_windows: vec![],
post_install_cmds_windows: vec![],
env_vars: HashMap::from([
("USER".to_string(), "alm".to_string()),
("HOME".to_string(), "{{DATA_PATH}}".to_string()),
]),
data_download_list: Vec::new(),
exec_cmd: "{{BIN_PATH}}/forgejo web --work-path {{DATA_PATH}}".to_string(),
},
);
}
fn register_alm_ci(&mut self) {
self.components.insert("alm-ci".to_string(), ComponentConfig {
name: "alm-ci".to_string(),
required: false,
ports: vec![],
dependencies: vec!["alm".to_string()],
linux_packages: vec!["git".to_string(), "curl".to_string(), "gnupg".to_string(), "ca-certificates".to_string(), "build-essential".to_string()],
macos_packages: vec!["git".to_string(), "node".to_string()],
windows_packages: vec![],
download_url: Some("https://code.forgejo.org/forgejo/runner/releases/download/v6.3.1/forgejo-runner-6.3.1-linux-amd64".to_string()),
binary_name: Some("forgejo-runner".to_string()),
pre_install_cmds_linux: vec![
"curl -fsSL https://deb.nodesource.com/setup_22.x | bash -".to_string(),
"apt-get install -y nodejs".to_string()
],
post_install_cmds_linux: vec![
"npm install -g pnpm@latest".to_string()
],
pre_install_cmds_macos: vec![],
post_install_cmds_macos: vec![
"npm install -g pnpm@latest".to_string()
],
pre_install_cmds_windows: vec![],
post_install_cmds_windows: vec![],
env_vars: HashMap::new(),
exec_cmd: "{{BIN_PATH}}/forgejo-runner daemon --config {{CONF_PATH}}/config.yaml".to_string(),
});
self.components.insert(
"alm-ci".to_string(),
ComponentConfig {
name: "alm-ci".to_string(),
required: false,
ports: vec![],
dependencies: vec!["alm".to_string()],
linux_packages: vec![
"git".to_string(),
"curl".to_string(),
"gnupg".to_string(),
"ca-certificates".to_string(),
"build-essential".to_string(),
],
macos_packages: vec!["git".to_string(), "node".to_string()],
windows_packages: vec![],
download_url: Some(
"https://code.forgejo.org/forgejo/runner/releases/download/v6.3.1/forgejo-runner-6.3.1-linux-amd64".to_string(),
),
binary_name: Some("forgejo-runner".to_string()),
pre_install_cmds_linux: vec![
"curl -fsSL https://deb.nodesource.com/setup_22.x | bash -".to_string(),
"apt-get install -y nodejs".to_string(),
],
post_install_cmds_linux: vec!["npm install -g pnpm@latest".to_string()],
pre_install_cmds_macos: vec![],
post_install_cmds_macos: vec!["npm install -g pnpm@latest".to_string()],
pre_install_cmds_windows: vec![],
post_install_cmds_windows: vec![],
env_vars: HashMap::new(),
data_download_list: Vec::new(),
exec_cmd: "{{BIN_PATH}}/forgejo-runner daemon --config {{CONF_PATH}}/config.yaml".to_string(),
},
);
}
fn register_dns(&mut self) {
self.components.insert("dns".to_string(), ComponentConfig {
name: "dns".to_string(),
required: false,
ports: vec![53],
dependencies: vec![],
linux_packages: vec![],
macos_packages: vec![],
windows_packages: vec![],
download_url: Some("https://github.com/coredns/coredns/releases/download/v1.12.4/coredns_1.12.4_linux_amd64.tgz".to_string()),
binary_name: Some("coredns".to_string()),
pre_install_cmds_linux: vec![],
post_install_cmds_linux: vec![
"setcap cap_net_bind_service=+ep {{BIN_PATH}}/coredns".to_string()
],
pre_install_cmds_macos: vec![],
post_install_cmds_macos: vec![],
pre_install_cmds_windows: vec![],
post_install_cmds_windows: vec![],
env_vars: HashMap::new(),
exec_cmd: "{{BIN_PATH}}/coredns -conf {{CONF_PATH}}/Corefile".to_string(),
});
self.components.insert(
"dns".to_string(),
ComponentConfig {
name: "dns".to_string(),
required: false,
ports: vec![53],
dependencies: vec![],
linux_packages: vec![],
macos_packages: vec![],
windows_packages: vec![],
download_url: Some(
"https://github.com/coredns/coredns/releases/download/v1.12.4/coredns_1.12.4_linux_amd64.tgz".to_string(),
),
binary_name: Some("coredns".to_string()),
pre_install_cmds_linux: vec![],
post_install_cmds_linux: vec![
"setcap cap_net_bind_service=+ep {{BIN_PATH}}/coredns".to_string(),
],
pre_install_cmds_macos: vec![],
post_install_cmds_macos: vec![],
pre_install_cmds_windows: vec![],
post_install_cmds_windows: vec![],
env_vars: HashMap::new(),
data_download_list: Vec::new(),
exec_cmd: "{{BIN_PATH}}/coredns -conf {{CONF_PATH}}/Corefile".to_string(),
},
);
}
fn register_webmail(&mut self) {
self.components.insert("webmail".to_string(), ComponentConfig {
name: "webmail".to_string(),
required: false,
ports: vec![8080],
dependencies: vec!["email".to_string()],
linux_packages: vec!["ca-certificates".to_string(), "apt-transport-https".to_string(), "php8.1".to_string(), "php8.1-fpm".to_string()],
macos_packages: vec!["php".to_string()],
windows_packages: vec![],
download_url: Some("https://github.com/roundcube/roundcubemail/releases/download/1.6.6/roundcubemail-1.6.6-complete.tar.gz".to_string()),
binary_name: None,
pre_install_cmds_linux: vec![],
post_install_cmds_linux: vec![],
pre_install_cmds_macos: vec![],
post_install_cmds_macos: vec![],
pre_install_cmds_windows: vec![],
post_install_cmds_windows: vec![],
env_vars: HashMap::new(),
exec_cmd: "php -S 0.0.0.0:8080 -t {{DATA_PATH}}/roundcubemail".to_string(),
});
self.components.insert(
"webmail".to_string(),
ComponentConfig {
name: "webmail".to_string(),
required: false,
ports: vec![8080],
dependencies: vec!["email".to_string()],
linux_packages: vec![
"ca-certificates".to_string(),
"apt-transport-https".to_string(),
"php8.1".to_string(),
"php8.1-fpm".to_string(),
],
macos_packages: vec!["php".to_string()],
windows_packages: vec![],
download_url: Some(
"https://github.com/roundcube/roundcubemail/releases/download/1.6.6/roundcubemail-1.6.6-complete.tar.gz".to_string(),
),
binary_name: None,
pre_install_cmds_linux: vec![],
post_install_cmds_linux: vec![],
pre_install_cmds_macos: vec![],
post_install_cmds_macos: vec![],
pre_install_cmds_windows: vec![],
post_install_cmds_windows: vec![],
env_vars: HashMap::new(),
data_download_list: Vec::new(),
exec_cmd: "php -S 0.0.0.0:8080 -t {{DATA_PATH}}/roundcubemail".to_string(),
},
);
}
fn register_meeting(&mut self) {
self.components.insert("meeting".to_string(), ComponentConfig {
name: "meeting".to_string(),
required: false,
ports: vec![7880, 3478],
dependencies: vec![],
linux_packages: vec!["coturn".to_string()],
macos_packages: vec![],
windows_packages: vec![],
download_url: Some("https://github.com/livekit/livekit/releases/download/v1.8.4/livekit_1.8.4_linux_amd64.tar.gz".to_string()),
binary_name: Some("livekit-server".to_string()),
pre_install_cmds_linux: vec![],
post_install_cmds_linux: vec![],
pre_install_cmds_macos: vec![],
post_install_cmds_macos: vec![],
pre_install_cmds_windows: vec![],
post_install_cmds_windows: vec![],
env_vars: HashMap::new(),
exec_cmd: "{{BIN_PATH}}/livekit-server --config {{CONF_PATH}}/config.yaml".to_string(),
});
self.components.insert(
"meeting".to_string(),
ComponentConfig {
name: "meeting".to_string(),
required: false,
ports: vec![7880, 3478],
dependencies: vec![],
linux_packages: vec!["coturn".to_string()],
macos_packages: vec![],
windows_packages: vec![],
download_url: Some(
"https://github.com/livekit/livekit/releases/download/v1.8.4/livekit_1.8.4_linux_amd64.tar.gz".to_string(),
),
binary_name: Some("livekit-server".to_string()),
pre_install_cmds_linux: vec![],
post_install_cmds_linux: vec![],
pre_install_cmds_macos: vec![],
post_install_cmds_macos: vec![],
pre_install_cmds_windows: vec![],
post_install_cmds_windows: vec![],
env_vars: HashMap::new(),
data_download_list: Vec::new(),
exec_cmd: "{{BIN_PATH}}/livekit-server --config {{CONF_PATH}}/config.yaml".to_string(),
},
);
}
fn register_table_editor(&mut self) {
@ -474,6 +526,7 @@ self.components.insert(
pre_install_cmds_windows: vec![],
post_install_cmds_windows: vec![],
env_vars: HashMap::new(),
data_download_list: Vec::new(),
exec_cmd: "{{BIN_PATH}}/nocodb".to_string(),
},
);
@ -499,6 +552,7 @@ self.components.insert(
pre_install_cmds_windows: vec![],
post_install_cmds_windows: vec![],
env_vars: HashMap::new(),
data_download_list: Vec::new(),
exec_cmd: "coolwsd --config-file={{CONF_PATH}}/coolwsd.xml".to_string(),
},
);
@ -524,6 +578,7 @@ self.components.insert(
pre_install_cmds_windows: vec![],
post_install_cmds_windows: vec![],
env_vars: HashMap::new(),
data_download_list: Vec::new(),
exec_cmd: "xrdp --nodaemon".to_string(),
},
);
@ -549,6 +604,7 @@ self.components.insert(
pre_install_cmds_windows: vec![],
post_install_cmds_windows: vec![],
env_vars: HashMap::new(),
data_download_list: Vec::new(),
exec_cmd: "".to_string(),
},
);
@ -582,6 +638,7 @@ self.components.insert(
pre_install_cmds_windows: vec![],
post_install_cmds_windows: vec![],
env_vars: HashMap::from([("DISPLAY".to_string(), ":99".to_string())]),
data_download_list: Vec::new(),
exec_cmd: "".to_string(),
},
);
@ -607,31 +664,38 @@ self.components.insert(
pre_install_cmds_windows: vec![],
post_install_cmds_windows: vec![],
env_vars: HashMap::new(),
data_download_list: Vec::new(),
exec_cmd: "".to_string(),
},
);
}
fn register_vector_db(&mut self) {
self.components.insert("vector_db".to_string(), ComponentConfig {
name: "vector_db".to_string(),
required: false,
ports: vec![6333],
dependencies: vec![],
linux_packages: vec![],
macos_packages: vec![],
windows_packages: vec![],
download_url: Some("https://github.com/qdrant/qdrant/releases/latest/download/qdrant-x86_64-unknown-linux-gnu.tar.gz".to_string()),
binary_name: Some("qdrant".to_string()),
pre_install_cmds_linux: vec![],
post_install_cmds_linux: vec![],
pre_install_cmds_macos: vec![],
post_install_cmds_macos: vec![],
pre_install_cmds_windows: vec![],
post_install_cmds_windows: vec![],
env_vars: HashMap::new(),
exec_cmd: "{{BIN_PATH}}/qdrant --storage-path {{DATA_PATH}}".to_string(),
});
self.components.insert(
"vector_db".to_string(),
ComponentConfig {
name: "vector_db".to_string(),
required: false,
ports: vec![6333],
dependencies: vec![],
linux_packages: vec![],
macos_packages: vec![],
windows_packages: vec![],
download_url: Some(
"https://github.com/qdrant/qdrant/releases/latest/download/qdrant-x86_64-unknown-linux-gnu.tar.gz".to_string(),
),
binary_name: Some("qdrant".to_string()),
pre_install_cmds_linux: vec![],
post_install_cmds_linux: vec![],
pre_install_cmds_macos: vec![],
post_install_cmds_macos: vec![],
pre_install_cmds_windows: vec![],
post_install_cmds_windows: vec![],
env_vars: HashMap::new(),
data_download_list: Vec::new(),
exec_cmd: "{{BIN_PATH}}/qdrant --storage-path {{DATA_PATH}}".to_string(),
},
);
}
fn register_host(&mut self) {
@ -661,6 +725,7 @@ self.components.insert(
pre_install_cmds_windows: vec![],
post_install_cmds_windows: vec![],
env_vars: HashMap::new(),
data_download_list: Vec::new(),
exec_cmd: "".to_string(),
},
);
@ -673,7 +738,6 @@ self.components.insert(
let conf_path = self.base_path.join("conf").join(&component.name);
let logs_path = self.base_path.join("logs").join(&component.name);
// For PostgreSQL, check if it's already running
if component.name == "tables" {
let check_cmd = format!(
"./bin/pg_ctl -D {} status",
@ -687,11 +751,7 @@ self.components.insert(
if let Ok(output) = check_output {
if output.status.success() {
trace!(
"Component {} is already running, skipping start",
component.name
);
// Return a dummy child process handle - PostgreSQL is already running
trace!("Component {} is already running, skipping start", component.name);
return Ok(std::process::Command::new("sh")
.arg("-c")
.arg("echo 'Already running'")
@ -707,11 +767,7 @@ self.components.insert(
.replace("{{CONF_PATH}}", &conf_path.to_string_lossy())
.replace("{{LOGS_PATH}}", &logs_path.to_string_lossy());
trace!(
"Starting component {} with command: {}",
component.name,
rendered_cmd
);
trace!("Starting component {} with command: {}", component.name, rendered_cmd);
let child = std::process::Command::new("sh")
.current_dir(&bin_path)
@ -719,16 +775,12 @@ self.components.insert(
.arg(&rendered_cmd)
.spawn();
// Handle "already running" errors gracefully
match child {
Ok(c) => Ok(c),
Err(e) => {
let err_msg = e.to_string();
if err_msg.contains("already running") || component.name == "tables" {
trace!(
"Component {} may already be running, continuing anyway",
component.name
);
trace!("Component {} may already be running, continuing anyway", component.name);
Ok(std::process::Command::new("sh")
.arg("-c")
.arg("echo 'Already running'")
@ -744,14 +796,9 @@ self.components.insert(
}
fn generate_secure_password(&self, length: usize) -> String {
// Use the non-deprecated `rng` function to obtain a thread-local RNG.
let mut rng = rand::rng();
// Generate `length` alphanumeric characters.
(0..length)
.map(|_| {
// `Alphanumeric` implements the `Distribution<u8>` trait.
// Use the fully qualified `rand::Rng::sample` method to avoid needing an explicit import.
let byte = rand::Rng::sample(&mut rng, Alphanumeric);
char::from(byte)
})

View file

@ -81,7 +81,7 @@ pub fn to_array(value: Dynamic) -> Array {
pub async fn download_file(
url: &str,
output_path: &str,
) -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
) -> Result<(), anyhow::Error> {
let url = url.to_string();
let output_path = output_path.to_string();
@ -115,7 +115,7 @@ pub async fn download_file(
trace!("Download completed: {} -> {}", url, output_path);
Ok(())
} else {
Err(format!("HTTP {}: {}", response.status(), url).into())
Err(anyhow::anyhow!("HTTP {}: {}", response.status(), url))
}
});