delete jen vytvoří job
This commit is contained in:
+25
-12
@@ -8,7 +8,7 @@ from fastapi.responses import HTMLResponse, RedirectResponse
|
||||
from ..auth import is_admin, is_developer, require_admin, require_developer, require_user
|
||||
from ..config import (
|
||||
DEFAULT_GITEA_ORG,
|
||||
DELETE_APP_SCRIPT,
|
||||
DELETE_APP_SCRIPT_NAME,
|
||||
DEPLOY_SCRIPT,
|
||||
GENERATE_COMPOSE_SCRIPT,
|
||||
get_appfactory_host,
|
||||
@@ -405,7 +405,7 @@ def apps_page(
|
||||
)
|
||||
delete_icon = (
|
||||
f"""
|
||||
<form method="post" action="/portal/delete-app" onsubmit="return confirm('Smazat {app_id}? Tím se odstraní kontejner, image, workspace, záznam v katalogu a Gitea repozitář.');">
|
||||
<form method="post" action="/portal/delete-app" onsubmit="return confirm('Smazat {app_id}? Worker odstraní kontejner, image, workspace, záznam v katalogu a Gitea repozitář. Akce se zařadí jako job.');">
|
||||
<input type="hidden" name="app_id" value="{app_id}">
|
||||
<button type="submit" class="icon-action icon-action-danger" title="Smazat" aria-label="Smazat">
|
||||
<i class="fa-solid fa-trash" aria-hidden="true"></i>
|
||||
@@ -1520,8 +1520,23 @@ def create_app(
|
||||
|
||||
@router.post("/delete-app", response_class=HTMLResponse)
|
||||
def delete_app(app_id: str = Form(...), user=Depends(require_admin)):
|
||||
result = run_command([DELETE_APP_SCRIPT, app_id])
|
||||
status = "OK" if result.returncode == 0 else "FAILED"
|
||||
# Portál NEMAŽE workspace přímo – nemá k němu práva (rm padá na "Permission denied").
|
||||
# Místo toho zařadí run_script job; mazání (container, image, gitea repo, workspace)
|
||||
# provede Worker přes scripts/delete-app.sh s právy serveru. Veškerá runtime/Docker
|
||||
# logika patří do Workeru a shell skriptů, ne do portálu.
|
||||
payload = {
|
||||
"script_name": DELETE_APP_SCRIPT_NAME,
|
||||
"args": [app_id],
|
||||
"arguments": [app_id],
|
||||
}
|
||||
job_id = create_job(
|
||||
job_type="run_script",
|
||||
target_type="app",
|
||||
target_id=app_id,
|
||||
payload=payload,
|
||||
user=user,
|
||||
source="portal",
|
||||
)
|
||||
log_audit_event(
|
||||
user,
|
||||
action="delete_app",
|
||||
@@ -1529,17 +1544,15 @@ def delete_app(app_id: str = Form(...), user=Depends(require_admin)):
|
||||
target_id=app_id,
|
||||
metadata={
|
||||
"app_id": app_id,
|
||||
"status": status,
|
||||
"returncode": result.returncode,
|
||||
"status": "QUEUED",
|
||||
"script_name": DELETE_APP_SCRIPT_NAME,
|
||||
"job_id": job_id,
|
||||
},
|
||||
)
|
||||
|
||||
return render_result(
|
||||
title=f"Smazání služby: {status}",
|
||||
back_url="/portal/apps",
|
||||
sections=[("Výstup", result.stdout), ("Chyba", result.stderr)],
|
||||
user=user,
|
||||
)
|
||||
# Worker zpracuje job asynchronně; pošleme uživatele rovnou na detail jobu, ať vidí
|
||||
# živé logy mazání a výsledek.
|
||||
return RedirectResponse(url=f"/portal/jobs/{job_id}", status_code=303)
|
||||
|
||||
|
||||
@router.post("/update-resources", response_class=HTMLResponse)
|
||||
|
||||
Reference in New Issue
Block a user