Generate catalog from database
This commit is contained in:
Executable
+59
@@ -0,0 +1,59 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
DB_FILE="/opt/appfactory/data/appfactory/appfactory.db"
|
||||
CATALOG_FILE="/opt/appfactory/apps/catalog.yml"
|
||||
|
||||
mkdir -p "$(dirname "$CATALOG_FILE")"
|
||||
|
||||
python3 - "$DB_FILE" "$CATALOG_FILE" <<'PY'
|
||||
import sqlite3
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
db_file = Path(sys.argv[1])
|
||||
catalog_file = Path(sys.argv[2])
|
||||
|
||||
con = sqlite3.connect(db_file)
|
||||
|
||||
rows = con.execute("""
|
||||
SELECT
|
||||
id,
|
||||
name,
|
||||
language,
|
||||
version,
|
||||
status,
|
||||
COALESCE(memory, ''),
|
||||
COALESCE(cpus, '')
|
||||
FROM apps
|
||||
ORDER BY id
|
||||
""").fetchall()
|
||||
|
||||
lines = ["apps:"]
|
||||
|
||||
for row in rows:
|
||||
app_id, name, language, version, status, memory, cpus = row
|
||||
|
||||
lines.append("")
|
||||
lines.append(f" - id: {app_id}")
|
||||
lines.append(f" name: {name}")
|
||||
lines.append(f" language: {language}")
|
||||
lines.append(f" version: {version}")
|
||||
lines.append(f" base_path: /apps/{app_id}")
|
||||
lines.append(f" docs: /apps/{app_id}/docs")
|
||||
lines.append(f" health: /apps/{app_id}/health")
|
||||
lines.append(f" status: {status}")
|
||||
|
||||
if memory:
|
||||
lines.append(f" memory: {memory}")
|
||||
|
||||
if cpus:
|
||||
lines.append(f' cpus: "{cpus}"')
|
||||
|
||||
catalog_file.write_text(
|
||||
"\n".join(lines) + "\n",
|
||||
encoding="utf-8"
|
||||
)
|
||||
|
||||
print(f"Generated: {catalog_file}")
|
||||
PY
|
||||
Reference in New Issue
Block a user