From dfbc22075ab79a736552458f781fac3077d03b49 Mon Sep 17 00:00:00 2001 From: Gamosoft Date: Tue, 30 Jun 2026 17:07:51 +0200 Subject: [PATCH] more env variables --- backend/main.py | 14 ++++++++++++++ documentation/ENVIRONMENT_VARIABLES.md | 24 ++++++++++++++++++++++++ run.py | 22 ++++++---------------- 3 files changed, 44 insertions(+), 16 deletions(-) diff --git a/backend/main.py b/backend/main.py index a19e546..415c9ea 100644 --- a/backend/main.py +++ b/backend/main.py @@ -146,6 +146,20 @@ if config.get('authentication', {}).get('enabled', False): if _is_default_secret: logger.critical("Using default secret_key - sessions can be forged! Change it in config.yaml") +# Storage paths: env vars override config.yaml. Logged either way so the +# resolved location is visible at startup. +_notes_source = "config.yaml" +if 'NOTES_DIR' in os.environ: + config['storage']['notes_dir'] = os.getenv('NOTES_DIR') + _notes_source = "NOTES_DIR env var" +logger.info("Notes directory: %s (from %s)", config['storage']['notes_dir'], _notes_source) + +_plugins_source = "config.yaml" +if 'PLUGINS_DIR' in os.environ: + config['storage']['plugins_dir'] = os.getenv('PLUGINS_DIR') + _plugins_source = "PLUGINS_DIR env var" +logger.info("Plugins directory: %s (from %s)", config['storage']['plugins_dir'], _plugins_source) + # OpenAPI tag metadata for grouping endpoints in Swagger UI tags_metadata = [ {"name": "Notes", "description": "Create, read, update, delete notes"}, diff --git a/documentation/ENVIRONMENT_VARIABLES.md b/documentation/ENVIRONMENT_VARIABLES.md index 138c1d3..4eeed87 100644 --- a/documentation/ENVIRONMENT_VARIABLES.md +++ b/documentation/ENVIRONMENT_VARIABLES.md @@ -12,6 +12,30 @@ NoteDiscovery supports environment variables to override configuration settings, > **Note**: Advanced server settings (CORS origins, debug mode) are configured via `config.yaml` only, not via environment variables. See [config.yaml](#advanced-server-configuration) for details. +### Storage + +| Variable | Type | Default | Description | +|----------|------|---------|-------------| +| `NOTES_DIR` | string | `./data` | Path to the notes vault | +| `PLUGINS_DIR` | string | `./plugins` | Path to the plugins directory | + +The resolved paths are logged at startup so you can confirm what's in use: + +``` +INFO: Notes directory: /home/me/MyVault (from NOTES_DIR env var) +INFO: Plugins directory: ./plugins (from config.yaml) +``` + +#### Example: Pointing at an existing vault + +```bash +# Local +NOTES_DIR=/home/me/MyVault python run.py + +# Docker +docker run -e NOTES_DIR=/vault -v /home/me/MyVault:/vault ... +``` + ### Authentication | Variable | Type | Default | Description | diff --git a/run.py b/run.py index bcac535..1cb270b 100644 --- a/run.py +++ b/run.py @@ -16,26 +16,21 @@ except ImportError: colorama = None def get_port(): - """Get port from: 1) ENV variable, 2) config.yaml, 3) default 8000""" - # Priority 1: Environment variable + """Get port from: 1) PORT env var, 2) config.yaml, 3) default 8000.""" if os.getenv("PORT"): return os.getenv("PORT") - - # Priority 2: config.yaml config_path = Path("config.yaml") if config_path.exists(): try: import yaml with open(config_path, 'r', encoding='utf-8') as f: - config = yaml.safe_load(f) - if config and 'server' in config and 'port' in config['server']: - return str(config['server']['port']) + cfg = yaml.safe_load(f) or {} + return str(cfg.get('server', {}).get('port', 8000)) except Exception: - pass # Fall through to default - - # Priority 3: Default + pass return "8000" + def main(): try: import fastapi # noqa: F401 @@ -44,13 +39,8 @@ def main(): print("Installing dependencies...") subprocess.check_call([sys.executable, "-m", "pip", "install", "-r", "requirements.txt"]) - Path("data").mkdir(parents=True, exist_ok=True) - Path("plugins").mkdir(parents=True, exist_ok=True) - port = get_port() - - print(f"🚀 NoteDiscovery → http://localhost:{port}") - print(f" notes: ./data/ plugins: ./plugins/ stop: Ctrl+C") + print(f"🚀 NoteDiscovery → http://localhost:{port} (Ctrl+C to stop)") print() subprocess.call([