Enhance Docker support and configuration

- Updated .env.example to recommend using docker.env and secrets for sensitive data.
- Modified .gitignore to include docker.env and secrets directory.
- Adjusted docker-compose.yml to utilize environment files and updated port mappings.
- Implemented read_env_or_file utility for better environment variable management.
- Refactored portfolio and trades routers to use the new utility for fetching environment variables.
- Added integration and phase 2 test updates for new environment variable handling.
- Created new documentation for Docker operations and secret management.
- Added placeholder files for Docker secrets and configuration.
This commit is contained in:
coddard
2026-05-19 01:49:11 +03:00
parent 0096c8819b
commit eabc96371b
17 changed files with 404 additions and 44 deletions
+5 -4
View File
@@ -12,6 +12,7 @@ from fastapi.responses import JSONResponse, Response
from fastapi.staticfiles import StaticFiles
from ib_async import IB
from config_utils import read_env_or_file
import dependencies
from init_db import ensure_database
from routers import charts, health, portfolio, scanner, trades
@@ -29,8 +30,8 @@ IBKR_PORT = int(os.getenv("IBKR_PORT", 7497))
IBKR_CLIENT_ID = int(os.getenv("IBKR_CLIENT_ID", 1))
DB_PATH = os.getenv("DB_PATH", "trades.db")
UI_USERNAME = os.getenv("UI_USERNAME", "")
UI_PASSWORD = os.getenv("UI_PASSWORD", "")
UI_USERNAME = read_env_or_file("UI_USERNAME", "") or ""
UI_PASSWORD = read_env_or_file("UI_PASSWORD", "") or ""
AUTH_ENABLED = bool(UI_USERNAME and UI_PASSWORD)
_DEFAULT_SECRET = "your_super_secret_string_123"
@@ -48,7 +49,7 @@ ib = IB()
def _validate_config() -> None:
webhook_secret = os.getenv("WEBHOOK_SECRET", "")
webhook_secret = read_env_or_file("WEBHOOK_SECRET", "") or ""
if not webhook_secret or webhook_secret == _DEFAULT_SECRET:
logger.warning(
"SECURITY: WEBHOOK_SECRET is unset or still the default value. "
@@ -58,7 +59,7 @@ def _validate_config() -> None:
logger.info("UI Basic Auth is ENABLED")
else:
logger.info(
"UI Basic Auth is DISABLED — set UI_USERNAME + UI_PASSWORD in .env to enable"
"UI Basic Auth is DISABLED — set UI_USERNAME/UI_PASSWORD or *_FILE to enable"
)