refactor: audit log to Postgres + split /healthz liveness from Pulp status

- audit.record_deploy 를 JSONL 파일 → Postgres deploy_audit 테이블로 (재배포 휘발 방지)
  - psycopg 지연 import, _write 는 테스트에서 monkeypatch 지점, DATABASE_URL 사용
  - 감사 기록 실패는 배포 완료를 막지 않고 UI 경고(audit_ok)
- /healthz: Pulp 무관 라이브니스 {"ok":true} (컨테이너 health check),
  Pulp 연결 배지는 /pulp-status 로 분리 (대시보드가 폴링)
- config: DATABASE_URL 추가, audit_log_path 제거

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-06-17 13:42:11 +09:00
parent 7ad6d65a11
commit aef4124da0
8 changed files with 95 additions and 35 deletions

View File

@@ -9,7 +9,7 @@ from pathlib import Path
import httpx
from fastapi import Depends, FastAPI, Request
from fastapi.responses import HTMLResponse
from fastapi.responses import HTMLResponse, JSONResponse
from fastapi.staticfiles import StaticFiles
# 테스트 호환을 위해 re-export (tests 가 app.main.get_pulp_client 를 override 함)
@@ -29,11 +29,21 @@ app.include_router(deploy.router)
__all__ = ["app", "get_pulp_client"]
@app.get("/healthz", response_class=HTMLResponse)
def healthz(
@app.get("/healthz")
def healthz() -> JSONResponse:
"""앱 라이브니스(컨테이너 헬스체크용). Pulp 상태와 무관하게 항상 200.
Pulp 미연결이라도 앱 자체는 살아있으므로, Coolify 가 컨테이너를 unhealthy 로
오판하지 않도록 여기서는 Pulp 를 확인하지 않는다. 연결 확인은 /pulp-status.
"""
return JSONResponse({"ok": True})
@app.get("/pulp-status", response_class=HTMLResponse)
def pulp_status(
request: Request, pulp: PulpClient = Depends(get_pulp_client)
) -> HTMLResponse:
"""Pulp status 프록시 → 연결 상태 배지 조각."""
"""Pulp status 프록시 → 연결 상태 배지 조각 (대시보드 폴링 대상)."""
try:
pulp.status()
online, detail = True, "Pulp 연결됨"