feat(appstore): модуль «App Store» — каталог self-hosted приложений (1 app = 1 LXC + Docker Compose)
All checks were successful
Backend Tests / pytest (Python 3.12) (push) Successful in 1m4s
Deploy to Production / Trigger production update (push) Successful in 12s

Полный цикл M0–M5 по ТЗ:
- Catalog Service: импорт runtipi/runtipi-appstore → catalog_apps, идемпотентный
  синк, кэш логотипов, авто раз в 24ч (APScheduler), флаг update_available.
- App Engine: установка (клон золотого шаблона → pct push compose/.env →
  docker compose up → health-check) с журналом шагов, шифрованием env (Fernet),
  генерацией random-секретов и прогрессом по WebSocket.
- Lifecycle: start/stop/restart/logs/delete + реконсиляция состояния (orphaned).
- Update/Rollback через снапшоты Proxmox (pre-update, хранение последнего 1).
- UI: экраны App Store (сетка/поиск/категории), страница приложения, мастер
  установки (динамическая form_fields + advanced + прогресс + креденшелы),
  My Apps; i18n ru/en; атрибуция Runtipi.
- RBAC app:view/install/manage; только unprivileged LXC; pct exec/push без
  shell-инъекций (base64 + экранирование).
- Модели catalog_apps/installed_apps/app_operations (миграции 31–32).
- Docs: golden-template, appstore-poc/catalog/engine.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
markmorado
2026-07-07 23:05:20 +05:00
parent 782524fff6
commit 0606e8ac77
32 changed files with 3700 additions and 3 deletions

View File

@@ -7,6 +7,7 @@ from .metrics import InstanceMetric, InstanceNicMetric
from .settings import PanelSettings, SecuritySetting, Workspace, WorkspaceServer, WorkspaceUser
from .misc import Notification, NotificationPreference, BackupJob, AuditLog
from .catalog import ImageMirror
from .appstore import CatalogApp, InstalledApp, AppOperation
__all__ = [
'Base', 'utcnow',
@@ -17,5 +18,6 @@ __all__ = [
'InstanceMetric', 'InstanceNicMetric',
'PanelSettings', 'SecuritySetting', 'Workspace', 'WorkspaceServer', 'WorkspaceUser',
'Notification', 'NotificationPreference', 'BackupJob', 'AuditLog',
'ImageMirror'
'ImageMirror',
'CatalogApp', 'InstalledApp', 'AppOperation'
]

View File

@@ -0,0 +1,186 @@
from .base import *
import json as _json
# Статусы установленного приложения (ТЗ 8)
INSTALLED_STATUSES = (
"installing", "running", "stopped", "error",
"updating", "update_failed", "orphaned", "deleting",
)
class CatalogApp(Base):
"""
Приложение из каталога App Store (импорт из runtipi/runtipi-appstore).
Наполняется Catalog Service (services/appstore_catalog.py). Публичные
метаданные — шифрование не требуется. Секреты появляются только на этапе
установки (installed_apps.env_encrypted, M2).
"""
__tablename__ = "catalog_apps"
# id приложения из runtipi (config.json → "id"), напр. "uptime-kuma"
app_id = Column(String(100), primary_key=True, index=True)
name = Column(String(200), nullable=False)
# version — строка тега docker-образа ("2", "1.23.1"); tipi_version — целочисленный
# инкремент версии рецепта (используется для update_available в M2).
version = Column(String(50), nullable=True)
tipi_version = Column(Integer, nullable=True)
categories = Column(JSON, nullable=False, default=list)
short_desc = Column(Text, nullable=True)
description_md = Column(Text, nullable=True)
# относительный путь логотипа внутри APPSTORE_DATA_DIR (напр. "logos/uptime-kuma.jpg")
logo_path = Column(String(300), nullable=True)
port = Column(Integer, nullable=True)
# массив объектов form_fields из config.json (см. ТЗ 6.2)
form_fields = Column(JSON, nullable=False, default=list)
compose_yaml = Column(Text, nullable=True)
architectures = Column(JSON, nullable=False, default=list)
available = Column(Boolean, nullable=False, default=True, index=True)
unavailable_reason = Column(String(200), nullable=True)
deprecated = Column(Boolean, nullable=False, default=False)
# config.json → dynamic_config: приложение имеет docker-compose.json (новый формат).
# В MVP всё равно используем docker-compose.yml; флаг сохраняем на будущее (риск п.13 ТЗ).
dynamic_config = Column(Boolean, nullable=False, default=False)
source_url = Column(String(500), nullable=True)
author = Column(String(200), nullable=True)
synced_at = Column(DateTime(timezone=True), server_default=func.now(), nullable=False)
def to_dict(self, *, light: bool = False, with_compose: bool = False) -> dict:
data = {
"app_id": self.app_id,
"name": self.name,
"version": self.version,
"tipi_version": self.tipi_version,
"categories": self.categories or [],
"short_desc": self.short_desc,
"port": self.port,
"architectures": self.architectures or [],
"available": self.available,
"unavailable_reason": self.unavailable_reason,
"deprecated": self.deprecated,
"dynamic_config": self.dynamic_config,
"source_url": self.source_url,
"author": self.author,
"logo_url": f"/api/appstore/catalog/{self.app_id}/logo" if self.logo_path else None,
"synced_at": self.synced_at.isoformat() if self.synced_at else None,
}
if not light:
# тяжёлые поля — только для страницы приложения
data["form_fields"] = self.form_fields or []
data["description_md"] = self.description_md
if with_compose:
data["compose_yaml"] = self.compose_yaml
return data
def __repr__(self):
return f"<CatalogApp(app_id='{self.app_id}', name='{self.name}', v='{self.version}')>"
class InstalledApp(Base):
"""
Установленное приложение = 1 LXC-контейнер с Docker Compose внутри (ТЗ 8).
env_encrypted — JSON-строка переменных .env (включая сгенерированные секреты),
хранится зашифрованной (Fernet) через EncryptedString.
"""
__tablename__ = "installed_apps"
id = Column(Integer, primary_key=True, index=True)
# ссылка на каталог (мягкая — приложение может исчезнуть из каталога)
app_id = Column(String(100), index=True, nullable=True)
server_id = Column(Integer, index=True, nullable=True)
vmid = Column(Integer, index=True, nullable=True)
node = Column(String(100), nullable=True)
name = Column(String(200), nullable=False) # пользовательское имя / hostname LXC
version_installed = Column(String(50), nullable=True)
tipi_version_installed = Column(Integer, nullable=True)
env_encrypted = Column(EncryptedString, nullable=True) # JSON строки .env (зашифровано)
ip = Column(String(64), nullable=True)
port = Column(Integer, nullable=True)
status = Column(String(20), nullable=False, default="installing", index=True)
update_available = Column(Boolean, nullable=False, default=False)
last_snapshot = Column(String(200), nullable=True)
# версия/tipi_version, зафиксированные в last_snapshot — для отката версии в БД (M4)
snapshot_version = Column(String(50), nullable=True)
snapshot_tipi_version = Column(Integer, nullable=True)
owner_id = Column(Integer, index=True, nullable=True)
created_at = Column(DateTime(timezone=True), server_default=func.now(), nullable=False)
updated_at = Column(DateTime(timezone=True), server_default=func.now(), onupdate=func.now(), nullable=False)
def env_dict(self) -> dict:
if not self.env_encrypted:
return {}
try:
return _json.loads(self.env_encrypted)
except Exception:
return {}
def to_dict(self) -> dict:
return {
"id": self.id,
"app_id": self.app_id,
"server_id": self.server_id,
"vmid": self.vmid,
"node": self.node,
"name": self.name,
"version_installed": self.version_installed,
"tipi_version_installed": self.tipi_version_installed,
"ip": self.ip,
"port": self.port,
"url": f"http://{self.ip}:{self.port}" if self.ip and self.port else None,
"status": self.status,
"update_available": self.update_available,
"last_snapshot": self.last_snapshot,
"owner_id": self.owner_id,
"created_at": self.created_at.isoformat() if self.created_at else None,
"updated_at": self.updated_at.isoformat() if self.updated_at else None,
}
def __repr__(self):
return f"<InstalledApp(id={self.id}, name='{self.name}', vmid={self.vmid}, status='{self.status}')>"
class AppOperation(Base):
"""Журнал операции над приложением (install/update/rollback/delete/...) — ТЗ 8."""
__tablename__ = "app_operations"
id = Column(Integer, primary_key=True, index=True)
installed_app_id = Column(Integer, ForeignKey("installed_apps.id", ondelete="CASCADE"), index=True, nullable=True)
type = Column(String(20), nullable=False) # install/update/rollback/delete/start/stop/restart
status = Column(String(20), nullable=False, default="running") # running/completed/failed
progress = Column(Integer, nullable=False, default=0)
steps_log = Column(JSON, nullable=False, default=list) # [{step, progress, ts}]
error_text = Column(Text, nullable=True)
user_id = Column(Integer, nullable=True)
started_at = Column(DateTime(timezone=True), server_default=func.now(), nullable=False)
finished_at = Column(DateTime(timezone=True), nullable=True)
def to_dict(self) -> dict:
return {
"id": self.id,
"kind": "appstore",
"installed_app_id": self.installed_app_id,
"type": self.type,
"status": self.status,
"progress": self.progress,
"steps_log": self.steps_log or [],
"error_text": self.error_text,
"user_id": self.user_id,
"started_at": self.started_at.isoformat() if self.started_at else None,
"finished_at": self.finished_at.isoformat() if self.finished_at else None,
}
def __repr__(self):
return f"<AppOperation(id={self.id}, type='{self.type}', status='{self.status}')>"