From f22963a666be8926c44482f12fab00a39c5cb422 Mon Sep 17 00:00:00 2001 From: Wild Karl-Heinz Date: Mon, 28 Sep 2026 20:57:43 +0200 Subject: [PATCH] Read database, host and SMTP settings from a .env file - gem dotenv loads .env (and .env.[.local]) at startup; real environment variables take precedence. - database.yml takes host, port, user, password and name from NUMOLUS_DATABASE_*; the database is called numolus by default. - .env.example documents every setting; .env itself stays ignored. Co-Authored-By: Claude Opus 5.5 --- .env.example | 26 ++++++++++++++++++++++++++ .gitignore | 1 + Gemfile | 4 ++++ Gemfile.lock | 2 ++ README.md | 11 ++++++----- config/database.yml | 18 ++++++++++-------- 6 files changed, 49 insertions(+), 13 deletions(-) create mode 100644 .env.example diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..8cd9d28 --- /dev/null +++ b/.env.example @@ -0,0 +1,26 @@ +# numolus settings -- copy to .env (same directory) and fill in. +# .env is read at startup (gem dotenv) and never committed. Variables that +# are already set in the real environment take precedence over this file. +# Environment-specific files are read too: .env.production, .env.development +# (and *.local variants). + +# ---- Database (PostgreSQL) -------------------------------------------------- +# Unset host/user/password = local socket as the current OS user (development). +NUMOLUS_DATABASE_NAME=numolus +NUMOLUS_DATABASE_HOST=localhost +NUMOLUS_DATABASE_PORT=5432 +NUMOLUS_DATABASE_USER=numolus +NUMOLUS_DATABASE_PASSWORD= + +# ---- Server ------------------------------------------------------------------- +# Host name used in links in mails (sign-in, invitations) +NUMOLUS_HOST=numolus.wicom.li +# Rails secret (production): generate with bin/rails secret +SECRET_KEY_BASE= + +# ---- Mail (production; development shows mails at /letter_opener) ------------ +NUMOLUS_MAIL_FROM="numolus " +SMTP_ADDRESS=smtp.example.com +SMTP_PORT=587 +SMTP_USER_NAME= +SMTP_PASSWORD= diff --git a/.gitignore b/.gitignore index 50e7110..b15b01b 100644 --- a/.gitignore +++ b/.gitignore @@ -26,4 +26,5 @@ node_modules !/storage/.keep /config/master.key /.env* +!/.env.example /vendor/gems diff --git a/Gemfile b/Gemfile index c0aaf7a..8fefa6a 100644 --- a/Gemfile +++ b/Gemfile @@ -37,6 +37,10 @@ group :development do gem "web-console" end +# Settings and secrets (database, SMTP, host) from a .env file in the project +# directory; real environment variables win -- see .env.example +gem "dotenv" + # Vite as the frontend build, integrated into Rails [https://vite-ruby.netlify.app] gem "vite_rails" diff --git a/Gemfile.lock b/Gemfile.lock index 803ef80..37a1817 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -97,6 +97,7 @@ GEM debug (1.11.1) irb (~> 1.10) reline (>= 0.3.8) + dotenv (3.2.0) drb (2.2.3) dry-cli (1.4.1) erb (6.0.7) @@ -300,6 +301,7 @@ DEPENDENCIES brakeman bundler-audit debug + dotenv letter_opener_web pg (~> 1.1) puma (>= 5.0) diff --git a/README.md b/README.md index 1ef1fa6..8f661fb 100644 --- a/README.md +++ b/README.md @@ -28,11 +28,12 @@ kommen über ActionCable sofort bei den anderen an (Yjs, siehe [`app/frontend/collab/`](app/frontend/collab/)), jede Person hat ihr eigenes Undo, und die Auswahl der anderen ist als farbiger Rahmen zu sehen. Details: [`docs/konzept-teilen-und-zusammenarbeit.md`](docs/konzept-teilen-und-zusammenarbeit.md). -Mails landen in der Entwicklung nicht im Postfach, sondern unter -. Produktion braucht `SMTP_ADDRESS`, -`SMTP_USER_NAME`, `SMTP_PASSWORD`, `NUMOLUS_MAIL_FROM`, `NUMOLUS_HOST` und -`NUMOLUS_DATABASE_PASSWORD`; Solid Queue, Cache und Cable liegen in derselben -Datenbank wie die Daten. +**Konfiguration:** Datenbank-Zugang, Server-Name, SMTP und `SECRET_KEY_BASE` +stehen in einer `.env` im Projektverzeichnis – Vorlage kopieren und ausfüllen: +`cp .env.example .env`. Die Datei wird nie committet; echte +Umgebungsvariablen haben Vorrang. Solid Queue, Cache und Cable liegen in +derselben Datenbank wie die Daten. Mails landen in der Entwicklung nicht im +Postfach, sondern unter . --- diff --git a/config/database.yml b/config/database.yml index 28f0d45..7cc3b24 100644 --- a/config/database.yml +++ b/config/database.yml @@ -15,14 +15,17 @@ default: &default adapter: postgresql encoding: unicode - # For details on connection pooling, see Rails configuration guide - # https://guides.rubyonrails.org/configuring.html#database-pooling max_connections: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %> - + # Connection details come from the environment, usually a .env file in + # the project directory (see .env.example). Unset = local socket, own user. + host: <%= ENV["NUMOLUS_DATABASE_HOST"] %> + port: <%= ENV["NUMOLUS_DATABASE_PORT"] %> + username: <%= ENV["NUMOLUS_DATABASE_USER"] %> + password: <%= ENV["NUMOLUS_DATABASE_PASSWORD"] %> development: <<: *default - database: numolus_development + database: <%= ENV.fetch("NUMOLUS_DATABASE_NAME", "numolus") %> # The specified database role being used to connect to PostgreSQL. # To create additional roles in PostgreSQL see `$ createuser --help`. @@ -59,9 +62,8 @@ test: database: numolus_test # Production: one database for everything -- app data, Solid Queue, Solid -# Cache and Solid Cable. The password comes from NUMOLUS_DATABASE_PASSWORD. +# Cache and Solid Cable. Credentials via NUMOLUS_DATABASE_* (see .env.example). production: <<: *default - database: numolus_production - username: numolus - password: <%= ENV["NUMOLUS_DATABASE_PASSWORD"] %> + database: <%= ENV.fetch("NUMOLUS_DATABASE_NAME", "numolus") %> + username: <%= ENV.fetch("NUMOLUS_DATABASE_USER", "numolus") %>