fix: shared config loads root .env as fallback for microservices
This commit is contained in:
@@ -4,11 +4,18 @@ All services import ``settings`` from here. Each service only uses a subset
|
||||
of the vars, but keeping one Settings class avoids fragmentation.
|
||||
"""
|
||||
|
||||
from pathlib import Path
|
||||
from typing import Literal
|
||||
|
||||
from pydantic import field_validator
|
||||
from pydantic_settings import BaseSettings, SettingsConfigDict
|
||||
|
||||
# Locate the repo root (adiuva-api/) so we can load its .env as a fallback.
|
||||
# Works whether cwd is adiuva-api/ (monolith) or adiuva-api/services/xyz/ (microservice).
|
||||
_this_dir = Path(__file__).resolve().parent # shared/
|
||||
_repo_root = _this_dir.parent # adiuva-api/
|
||||
_root_env = _repo_root / ".env"
|
||||
|
||||
|
||||
class Settings(BaseSettings):
|
||||
# ── Database ─────────────────────────────────────────────────────
|
||||
@@ -57,7 +64,6 @@ class Settings(BaseSettings):
|
||||
CEREBRAS_API_KEY: str = ""
|
||||
|
||||
LLM_MODEL: str = "gpt-4o"
|
||||
LLM_ROUTER_MODEL: str = "gpt-4o-mini"
|
||||
LLM_EMBED_MODEL: str = "text-embedding-3-small"
|
||||
|
||||
GITHUB_COPILOT_TOKEN_DIR: str = ""
|
||||
@@ -77,7 +83,10 @@ class Settings(BaseSettings):
|
||||
ENV: Literal["dev", "prod"] = "dev"
|
||||
|
||||
model_config = SettingsConfigDict(
|
||||
env_file=".env", env_file_encoding="utf-8", extra="ignore"
|
||||
# Local .env (cwd) takes priority; root .env is fallback.
|
||||
env_file=(".env", str(_root_env)),
|
||||
env_file_encoding="utf-8",
|
||||
extra="ignore",
|
||||
)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user