feat(bootstrap): remove legacy mode and simplify bootstrap process
Removed the legacy TABLES_SERVER environment variable check and related database connection logic. Simplified the bootstrap process to always generate new credentials and write them to .env file. Also updated drive monitor log message to use "Drive" instead of "S3" for consistency. #464
This commit is contained in:
parent
3ffc005cbd
commit
d1f6da70d8
4 changed files with 23 additions and 58 deletions
|
|
@ -63,7 +63,6 @@ impl BootstrapManager {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
|
||||
fn generate_secure_password(&self, length: usize) -> String {
|
||||
let mut rng = rand::rng();
|
||||
(0..length)
|
||||
|
|
@ -75,38 +74,6 @@ impl BootstrapManager {
|
|||
}
|
||||
|
||||
pub async fn bootstrap(&mut self) {
|
||||
if let Ok(tables_server) = std::env::var("TABLES_SERVER") {
|
||||
if !tables_server.is_empty() {
|
||||
info!(
|
||||
"Legacy mode detected (TABLES_SERVER present), skipping bootstrap installation"
|
||||
);
|
||||
let _database_url = std::env::var("DATABASE_URL").unwrap_or_else(|_| {
|
||||
let username =
|
||||
std::env::var("TABLES_USERNAME").unwrap_or_else(|_| "gbuser".to_string());
|
||||
let password =
|
||||
std::env::var("TABLES_PASSWORD").unwrap_or_else(|_| "postgres".to_string());
|
||||
let server =
|
||||
std::env::var("TABLES_SERVER").unwrap_or_else(|_| "localhost".to_string());
|
||||
let port = std::env::var("TABLES_PORT").unwrap_or_else(|_| "5432".to_string());
|
||||
let database =
|
||||
std::env::var("TABLES_DATABASE").unwrap_or_else(|_| "gbserver".to_string());
|
||||
format!(
|
||||
"postgres://{}:{}@{}:{}/{}",
|
||||
username, password, server, port, database
|
||||
)
|
||||
});
|
||||
match establish_pg_connection() {
|
||||
Ok(mut conn) => {
|
||||
if let Err(e) = self.apply_migrations(&mut conn) {
|
||||
log::warn!("Failed to apply migrations: {}", e);
|
||||
}
|
||||
}
|
||||
Err(e) => {
|
||||
log::warn!("Failed to connect to database: {}", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
let db_env_path = std::env::current_dir().unwrap().join(".env");
|
||||
let db_password = self.generate_secure_password(32);
|
||||
let database_url = std::env::var("DATABASE_URL").unwrap_or_else(|_| {
|
||||
|
|
@ -128,7 +95,6 @@ impl BootstrapManager {
|
|||
.and_then(|mut file| std::io::Write::write_all(&mut file, env_content.as_bytes()));
|
||||
|
||||
let _ = std::fs::write(&db_env_path, db_line);
|
||||
}
|
||||
|
||||
let pm = PackageManager::new(self.install_mode.clone(), self.tenant.clone()).unwrap();
|
||||
let required_components = vec!["tables", "drive", "cache", "llm"];
|
||||
|
|
|
|||
|
|
@ -240,15 +240,15 @@ impl DriveMonitor {
|
|||
Ok(())
|
||||
}
|
||||
async fn compile_tool(&self, client: &Client, file_path: &str) -> Result<(), Box<dyn Error + Send + Sync>> {
|
||||
info!("Fetching object from S3: bucket={}, key={}", &self.bucket_name, file_path);
|
||||
info!("Fetching object from Drive: bucket={}, key={}", &self.bucket_name, file_path);
|
||||
let response = match client.get_object().bucket(&self.bucket_name).key(file_path).send().await {
|
||||
Ok(res) => {
|
||||
info!("Successfully fetched object from S3: bucket={}, key={}, size={}",
|
||||
info!("Successfully fetched object from Drive: bucket={}, key={}, size={}",
|
||||
&self.bucket_name, file_path, res.content_length().unwrap_or(0));
|
||||
res
|
||||
}
|
||||
Err(e) => {
|
||||
log::error!("Failed to fetch object from S3: bucket={}, key={}, error={:?}",
|
||||
log::error!("Failed to fetch object from Drive: bucket={}, key={}, error={:?}",
|
||||
&self.bucket_name, file_path, e);
|
||||
return Err(e.into());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -54,7 +54,7 @@ let (_default_bot_id, llm_url, llm_model, embedding_url, embedding_model, llm_se
|
|||
info!("Restarting any existing llama-server processes...");
|
||||
if let Err(e) = tokio::process::Command::new("sh")
|
||||
.arg("-c")
|
||||
.arg("pkill -f llama-server || true")
|
||||
.arg("pkill llama-server -9 || true")
|
||||
.spawn()
|
||||
{
|
||||
error!("Failed to execute pkill for llama-server: {}", e);
|
||||
|
|
|
|||
|
|
@ -229,7 +229,6 @@ async fn main() -> std::io::Result<()> {
|
|||
}
|
||||
};
|
||||
let cache_url = std::env::var("CACHE_URL")
|
||||
.or_else(|_| std::env::var("REDIS_URL"))
|
||||
.unwrap_or_else(|_| "redis://localhost:6379".to_string());
|
||||
let redis_client = match redis::Client::open(cache_url.as_str()) {
|
||||
Ok(client) => Some(Arc::new(client)),
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue