39 lines
1.1 KiB
Python
39 lines
1.1 KiB
Python
"""Configuration loader.
|
|
|
|
Reads from the path in FESTER_CONFIG env var if set, otherwise from
|
|
config.yaml in the project root. Provides CONFIG as a module-level dict.
|
|
"""
|
|
|
|
import os
|
|
from pathlib import Path
|
|
|
|
import yaml
|
|
|
|
BASE_DIR = os.path.dirname(os.path.dirname(__file__))
|
|
|
|
# Allow override via env var (for tests / dev / multi-cluster setups)
|
|
_env_config = os.environ.get("FESTER_CONFIG")
|
|
if _env_config:
|
|
CONFIG_PATH = _env_config
|
|
else:
|
|
CONFIG_PATH = os.path.join(BASE_DIR, "config.yaml")
|
|
|
|
# Graceful fallback: if the requested config doesn't exist, use a sensible
|
|
# default so the backend can still boot (e.g. in a fresh clone or container).
|
|
if not Path(CONFIG_PATH).exists():
|
|
CONFIG = {
|
|
"master": {"name": "fester-master", "role": "control"},
|
|
"nodes": [
|
|
{"name": "localhost", "host": "127.0.0.1", "max_jobs": 4},
|
|
],
|
|
"projects": [],
|
|
}
|
|
else:
|
|
with open(CONFIG_PATH, "r") as f:
|
|
CONFIG = yaml.safe_load(f) or {}
|
|
|
|
# Ensure required keys exist
|
|
CONFIG.setdefault("master", {"name": "fester-master", "role": "control"})
|
|
CONFIG.setdefault("nodes", [])
|
|
CONFIG.setdefault("projects", [])
|