fix(api): service_registry.py Path 索引修正 — 相容 Docker 容器環境
Some checks failed
CD Pipeline / build-and-deploy (push) Has been cancelled

This commit is contained in:
OG T
2026-04-08 21:34:40 +08:00
parent f7c1c46f96
commit 1f9eea5b74

View File

@@ -15,8 +15,24 @@ import yaml
logger = structlog.get_logger(__name__)
# YAML 路徑(相對於 repo root
_DEFAULT_REGISTRY_PATH = Path(__file__).parents[5] / "ops" / "config" / "service-registry.yaml"
# YAML 路徑 — 安全搜尋,相容本地開發 + Docker 容器
# 本地: apps/api/src/services/ → parents[4] = repo root
# Docker: /app/src/services/ → parents[3] = /app → 需要往上找 ops/config
def _find_registry_path() -> Path:
"""安全搜尋 service-registry.yaml相容不同部署環境"""
candidates = [
Path(__file__).resolve().parents[4] / "ops" / "config" / "service-registry.yaml", # 本地開發
Path(__file__).resolve().parents[3] / "ops" / "config" / "service-registry.yaml", # Docker
Path("/app/ops/config/service-registry.yaml"), # Docker 絕對路徑
Path(__file__).resolve().parents[2] / "ops" / "config" / "service-registry.yaml",
]
for p in candidates:
if p.exists():
return p
# fallback: 回傳第一個候選(會在載入時報錯,但不會 crash import
return candidates[0]
_DEFAULT_REGISTRY_PATH = _find_registry_path()
class StatefulLevel(str, Enum):