Docker : support env vars, compose standard + swarm séparés

- Dockerfile : copie config.json dans l'image (évite le problème de répertoire)
- app.py : load_config() lit les variables d'environnement en priorité sur config.json
- docker-compose.yml : converti en compose standard (sans section deploy Swarm)
- docker-compose.swarm.yml : nouveau fichier dédié au déploiement Docker Swarm

Variables supportées : OLLAMA_URL, OLLAMA_CLUSTER_MODEL, OLLAMA_LOCAL_MODEL,
SITE_CALENDAR_URL, SITE_BASE_URL, AUTH_SESSION_SECRET, AUTH_USERS

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
sylvain
2026-03-08 15:52:36 +01:00
parent 39b7524f31
commit 9ed22fb14a
4 changed files with 80 additions and 25 deletions
+28 -2
View File
@@ -4,6 +4,7 @@ app.py - Backend FastAPI pour planning2ics web app.
import asyncio
import json
import os
import secrets
import uuid
from datetime import datetime
@@ -21,8 +22,33 @@ CONFIG_PATH = Path("/app/config.json")
DATA_DIR = Path("/app/data")
def load_config() -> dict:
with open(CONFIG_PATH) as f:
return json.load(f)
if CONFIG_PATH.exists() and CONFIG_PATH.is_file():
with open(CONFIG_PATH) as f:
config = json.load(f)
else:
config = {
"ollama": {"url": "", "cluster_model": "", "local_model": ""},
"site": {"calendar_url": "", "base_url": ""},
"auth": {"session_secret": "changez-cette-cle-secrete-en-production", "users": []},
}
# Les variables d'environnement ont priorité sur config.json
if os.getenv("OLLAMA_URL"):
config["ollama"]["url"] = os.environ["OLLAMA_URL"]
if os.getenv("OLLAMA_CLUSTER_MODEL"):
config["ollama"]["cluster_model"] = os.environ["OLLAMA_CLUSTER_MODEL"]
if os.getenv("OLLAMA_LOCAL_MODEL"):
config["ollama"]["local_model"] = os.environ["OLLAMA_LOCAL_MODEL"]
if os.getenv("SITE_CALENDAR_URL"):
config["site"]["calendar_url"] = os.environ["SITE_CALENDAR_URL"]
if os.getenv("SITE_BASE_URL"):
config["site"]["base_url"] = os.environ["SITE_BASE_URL"]
if os.getenv("AUTH_SESSION_SECRET"):
config["auth"]["session_secret"] = os.environ["AUTH_SESSION_SECRET"]
if os.getenv("AUTH_USERS"):
config["auth"]["users"] = json.loads(os.environ["AUTH_USERS"])
return config
# ── App ───────────────────────────────────────────────────────────────────────