Backend:
- update_service: registry manifest digest check (Docker Hub/ghcr/lscr/private
v2 token auth) vs local RepoDigests; in-memory cache + background loop
- port_service: parse compose ports, check /proc/net/tcp[6] + docker bindings
- template_service + bundled templates (jellyfin/vaultwarden/uptime-kuma/
paperless-ngx/gitea) with {{VAR}} placeholders; custom templates in DB
- compose_edit set_resources (deploy.resources.limits/reservations)
- routers: images, ports, templates, editor/set-resources
- Template model; background update task wired into lifespan
Frontend:
- EnvEditor (table + raw, sensitive masking, quick-insert)
- Images page + UpdateBadge + dashboard 'updates available' banner
- PortConflictDialog pre-deploy check on Deploy
- ResourcePanel (CPU/RAM sliders) as editor Limits tab
- Templates page with per-variable instantiate form
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
103 lines
2.8 KiB
Python
103 lines
2.8 KiB
Python
"""Editor helper endpoints — merge wizard fragments into compose YAML."""
|
|
from __future__ import annotations
|
|
|
|
from fastapi import APIRouter, Depends, HTTPException
|
|
from pydantic import BaseModel
|
|
|
|
from auth import get_current_user
|
|
from models.user import User
|
|
from services import compose_edit_service as edit
|
|
|
|
router = APIRouter(prefix="/api/editor", tags=["editor"])
|
|
|
|
|
|
class AddVolumeBody(BaseModel):
|
|
yaml: str
|
|
service: str
|
|
spec: dict
|
|
|
|
|
|
class SetGpuBody(BaseModel):
|
|
yaml: str
|
|
service: str
|
|
config: dict
|
|
|
|
|
|
class DeviceBody(BaseModel):
|
|
yaml: str
|
|
service: str
|
|
host_path: str
|
|
target: str | None = None
|
|
|
|
|
|
class PrivilegedBody(BaseModel):
|
|
yaml: str
|
|
service: str
|
|
value: bool
|
|
|
|
|
|
class ResourcesBody(BaseModel):
|
|
yaml: str
|
|
service: str
|
|
cpus: float | None = None
|
|
memory: str | None = None
|
|
cpus_reserve: float | None = None
|
|
memory_reserve: str | None = None
|
|
|
|
|
|
def _run(fn, *args) -> dict:
|
|
try:
|
|
return {"yaml": fn(*args)}
|
|
except edit.EditError as exc:
|
|
raise HTTPException(status_code=400, detail=str(exc)) from exc
|
|
|
|
|
|
@router.post("/services")
|
|
def services(body: dict, _user: User = Depends(get_current_user)) -> dict:
|
|
try:
|
|
return {"services": edit.list_services(body.get("yaml", ""))}
|
|
except edit.EditError as exc:
|
|
raise HTTPException(status_code=400, detail=str(exc)) from exc
|
|
|
|
|
|
@router.post("/add-volume")
|
|
def add_volume(body: AddVolumeBody, _user: User = Depends(get_current_user)) -> dict:
|
|
return _run(edit.add_volume, body.yaml, body.service, body.spec)
|
|
|
|
|
|
@router.post("/set-gpu")
|
|
def set_gpu(body: SetGpuBody, _user: User = Depends(get_current_user)) -> dict:
|
|
return _run(edit.set_gpu, body.yaml, body.service, body.config)
|
|
|
|
|
|
@router.post("/add-device")
|
|
def add_device(body: DeviceBody, _user: User = Depends(get_current_user)) -> dict:
|
|
return _run(edit.add_device, body.yaml, body.service, body.host_path, body.target)
|
|
|
|
|
|
@router.post("/remove-device")
|
|
def remove_device(body: DeviceBody, _user: User = Depends(get_current_user)) -> dict:
|
|
return _run(edit.remove_device, body.yaml, body.service, body.host_path)
|
|
|
|
|
|
@router.post("/set-privileged")
|
|
def set_privileged(body: PrivilegedBody, _user: User = Depends(get_current_user)) -> dict:
|
|
return _run(edit.set_privileged, body.yaml, body.service, body.value)
|
|
|
|
|
|
@router.post("/set-resources")
|
|
def set_resources(body: ResourcesBody, _user: User = Depends(get_current_user)) -> dict:
|
|
try:
|
|
return {
|
|
"yaml": edit.set_resources(
|
|
body.yaml,
|
|
body.service,
|
|
cpus=body.cpus,
|
|
memory=body.memory,
|
|
cpus_reserve=body.cpus_reserve,
|
|
memory_reserve=body.memory_reserve,
|
|
)
|
|
}
|
|
except edit.EditError as exc:
|
|
raise HTTPException(status_code=400, detail=str(exc)) from exc
|