From f096145cee6ad2bedd903c084081baea811e92da Mon Sep 17 00:00:00 2001 From: Ruben Fiszel Date: Thu, 29 Jun 2023 11:52:46 +0200 Subject: [PATCH] improve docker-compose and email sending --- README.md | 2 ++ backend/src/main.rs | 5 ++++- backend/windmill-api/src/lib.rs | 2 ++ backend/windmill-api/src/users.rs | 15 +++------------ backend/windmill-api/src/workspaces.rs | 13 ++++++++++++- docker-compose.yml | 2 ++ 6 files changed, 25 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 4875831cc6..8045f26776 100644 --- a/README.md +++ b/README.md @@ -304,6 +304,7 @@ the instances using their emails, configure the SMTP env variables in the servers: ``` +SMTP_FROM=noreply@windmill.dev SMTP_HOST=smtp.gmail.com SMTP_PORT=587 SMTP_USERNAME=ruben@windmill.dev @@ -379,6 +380,7 @@ it being synced automatically everyday. | HTTP_PROXY | None | http_proxy | Server + Worker | | HTTPS_PROXY | None | https_proxy | Server + Worker | | NO_PROXY | None | no_proxy | Server + Worker | +| SMTP_FROM | None | the address to use as the from field for emails send | Server | | SMTP_HOST | None | host for the smtp server to send invite emails | Server | | SMTP_PORT | 587 | port for the smtp server to send invite emails | Server | | SMTP_USERNAME | None | username for the smtp server to send invite emails | Server | diff --git a/backend/src/main.rs b/backend/src/main.rs index a7ac2bdada..9bcb179cc2 100644 --- a/backend/src/main.rs +++ b/backend/src/main.rs @@ -27,7 +27,7 @@ use windmill_worker::{ }; const GIT_VERSION: &str = git_version!(args = ["--tag", "--always"], fallback = "unknown-version"); -const DEFAULT_NUM_WORKERS: usize = 3; +const DEFAULT_NUM_WORKERS: usize = 1; const DEFAULT_PORT: u16 = 8000; const DEFAULT_SERVER_BIND_ADDR: Ipv4Addr = Ipv4Addr::new(0, 0, 0, 0); @@ -45,6 +45,9 @@ async fn main() -> anyhow::Result<()> { .and_then(|x| x.parse::().ok()) .unwrap_or(DEFAULT_NUM_WORKERS as i32); + if num_workers > 1 { + tracing::warn!("We recommend using at most 1 worker per container, use more only if you know what you are doing."); + } let metrics_addr: Option = *METRICS_ADDR; let server_mode = !std::env::var("DISABLE_SERVER") diff --git a/backend/windmill-api/src/lib.rs b/backend/windmill-api/src/lib.rs index b41f6e8e51..a5335f11ba 100644 --- a/backend/windmill-api/src/lib.rs +++ b/backend/windmill-api/src/lib.rs @@ -107,6 +107,8 @@ lazy_static::lazy_static! { } }; + pub static ref SMTP_FROM: String = std::env::var("SMTP_FROM").unwrap_or_else(|_| "noreply@getwindmill.com".to_string()); + pub static ref LICENSE_KEY: Option = std::env::var("LICENSE_KEY").ok(); } diff --git a/backend/windmill-api/src/users.rs b/backend/windmill-api/src/users.rs index cc60bb0ff9..fe4e0b00f2 100644 --- a/backend/windmill-api/src/users.rs +++ b/backend/windmill-api/src/users.rs @@ -14,7 +14,7 @@ use crate::{ utils::require_super_admin, webhook_util::{InstanceEvent, WebhookShared}, workspaces::invite_user_to_all_auto_invite_worspaces, - BASE_URL, COOKIE_DOMAIN, IS_SECURE, SMTP_CLIENT, + BASE_URL, COOKIE_DOMAIN, IS_SECURE, SMTP_CLIENT, SMTP_FROM, }; use argon2::{password_hash::SaltString, Argon2, PasswordHash, PasswordHasher, PasswordVerifier}; use axum::{ @@ -1236,16 +1236,6 @@ async fn add_user_to_workspace<'c>( None, ) .await?; - send_email_if_possible( - &format!("Added to Windmill's workspace: {w_id}"), - &format!( - "You have been granted access to Windmill's workspace {w_id} - -If you do not have an account on {}, login with SSO or ask an admin to create an account for you.", - *BASE_URL - ), - &email, - ); Ok(tx) } @@ -1470,7 +1460,7 @@ pub fn send_email_if_possible(subject: &str, content: &str, to: &str) { pub async fn send_email_if_possible_intern(subject: &str, content: &str, to: &str) -> Result<()> { if let Some(ref smtp) = *SMTP_CLIENT { let message = MessageBuilder::new() - .from(("Windmill", "noreply@getwindmill.com")) + .from(("Windmill", SMTP_FROM.as_str())) .to(to) .subject(subject) .text_body(content); @@ -1480,6 +1470,7 @@ pub async fn send_email_if_possible_intern(subject: &str, content: &str, to: &st .send(message) .await .map_err(to_anyhow)?; + tracing::info!("Sent email to {to}: {subject}"); } return Ok(()); } diff --git a/backend/windmill-api/src/workspaces.rs b/backend/windmill-api/src/workspaces.rs index cb2e794ad6..cc94ea30c8 100644 --- a/backend/windmill-api/src/workspaces.rs +++ b/backend/windmill-api/src/workspaces.rs @@ -1043,7 +1043,7 @@ If you do not have an account on {}, login with SSO or ask an admin to create an } async fn add_user( - Authed { username, is_admin, .. }: Authed, + Authed { username, email, is_admin, .. }: Authed, Extension(db): Extension, Extension(webhook): Extension, Path(w_id): Path, @@ -1084,6 +1084,17 @@ async fn add_user( tx.commit().await?; + send_email_if_possible( + &format!("Added to Windmill's workspace: {w_id}"), + &format!( + "You have been granted access to Windmill's workspace {w_id} by {email} + +If you do not have an account on {}, login with SSO or ask an admin to create an account for you.", + *BASE_URL + ), + &nu.email, + ); + webhook.send_instance_event(InstanceEvent::UserAddedWorkspace { workspace: w_id.clone(), email: nu.email.clone(), diff --git a/docker-compose.yml b/docker-compose.yml index 179dd8f945..3d155b7307 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -53,6 +53,8 @@ services: - DATABASE_URL=postgres://postgres:${DB_PASSWORD}@db/windmill?sslmode=disable - BASE_URL=${WM_BASE_URL} - RUST_LOG=info + # DO NOT INCREASE NUM_WORKERS > 1 UNLESS YOU KNOW WHAT YOU ARE DOING + # Increase the number of replicas instead. - NUM_WORKERS=1 - DISABLE_SERVER=true - KEEP_JOB_DIR=false