From 0d60a3fb67c573283d16fce474a5b3f9a639b03c Mon Sep 17 00:00:00 2001 From: PedroHMCosme Date: Fri, 17 Jul 2026 09:44:38 -0300 Subject: [PATCH] feat(gateway): optional .env loading for local dev (app + seed); document in e2e guide --- docs/e2e-test-guide.md | 2 ++ ingestor/app.py | 7 +++++++ requirements-dev.txt | 2 +- scripts/seed_e2e.py | 7 +++++++ 4 files changed, 17 insertions(+), 1 deletion(-) diff --git a/docs/e2e-test-guide.md b/docs/e2e-test-guide.md index 93e848f..e73d029 100644 --- a/docs/e2e-test-guide.md +++ b/docs/e2e-test-guide.md @@ -20,6 +20,8 @@ Session script for validating the gateway against a real KepServer + cluster (wi ## 1. Seed test data +Copy `.env.example` to `.env` (gitignored) and fill in the values from the session (OPC endpoint, Mongo/Redis/Postgres/MinIO accesses) — both the app and the seed script read it automatically (add `OPC_SERVER_URL=opc.tcp://HOST:49320`; it is seed-only, so it isn't in the example file). Then: + ```bash python scripts/seed_e2e.py --print-only # inspect first python scripts/seed_e2e.py # seed Mongo + Redis slot v1 + Postgres table diff --git a/ingestor/app.py b/ingestor/app.py index bf96140..e18ab41 100644 --- a/ingestor/app.py +++ b/ingestor/app.py @@ -7,6 +7,13 @@ from time import time from prometheus_client import start_http_server +try: # optional: local dev reads .env; in-cluster env comes from Helm (no .env file) + from dotenv import load_dotenv + + load_dotenv() +except ImportError: + pass + import ingestor.metrics as metrics from ingestor.config import GatewayConfig from ingestor.gateway_runtime import GatewayRuntime diff --git a/requirements-dev.txt b/requirements-dev.txt index 56ab376..42c84fe 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -16,4 +16,4 @@ pytest-asyncio>=0.21.0 # Async test support (already in main requirements) # Development Tools ipython>=8.12.0 # Enhanced Python shell -ipdb>=0.13.13 # IPython debugger \ No newline at end of file +ipdb>=0.13.13 # IPython debuggerpython-dotenv>=1.0 # local dev only: app/seed read .env if present (in-cluster env comes from Helm) diff --git a/scripts/seed_e2e.py b/scripts/seed_e2e.py index 0659399..394a924 100644 --- a/scripts/seed_e2e.py +++ b/scripts/seed_e2e.py @@ -28,6 +28,13 @@ import json import os import sys +try: # optional: local dev reads .env; in-cluster env comes from Helm + from dotenv import load_dotenv + + load_dotenv() +except ImportError: + pass + OPC_URL = os.getenv('OPC_SERVER_URL', 'opc.tcp://localhost:49320') CONNECTOR = {