import html from fastapi import APIRouter, HTTPException from fastapi.responses import HTMLResponse from app.db.apps import get_deployment, get_deployments from app.templates.layout import page router = APIRouter() @router.get("/deployments", response_class=HTMLResponse) async def deployments_page(): deployments = get_deployments() rows = "" for deployment in deployments: deployment_id = html.escape(str(deployment.get("id", ""))) app_id = html.escape(deployment.get("app_id", "") or "") kind = html.escape(deployment.get("kind", "") or "") status = html.escape(deployment.get("status", "") or "") started_at = html.escape(deployment.get("started_at", "") or "") finished_at = html.escape(deployment.get("finished_at", "") or "") returncode = deployment.get("returncode") returncode_label = "" if returncode is None else html.escape(str(returncode)) rows += f""" #{deployment_id}
{started_at} {app_id} {kind} {status} {returncode_label} {finished_at} Detail """ if not rows: rows = 'Zatím nejsou evidovaná žádná nasazení.' return page( "Nasazení", f"""

Historie nasazení

Přehled posledních běhů nasazení a jejich výsledků.

← Zpět na portál

Nasazení

{rows}
ID Aplikace Typ Status Kód Dokončeno Akce
""", ) @router.get("/deployments/{deployment_id}", response_class=HTMLResponse) async def deployment_detail_page( deployment_id: int, ): deployment = get_deployment(deployment_id) if not deployment: raise HTTPException(status_code=404, detail="Deployment not found") title = f"Nasazení #{html.escape(str(deployment.get('id', deployment_id)))}" app_id = html.escape(deployment.get("app_id", "") or "") kind = html.escape(deployment.get("kind", "") or "") status = html.escape(deployment.get("status", "") or "") started_at = html.escape(deployment.get("started_at", "") or "") finished_at = html.escape(deployment.get("finished_at", "") or "") returncode = deployment.get("returncode") returncode_label = "" if returncode is None else html.escape(str(returncode)) stdout = html.escape(deployment.get("stdout", "") or "") stderr = html.escape(deployment.get("stderr", "") or "") return page( title, f"""

{title}

Detail běhu nasazení včetně výstupu procesu.

← Zpět na nasazení Zpět na portál

Souhrn

Aplikace{app_id}
Typ{kind}
Status{status}
Návratový kód{returncode_label}
Spuštěno{started_at}
Dokončeno{finished_at}

Výstup

{stdout}

Chyba

{stderr}
""", )