From f2bacf6ca8da23222e36d24d5ffdb9137fc40646 Mon Sep 17 00:00:00 2001 From: "Rodrigo Rodriguez (Pragmatismo)" Date: Mon, 30 Jun 2025 11:15:14 -0300 Subject: [PATCH] Add container setup scripts for various services - Implemented ALM container setup with Forgejo installation and systemd service configuration. - Created Bot container setup with necessary dependencies and Node.js application installation. - Developed Desktop container setup with XRDP and Brave browser installation. - Established Directory container setup with Zitadel installation and service configuration. - Added Doc Editor container setup for Collabora Online integration. - Implemented Drive container setup with MinIO installation and service configuration. - Created Email container setup with Stalwart Mail installation and service configuration. - Developed Meeting container setup with LiveKit and TURN server configuration. - Added Proxy container setup with Caddy installation and service configuration. - Implemented System container setup for general bots with service configuration. - Created Table Editor container setup with NocoDB installation and service configuration. - Developed Tables container setup with PostgreSQL installation and configuration. - Added Webmail container setup with Roundcube installation and service configuration. - Included prompt guidelines for container setup scripts. --- src/main.rs | 17 ++++---------- src/services/config.rs | 51 +++++++++++++++++++++++++++++++++++------- src/services/email.rs | 2 +- src/services/file.rs | 2 +- 4 files changed, 49 insertions(+), 23 deletions(-) diff --git a/src/main.rs b/src/main.rs index 21bf708..8d9bdf9 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,28 +1,21 @@ -use actix_web::{middleware, web, App, HttpServer}; +use actix_web::{web, App, HttpServer}; use dotenv::dotenv; use sqlx::PgPool; -use tracing_subscriber::fmt::format::FmtSpan; use services::config::*; +use services::email::*; use services::file::*; use services::state::*; -use services::email::*; - mod services; #[actix_web::main] async fn main() -> std::io::Result<()> { - dotenv().ok(); let config = AppConfig::from_env(); - let db = PgPool::connect(&std::env::var("DATABASE_URL").unwrap()) - .await - .unwrap(); - tracing_subscriber::fmt() - .with_span_events(FmtSpan::CLOSE) - .init(); + let db_url = config.database_url(); + let db = PgPool::connect(&db_url).await.unwrap(); let minio_client = init_minio(&config) .await @@ -37,8 +30,6 @@ async fn main() -> std::io::Result<()> { // Start HTTP server HttpServer::new(move || { App::new() - .wrap(middleware::Logger::default()) - .wrap(middleware::Compress::default()) .app_data(app_state.clone()) .service(upload_file) .service(list_file) diff --git a/src/services/config.rs b/src/services/config.rs index 117c87f..22787e6 100644 --- a/src/services/config.rs +++ b/src/services/config.rs @@ -4,11 +4,22 @@ use std::env; pub struct AppConfig { pub minio: MinioConfig, pub server: ServerConfig, + pub database: DatabaseConfig, +} + +#[derive(Clone)] +pub struct DatabaseConfig { + + pub username: String, + pub password: String, + pub server: String, + pub port: u32, + pub database: String, } #[derive(Clone)] pub struct MinioConfig { - pub endpoint: String, + pub server: String, pub access_key: String, pub secret_key: String, pub use_ssl: bool, @@ -22,25 +33,49 @@ pub struct ServerConfig { } impl AppConfig { + pub fn database_url(&self) -> String { + format!( + "postgres://{}:{}@{}:{}/{}", + self.database.username, + self.database.password, + self.database.server, + self.database.port, + self.database.database + ) + } + pub fn from_env() -> Self { + let database = DatabaseConfig { + username: env::var("TABLES_USERNAME").unwrap_or_else(|_| "user".to_string()), + password: env::var("TABLES_PASSWORD").unwrap_or_else(|_| "pass".to_string()), + server: env::var("TABLES_SERVER").unwrap_or_else(|_| "localhost".to_string()), + port: env::var("TABLES_PORT") + .ok() + .and_then(|p| p.parse().ok()) + .unwrap_or(5432), + database: env::var("TABLES_DATABASE").unwrap_or_else(|_| "db".to_string()), + }; + let minio = MinioConfig { - endpoint: env::var("MINIO_ENDPOINT").expect("MINIO_ENDPOINT not set"), - access_key: env::var("MINIO_ACCESS_KEY").expect("MINIO_ACCESS_KEY not set"), - secret_key: env::var("MINIO_SECRET_KEY").expect("MINIO_SECRET_KEY not set"), - use_ssl: env::var("MINIO_USE_SSL") + server: env::var("DRIVE_SERVER").expect("DRIVE_SERVER not set"), + access_key: env::var("DRIVE_ACCESSKEY").expect("DRIVE_ACCESSKEY not set"), + secret_key: env::var("DRIVE_SECRET").expect("DRIVE_SECRET not set"), + use_ssl: env::var("DRIVE_USE_SSL") .unwrap_or_else(|_| "false".to_string()) .parse() .unwrap_or(false), - bucket: env::var("MINIO_BUCKET").expect("MINIO_BUCKET not set"), + bucket: env::var("DRIVE_ORG_PREFIX").unwrap_or_else(|_| "".to_string()), }; - AppConfig { + AppConfig { minio, server: ServerConfig { host: env::var("SERVER_HOST").unwrap_or_else(|_| "127.0.0.1".to_string()), - port: env::var("SERVER_PORT").ok() + port: env::var("SERVER_PORT") + .ok() .and_then(|p| p.parse().ok()) .unwrap_or(8080), }, + database, } } } diff --git a/src/services/email.rs b/src/services/email.rs index 3d23b0a..c38061f 100644 --- a/src/services/email.rs +++ b/src/services/email.rs @@ -57,7 +57,7 @@ pub async fn list_emails() -> Result>, actix_web::Er } -#[actix_web::post("/campaigns/{campaign_id}/click/{email}")] +#[actix_web::get("/campaigns/{campaign_id}/click/{email}")] pub async fn save_click( path: web::Path<(String, String)>, state: web::Data, diff --git a/src/services/file.rs b/src/services/file.rs index 0d6b3a7..c451dc2 100644 --- a/src/services/file.rs +++ b/src/services/file.rs @@ -19,7 +19,7 @@ use crate::services::state::AppState; pub async fn init_minio(config: &AppConfig) -> Result { let scheme = if config.minio.use_ssl { "https" } else { "http" }; - let base_url = format!("{}://{}", scheme, config.minio.endpoint); + let base_url = format!("{}://{}", scheme, config.minio.server); let base_url = BaseUrl::from_str(&base_url)?; let credentials = StaticProvider::new( &config.minio.access_key,