Read apps and resources from database
This commit is contained in:
+13
-20
@@ -3,7 +3,6 @@ import html
|
||||
from fastapi import APIRouter, Form
|
||||
from fastapi.responses import HTMLResponse
|
||||
|
||||
from ..catalog import load_apps, save_apps
|
||||
from ..config import (
|
||||
DEFAULT_APPFACTORY_HOST,
|
||||
DEFAULT_GITEA_ORG,
|
||||
@@ -13,6 +12,7 @@ from ..config import (
|
||||
NEW_APP_SCRIPT,
|
||||
read_env_value,
|
||||
)
|
||||
from ..db.apps import get_apps, update_app_resources
|
||||
from ..shell import run_command
|
||||
from ..templates.layout import page, render_result
|
||||
|
||||
@@ -21,7 +21,7 @@ router = APIRouter()
|
||||
|
||||
@router.get("/", response_class=HTMLResponse)
|
||||
def index():
|
||||
apps = load_apps()
|
||||
apps = get_apps()
|
||||
|
||||
gitea_url = read_env_value("GITEA_URL", "")
|
||||
gitea_org = read_env_value("GITEA_ORG", DEFAULT_GITEA_ORG)
|
||||
@@ -224,34 +224,27 @@ def delete_app(app_id: str = Form(...)):
|
||||
|
||||
@router.post("/update-resources", response_class=HTMLResponse)
|
||||
def update_resources(app_id: str = Form(...), memory: str = Form(""), cpus: str = Form("")):
|
||||
apps = load_apps()
|
||||
memory = memory.strip()
|
||||
cpus = cpus.strip()
|
||||
|
||||
for item in apps:
|
||||
if item.get("id") == app_id:
|
||||
memory = memory.strip()
|
||||
cpus = cpus.strip()
|
||||
|
||||
if memory:
|
||||
item["memory"] = memory
|
||||
else:
|
||||
item.pop("memory", None)
|
||||
|
||||
if cpus:
|
||||
item["cpus"] = cpus
|
||||
else:
|
||||
item.pop("cpus", None)
|
||||
|
||||
save_apps(apps)
|
||||
update_app_resources(app_id, memory, cpus)
|
||||
|
||||
catalog_result = run_command(["/tools/generate-catalog.sh"])
|
||||
compose_result = run_command([GENERATE_COMPOSE_SCRIPT])
|
||||
deploy_result = run_command([DEPLOY_SCRIPT, app_id])
|
||||
|
||||
status = "OK" if compose_result.returncode == 0 and deploy_result.returncode == 0 else "FAILED"
|
||||
status = (
|
||||
"OK"
|
||||
if catalog_result.returncode == 0 and compose_result.returncode == 0 and deploy_result.returncode == 0
|
||||
else "FAILED"
|
||||
)
|
||||
|
||||
return render_result(
|
||||
title=f"Úprava prostředků: {status}",
|
||||
back_url="/portal",
|
||||
sections=[
|
||||
("Výstup katalogu", catalog_result.stdout),
|
||||
("Chyba katalogu", catalog_result.stderr),
|
||||
("Výstup compose", compose_result.stdout),
|
||||
("Chyba compose", compose_result.stderr),
|
||||
("Výstup nasazení", deploy_result.stdout),
|
||||
|
||||
Reference in New Issue
Block a user