Store new apps in database
This commit is contained in:
+56
-14
@@ -7,24 +7,21 @@ source "$CONFIG_FILE"
|
|||||||
APP_ID="${1:-}"
|
APP_ID="${1:-}"
|
||||||
APP_NAME="${2:-$APP_ID}"
|
APP_NAME="${2:-$APP_ID}"
|
||||||
|
|
||||||
|
DB_FILE="/opt/appfactory/data/appfactory/appfactory.db"
|
||||||
|
TEMPLATE_DIR="$WORKSPACE_DIR/python-fastapi-template"
|
||||||
|
TARGET_DIR="$WORKSPACE_DIR/$APP_ID"
|
||||||
|
TOOLS_DIR="$WORKSPACE_DIR/appfactory-tools"
|
||||||
|
|
||||||
if [ -z "$APP_ID" ]; then
|
if [ -z "$APP_ID" ]; then
|
||||||
echo "Usage: ./new-python-app.sh <app-id> [app-name]"
|
echo "Usage: ./new-python-app.sh <app-id> [app-name]"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
TEMPLATE_DIR="$WORKSPACE_DIR/python-fastapi-template"
|
if [ ! -f "$DB_FILE" ]; then
|
||||||
TARGET_DIR="$WORKSPACE_DIR/$APP_ID"
|
echo "Missing database: $DB_FILE"
|
||||||
|
echo "Run: $TOOLS_DIR/scripts/init-appfactory-db.sh"
|
||||||
safe_chown() {
|
exit 1
|
||||||
local target="$1"
|
fi
|
||||||
local uid
|
|
||||||
local gid
|
|
||||||
|
|
||||||
uid="${APP_UID:-$(stat -c '%u' "$WORKSPACE_DIR")}"
|
|
||||||
gid="${APP_GID:-$(stat -c '%g' "$WORKSPACE_DIR")}"
|
|
||||||
|
|
||||||
chown -R "$uid:$gid" "$target" || true
|
|
||||||
}
|
|
||||||
|
|
||||||
if [ ! -d "$TEMPLATE_DIR" ]; then
|
if [ ! -d "$TEMPLATE_DIR" ]; then
|
||||||
echo "Template not found: $TEMPLATE_DIR"
|
echo "Template not found: $TEMPLATE_DIR"
|
||||||
@@ -110,7 +107,52 @@ git add .
|
|||||||
git commit -m "Initial $APP_NAME"
|
git commit -m "Initial $APP_NAME"
|
||||||
git push -u origin main
|
git push -u origin main
|
||||||
|
|
||||||
safe_chown "$TARGET_DIR"
|
echo "Saving app to database..."
|
||||||
|
|
||||||
|
python3 - "$DB_FILE" "$APP_ID" "$APP_NAME" <<'PY'
|
||||||
|
import sqlite3
|
||||||
|
import sys
|
||||||
|
|
||||||
|
db_file = sys.argv[1]
|
||||||
|
app_id = sys.argv[2]
|
||||||
|
app_name = sys.argv[3]
|
||||||
|
|
||||||
|
con = sqlite3.connect(db_file)
|
||||||
|
|
||||||
|
con.execute(
|
||||||
|
"""
|
||||||
|
INSERT INTO apps (
|
||||||
|
id,
|
||||||
|
name,
|
||||||
|
language,
|
||||||
|
version,
|
||||||
|
status
|
||||||
|
)
|
||||||
|
VALUES (?, ?, ?, ?, ?)
|
||||||
|
ON CONFLICT(id) DO UPDATE SET
|
||||||
|
name = excluded.name,
|
||||||
|
language = excluded.language,
|
||||||
|
version = excluded.version,
|
||||||
|
status = excluded.status,
|
||||||
|
updated_at = CURRENT_TIMESTAMP
|
||||||
|
""",
|
||||||
|
(
|
||||||
|
app_id,
|
||||||
|
app_name or app_id,
|
||||||
|
"python",
|
||||||
|
"1.0.0",
|
||||||
|
"created",
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
|
con.commit()
|
||||||
|
con.close()
|
||||||
|
PY
|
||||||
|
|
||||||
|
"$TOOLS_DIR/scripts/generate-catalog.sh"
|
||||||
|
"$TOOLS_DIR/scripts/generate-apps-compose.sh"
|
||||||
|
"$TOOLS_DIR/scripts/generate-caddyfile.sh"
|
||||||
|
"$TOOLS_DIR/scripts/generate-apps-page.sh"
|
||||||
|
|
||||||
echo ""
|
echo ""
|
||||||
echo "DONE"
|
echo "DONE"
|
||||||
|
|||||||
Reference in New Issue
Block a user