diff --git a/scripts/appctl b/scripts/appctl index 3dc9204..608e4fe 100755 --- a/scripts/appctl +++ b/scripts/appctl @@ -2,15 +2,19 @@ # appctl - Unified, Manifest-Driven Container Orchestrator # Discovers individual application repositories located in ~/Sites/*/ -# Injects global homelab secrets from /run/secrets/rendered/traefik-deployments.env +# Injects global homelab secrets and per-app metadata from app.yaml set -e +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +ENGINE="$SCRIPT_DIR/appctl_engine.py" ENV_FILE="/run/secrets/rendered/traefik-deployments.env" if [ ! -f "$ENV_FILE" ] && [ -f "/run/secrets/traefik-deployments.env" ]; then ENV_FILE="/run/secrets/traefik-deployments.env" fi -SITES_DIR="${SITES_DIR:-$HOME/Sites}" +export SITES_DIR="${SITES_DIR:-$HOME/Sites}" +export CORE_DIR="${CORE_DIR:-$HOME/Core}" +export ENV_FILE # Source global secrets/environment if available if [ -f "$ENV_FILE" ]; then @@ -20,156 +24,78 @@ if [ -f "$ENV_FILE" ]; then set +a fi -# Discover registered application directories in ~/Sites/ -get_apps() { - if [ ! -d "$SITES_DIR" ]; then - return - fi - find "$SITES_DIR" -mindepth 1 -maxdepth 2 \( -name "docker-compose.yml" -o -name "compose.yaml" -o -name "compose.yml" \) \ - -exec dirname {} \; | xargs -I {} basename {} | sort -u +# Show help usage +show_help() { + echo "🚀 appctl - Homelab Container Orchestrator" + echo "" + echo "Usage: appctl [service] [options...]" + echo "" + echo "Commands:" + echo " list, status [--core] List all applications (and core infrastructure if --core)" + echo " info Display comprehensive application metadata & status" + echo " up Start/build a service stack" + echo " down Stop and remove a service stack" + echo " restart Restart a service stack" + echo " pull Pull latest images and recreate service" + echo " logs Stream service logs" + echo " config Validate and view resolved compose configuration" + echo " sync Synchronize Homepage dashboard services.yaml from app.yaml" } -# Resolve app directory -get_app_dir() { - local app="$1" - if [ -d "$SITES_DIR/$app" ]; then - echo "$SITES_DIR/$app" - else - echo "" - fi -} - -# Load environment for a specific app (global + app-specific .env or app.yaml) +# Setup application environment based on resolved metadata setup_app_env() { - local app="$1" - local app_dir - app_dir="$(get_app_dir "$app")" - - if [ -z "$app_dir" ]; then - echo "❌ Error: App '$app' not found under $SITES_DIR" + local query="$1" + local resolved_json + resolved_json=$(python3 "$ENGINE" resolve "$query" 2>/dev/null || true) + + if [ -z "$resolved_json" ]; then + echo "❌ Error: Application '$query' not found under $SITES_DIR" exit 1 fi - # 1. Provide sensible defaults based on standard global variables + # Extract fields via python json + APP_DIR=$(python3 -c "import json, sys; d=json.loads(sys.argv[1]); print(d['dir_path'])" "$resolved_json") + CANONICAL_NAME=$(python3 -c "import json, sys; d=json.loads(sys.argv[1]); print(d['name'])" "$resolved_json") + RESOLVED_DOMAIN=$(python3 -c "import json, sys; d=json.loads(sys.argv[1]); print(d['domain'])" "$resolved_json") + + # 1. Base infrastructure defaults export PROXY_NETWORK="${PROXY_NETWORK:-proxy-net}" export NETWORK_NAME="${NETWORK_NAME:-$PROXY_NETWORK}" export CERT_RESOLVER="${CERT_RESOLVER:-myresolver}" export DOMAIN_SUFFIX="${DOMAIN_SUFFIX:-roadtotech.me}" - # Smart per-application default domain and variable mappings - case "$app" in - homelab-landing) - export SERVICE_DOMAIN="${LANDING_DOMAIN:-$DOMAIN_SUFFIX}" - export CONTAINER_NAME="homelab-landing" - ;; - homelab-dashboard) - export SERVICE_DOMAIN="${DASHBOARD_DOMAIN:-dashboard.$DOMAIN_SUFFIX}" - export LEARNING_DOMAIN="${LEARNING_DOMAIN:-learning.$DOMAIN_SUFFIX}" - ;; - homelab-doc2site) - export SERVICE_NAME="docs" - export CONTAINER_NAME="docs" - export SERVICE_DOMAIN="${DOCS_DOMAIN:-docs.$DOMAIN_SUFFIX}" - export PROJECT_PATH="${DOCS_PROJECT_PATH:-/home/kiskaadee/Learn/backend-residency}" - ;; - homelab-jellyfin) - export SERVICE_NAME="${JELLYFIN_SERVICE_NAME:-jellyfin}" - export CONTAINER_NAME="${JELLYFIN_CONTAINER_NAME:-jellyfin}" - export SERVICE_DOMAIN="${JELLYFIN_DOMAIN:-jellyfin.$DOMAIN_SUFFIX}" - export MEDIA_PATH="${JELLYFIN_MEDIA_PATH:-/media}" - ;; - homelab-excalidraw) - export SERVICE_DOMAIN="${EXCALIDRAW_DOMAIN:-excalidraw.$DOMAIN_SUFFIX}" - export DOMAIN="${EXCALIDRAW_DOMAIN:-excalidraw.$DOMAIN_SUFFIX}" - ;; - homelab-mermaid) - export SERVICE_NAME="${MERMAID_SERVICE_NAME:-mermaid}" - export SERVICE_DOMAIN="${MERMAID_DOMAIN:-mermaid.$DOMAIN_SUFFIX}" - ;; - homelab-minecraft) - export SERVICE_DOMAIN="${MINECRAFT_DOMAIN:-minecraft.$DOMAIN_SUFFIX}" - export MINECRAFT_DOMAIN="${MINECRAFT_DOMAIN:-minecraft.$DOMAIN_SUFFIX}" - ;; - homelab-gitea) - export SERVICE_NAME="gitea" - export CONTAINER_NAME="gitea" - export SERVICE_DOMAIN="${GITEA_DOMAIN:-gitea.$DOMAIN_SUFFIX}" - export SSH_DOMAIN="${GITEA_SSH_DOMAIN:-gitea.$DOMAIN_SUFFIX}" - ;; - homelab-ollama) - export SERVICE_NAME="ollama" - export CONTAINER_NAME="ollama" - export SERVICE_DOMAIN="${OLLAMA_DOMAIN:-ollama.$DOMAIN_SUFFIX}" - ;; - homelab-pgsql) - export SERVICE_NAME="pgsql" - export SERVICE_DOMAIN="${POSTGRES_DOMAIN:-pgsql.$DOMAIN_SUFFIX}" - ;; - homelab-mongodb) - export SERVICE_NAME="mongodb" - export SERVICE_DOMAIN="${MONGO_DOMAIN:-mongodb.$DOMAIN_SUFFIX}" - ;; - *) - export SERVICE_DOMAIN="${SERVICE_DOMAIN:-$app.$DOMAIN_SUFFIX}" - ;; - esac + # 2. Canonical application identity + export SERVICE_NAME="$CANONICAL_NAME" + export CONTAINER_NAME="$CANONICAL_NAME" + export SERVICE_DOMAIN="$RESOLVED_DOMAIN" + export DOMAIN="$RESOLVED_DOMAIN" - export DOMAIN="${DOMAIN:-$SERVICE_DOMAIN}" - export CONTAINER_NAME="${CONTAINER_NAME:-$app}" + # 3. Dynamic environment variables from app.yaml (e.g. PROJECT_PATH, MEDIA_PATH, etc.) + eval "$(python3 -c " +import json, sys +d = json.loads(sys.argv[1]) +env_dict = d.get('env', {}) +for k, v in env_dict.items(): + print(f'export {k}=\"{v}\"') +" "$resolved_json")" - # 2. Source local .env if present - if [ -f "$app_dir/.env" ]; then + # 4. Source local .env if present + if [ -f "$APP_DIR/.env" ]; then set -a # shellcheck disable=SC1090 - source "$app_dir/.env" + source "$APP_DIR/.env" set +a fi - # 3. Source local app.env if present - if [ -f "$app_dir/app.env" ]; then + # 6. Source local app.env if present + if [ -f "$APP_DIR/app.env" ]; then set -a # shellcheck disable=SC1090 - source "$app_dir/app.env" + source "$APP_DIR/app.env" set +a fi } -# Show help usage -show_help() { - echo "🚀 appctl - Homelab Container Orchestrator" - echo "" - echo "Usage: appctl [service] [args...]" - echo "" - echo "Commands:" - echo " list, status List all discovered applications in ~/Sites and their live status" - echo " up Start/build a service stack" - echo " down Stop and remove a service stack" - echo " restart Restart a service stack" - echo " logs Stream service logs" - echo " pull Pull latest images and recreate service" - echo " config Validate and view resolved compose configuration" -} - -# List applications dynamically -cmd_list() { - printf "%-20s %-15s %-35s\n" "SERVICE" "STATUS" "DIRECTORY" - printf "%-20s %-15s %-35s\n" "-------" "------" "---------" - - for app in $(get_apps); do - local app_dir="$SITES_DIR/$app" - local status="🔴 Stopped" - - if cd "$app_dir" >/dev/null 2>&1; then - local running_count - running_count=$(docker compose ps --format json 2>/dev/null | grep -c '"State":' || true) - if [ "$running_count" -gt 0 ]; then - status="đŸŸĸ Running ($running_count)" - fi - printf "%-20s %-15s %-35s\n" "$app" "$status" "~/Sites/$app" - fi - done -} - if [ $# -lt 1 ]; then show_help exit 1 @@ -180,41 +106,51 @@ APP=$2 case "$COMMAND" in list|status) - cmd_list + python3 "$ENGINE" list "${@:2}" + ;; + info) + if [ -z "$APP" ]; then echo "❌ Error: Service name required"; exit 1; fi + python3 "$ENGINE" info "$APP" + ;; + sync) + python3 "$ENGINE" sync "${@:2}" ;; up) if [ -z "$APP" ]; then echo "❌ Error: Service name required"; exit 1; fi setup_app_env "$APP" - echo "🚀 Starting $APP..." - cd "$(get_app_dir "$APP")" && docker compose up -d --remove-orphans "${@:3}" + echo "🚀 Starting $CANONICAL_NAME ($APP_DIR)..." + cd "$APP_DIR" && docker compose up -d --remove-orphans "${@:3}" + python3 "$ENGINE" sync >/dev/null 2>&1 || true ;; down) if [ -z "$APP" ]; then echo "❌ Error: Service name required"; exit 1; fi setup_app_env "$APP" - echo "🛑 Stopping $APP..." - cd "$(get_app_dir "$APP")" && docker compose down "${@:3}" + echo "🛑 Stopping $CANONICAL_NAME ($APP_DIR)..." + cd "$APP_DIR" && docker compose down "${@:3}" + python3 "$ENGINE" sync >/dev/null 2>&1 || true ;; restart) if [ -z "$APP" ]; then echo "❌ Error: Service name required"; exit 1; fi setup_app_env "$APP" - echo "🔄 Restarting $APP..." - cd "$(get_app_dir "$APP")" && docker compose down && docker compose up -d "${@:3}" + echo "🔄 Restarting $CANONICAL_NAME ($APP_DIR)..." + cd "$APP_DIR" && docker compose down && docker compose up -d "${@:3}" + python3 "$ENGINE" sync >/dev/null 2>&1 || true ;; pull) if [ -z "$APP" ]; then echo "❌ Error: Service name required"; exit 1; fi setup_app_env "$APP" - echo "đŸ“Ĩ Pulling latest images for $APP..." - cd "$(get_app_dir "$APP")" && docker compose pull && docker compose up -d --remove-orphans "${@:3}" + echo "đŸ“Ĩ Pulling latest images for $CANONICAL_NAME..." + cd "$APP_DIR" && docker compose pull && docker compose up -d --remove-orphans "${@:3}" ;; logs) if [ -z "$APP" ]; then echo "❌ Error: Service name required"; exit 1; fi setup_app_env "$APP" - cd "$(get_app_dir "$APP")" && docker compose logs -f "${@:3}" + cd "$APP_DIR" && docker compose logs -f "${@:3}" ;; config) if [ -z "$APP" ]; then echo "❌ Error: Service name required"; exit 1; fi setup_app_env "$APP" - cd "$(get_app_dir "$APP")" && docker compose config + cd "$APP_DIR" && docker compose config ;; *) show_help diff --git a/scripts/appctl_engine.py b/scripts/appctl_engine.py new file mode 100755 index 0000000..62d2419 --- /dev/null +++ b/scripts/appctl_engine.py @@ -0,0 +1,402 @@ +#!/usr/bin/env python3 +""" +appctl_engine.py - Homelab Metadata Engine & Orchestration Parser +""" + +import os +import sys +import json +import subprocess +import shutil + +SITES_DIR = os.environ.get("SITES_DIR", os.path.expanduser("~/Sites")) +CORE_DIR = os.environ.get("CORE_DIR", os.path.expanduser("~/Core")) +ENV_FILE = os.environ.get("ENV_FILE", "/run/secrets/rendered/traefik-deployments.env") +if not os.path.isfile(ENV_FILE) and os.path.isfile("/run/secrets/traefik-deployments.env"): + ENV_FILE = "/run/secrets/traefik-deployments.env" + + +def parse_yaml_simple(text): + """Simple, zero-dependency YAML parser tailored for app.yaml schemas.""" + data = {} + current_key = None + lines = text.splitlines() + for line in lines: + stripped = line.strip() + if not stripped or stripped.startswith("#"): + continue + indent = len(line) - len(line.lstrip(" ")) + + # List element + if stripped.startswith("- "): + item = stripped[2:].strip().strip("\"'") + if current_key: + if not isinstance(data.get(current_key), list): + data[current_key] = [] + data[current_key].append(item) + continue + + if ":" in stripped: + k, v = stripped.split(":", 1) + k = k.strip() + v = v.strip().strip("\"'") + + if v.lower() == "true": + v = True + elif v.lower() == "false": + v = False + elif v.isdigit(): + v = int(v) + + if indent == 0: + current_key = k + if v == "": + data[k] = {} + else: + data[k] = v + elif indent > 0 and current_key: + if not isinstance(data.get(current_key), dict): + data[current_key] = {} + data[current_key][k] = v + + return data + + +def load_global_env(): + """Load default global environment file if present.""" + env_vars = {} + if os.path.isfile(ENV_FILE): + try: + with open(ENV_FILE, "r") as f: + for line in f: + line = line.strip() + if line and not line.startswith("#") and "=" in line: + k, v = line.split("=", 1) + env_vars[k.strip()] = v.strip().strip("\"'") + except Exception: + pass + return env_vars + + +def get_all_apps(): + """Scan SITES_DIR for all application directories and parse app.yaml.""" + apps = [] + if not os.path.isdir(SITES_DIR): + return apps + + for entry in sorted(os.listdir(SITES_DIR)): + app_dir = os.path.join(SITES_DIR, entry) + if not os.path.isdir(app_dir): + continue + + manifest_path = os.path.join(app_dir, "app.yaml") + manifest = {} + if os.path.isfile(manifest_path): + try: + manifest = parse_yaml_simple(open(manifest_path).read()) + except Exception: + pass + + canonical_name = manifest.get("name") or entry.replace("homelab-", "") + aliases = manifest.get("aliases") or [] + if isinstance(aliases, str): + aliases = [aliases] + + app_info = { + "dir_name": entry, + "dir_path": app_dir, + "name": canonical_name, + "aliases": aliases, + "domain": manifest.get("domain", f"{canonical_name}.roadtotech.me"), + "description": manifest.get("description", ""), + "visible": manifest.get("visible", True), + "auth": manifest.get("auth", False), + "networks": manifest.get("networks", ["proxy-net"]), + "env": manifest.get("env", {}), + "homepage": manifest.get("homepage", {}), + "has_compose": os.path.isfile(os.path.join(app_dir, "docker-compose.yml")), + } + apps.append(app_info) + return apps + + +def resolve_app(query): + """Resolve an app query (canonical name, alias, or folder name).""" + apps = get_all_apps() + query_clean = query.strip().lower() + + # 1. Exact match on canonical name + for app in apps: + if app["name"].lower() == query_clean: + return app + + # 2. Match on alias + for app in apps: + for alias in app["aliases"]: + if str(alias).lower() == query_clean: + return app + + # 3. Match on directory name + for app in apps: + if app["dir_name"].lower() == query_clean: + return app + + # 4. Match stripped 'homelab-' prefix + for app in apps: + if app["dir_name"].lower() == f"homelab-{query_clean}": + return app + + return None + + +def get_docker_status(dir_path): + """Get container running status for a docker-compose directory.""" + if not os.path.isdir(dir_path) or not os.path.isfile(os.path.join(dir_path, "docker-compose.yml")): + return "âšĒ Not Stack" + + try: + res = subprocess.run( + ["docker", "compose", "ps", "-q"], + cwd=dir_path, + capture_output=True, + text=True, + check=False, + ) + container_ids = [c for c in res.stdout.strip().splitlines() if c] + if not container_ids: + return "🔴 Stopped" + + # Check how many are running + inspect_res = subprocess.run( + ["docker", "inspect", "-f", "{{.State.Running}}"] + container_ids, + capture_output=True, + text=True, + check=False, + ) + running_states = inspect_res.stdout.strip().splitlines() + running_count = sum(1 for s in running_states if s.lower() == "true") + total_count = len(container_ids) + + if running_count == total_count and total_count > 0: + return f"đŸŸĸ Running ({running_count})" + elif running_count > 0: + return f"🟡 Degraded ({running_count}/{total_count})" + else: + return "🔴 Stopped" + except Exception: + return "❓ Unknown" + + +def get_core_services(): + """Inspect Core stack from CORE_DIR.""" + core_services = [ + {"name": "traefik", "domain": "traefik.roadtotech.me", "container": "traefik", "desc": "Edge Reverse Proxy & ACME TLS"}, + {"name": "authelia", "domain": "auth.roadtotech.me", "container": "authelia", "desc": "Identity & SSO Access Control"}, + {"name": "portainer", "domain": "portainer.roadtotech.me", "container": "portainer", "desc": "Container Management GUI"}, + {"name": "dozzle", "domain": "logs.roadtotech.me", "container": "dozzle", "desc": "Real-time Log Viewer"}, + {"name": "socket-proxy", "domain": "internal", "container": "socket-proxy", "desc": "Docker Socket Security Proxy"}, + {"name": "diun", "domain": "internal", "container": "diun", "desc": "Docker Image Update Notifier"}, + {"name": "watchtower", "domain": "internal", "container": "watchtower", "desc": "Automated Container Updates"}, + ] + for svc in core_services: + try: + inspect_res = subprocess.run( + ["docker", "inspect", "-f", "{{.State.Running}}", svc["container"]], + capture_output=True, + text=True, + check=False, + ) + state = inspect_res.stdout.strip() + if state.lower() == "true": + svc["status"] = "đŸŸĸ Running (1)" + else: + svc["status"] = "🔴 Stopped" + except Exception: + svc["status"] = "❓ Unknown" + return core_services + + +def cmd_list(args): + """Format and print application and core stack listings.""" + show_core = any(a in ["--core", "-c", "--all", "-a"] for a in args) + apps = get_all_apps() + + print(f"{'SERVICE':<18} {'STATUS':<16} {'DOMAIN':<30} {'DIRECTORY'}") + print(f"{'-------':<18} {'------':<16} {'------':<30} {'---------'}") + + for app in apps: + status = get_docker_status(app["dir_path"]) + rel_dir = app["dir_path"].replace(os.path.expanduser("~"), "~") + print(f"{app['name']:<18} {status:<16} {app['domain']:<30} {rel_dir}") + + if show_core: + print() + print(f"{'CORE SERVICE':<18} {'STATUS':<16} {'DOMAIN':<30} {'DIRECTORY'}") + print(f"{'------------':<18} {'------':<16} {'------':<30} {'---------'}") + core_services = get_core_services() + rel_core = CORE_DIR.replace(os.path.expanduser("~"), "~") + for svc in core_services: + print(f"{svc['name']:<18} {svc['status']:<16} {svc['domain']:<30} {rel_core}") + + +def cmd_info(args): + """Show detailed metadata and runtime overview for a service.""" + if not args: + print("❌ Error: Service name required for 'info' command") + sys.exit(1) + + query = args[0] + app = resolve_app(query) + if not app: + # Check if it's a core service + core_services = get_core_services() + for svc in core_services: + if svc["name"] == query: + print(f"â„šī¸ Core Infrastructure Service: {svc['name']}") + print("-" * 45) + print(f"Directory: {CORE_DIR}") + print(f"Status: {svc['status']}") + print(f"Primary Domain: https://{svc['domain']}" if svc["domain"] != "internal" else f"Domain: {svc['domain']}") + print(f"Description: {svc['desc']}") + return + + print(f"❌ Error: Application '{query}' not found under {SITES_DIR}") + sys.exit(1) + + status = get_docker_status(app["dir_path"]) + aliases_str = ", ".join(app["aliases"]) if app["aliases"] else "None" + auth_str = "🔒 Protected (Authelia)" if app["auth"] else "âšĒ Disabled (Public)" + visible_str = f"đŸŸĸ Visible ({app['homepage'].get('group', 'Default')})" if app["visible"] else "âšĒ Hidden" + networks_str = ", ".join(app["networks"]) if app["networks"] else "proxy-net" + + print(f"â„šī¸ Application Information: {app['name']}") + print("-" * 45) + print(f"Directory: {app['dir_path']}") + print(f"Canonical Name: {app['name']}") + print(f"Aliases: {aliases_str}") + print(f"Status: {status}") + print(f"Primary Domain: https://{app['domain']}") + print(f"Authelia Guard: {auth_str}") + print(f"Dashboard View: {visible_str}") + print(f"Networks: {networks_str}") + if app["description"]: + print(f"Description: {app['description']}") + + if app["env"]: + print("\nConfigured Environment Defaults:") + for k, v in app["env"].items(): + print(f" {k} = {v}") + + if app["visible"] and app["homepage"]: + hp = app["homepage"] + print("\nHomepage Dashboard Card:") + print(f" Title: {hp.get('title', app['name'].title())}") + print(f" Group: {hp.get('group', 'Applications')}") + print(f" Icon: {hp.get('icon', 'default.png')}") + print(f" Container: {hp.get('container', app['name'])}") + + +def cmd_resolve(args): + """Resolve service name and output JSON for the bash caller.""" + if not args: + sys.exit(1) + app = resolve_app(args[0]) + if not app: + sys.exit(1) + print(json.dumps(app)) + + +def cmd_sync_homepage(args): + """Compile Sites/*/app.yaml into homelab-dashboard/config/services.yaml.""" + dashboard_dir = os.path.join(SITES_DIR, "homelab-dashboard") + for a in args: + if a.startswith("--dashboard-dir="): + dashboard_dir = a.split("=", 1)[1] + + services_yaml_path = os.path.join(dashboard_dir, "config", "services.yaml") + if not os.path.isdir(os.path.dirname(services_yaml_path)): + print(f"❌ Error: Dashboard directory not found at {dashboard_dir}") + sys.exit(1) + + apps = get_all_apps() + visible_apps = [a for a in apps if a.get("visible", True)] + + # Group by homepage group + groups = {} + for app in visible_apps: + hp = app.get("homepage", {}) + group_name = hp.get("group", "Applications") + if group_name not in groups: + groups[group_name] = [] + + card_title = hp.get("title", app["name"].title()) + icon = hp.get("icon", f"{app['name']}.png") + container = hp.get("container", app["name"]) + weight = hp.get("weight", 50) + desc = app.get("description", "") + + card_data = { + "title": card_title, + "icon": icon, + "href": f"https://{app['domain']}", + "description": desc, + "server": "my-docker", + "container": container, + "weight": weight, + } + groups[group_name].append(card_data) + + # Preferred group order + preferred_order = ["Knowledge & Notes", "Media & Productivity", "Development & AI", "Applications"] + sorted_groups = [] + for g in preferred_order: + if g in groups: + sorted_groups.append(g) + for g in groups: + if g not in sorted_groups: + sorted_groups.append(g) + + # Render YAML + lines = ["---", "# 🚀 Auto-generated by appctl sync - Do not edit directly"] + for group_name in sorted_groups: + cards = sorted(groups[group_name], key=lambda x: (x["weight"], x["title"])) + lines.append(f"- {group_name}:") + for card in cards: + lines.append(f" - {card['title']}:") + lines.append(f" icon: {card['icon']}") + lines.append(f" href: {card['href']}") + if card["description"]: + lines.append(f" description: {card['description']}") + lines.append(f" server: {card['server']}") + lines.append(f" container: {card['container']}") + lines.append("") + + content = "\n".join(lines).strip() + "\n" + with open(services_yaml_path, "w") as f: + f.write(content) + + print(f"✨ Homepage synchronized successfully ({len(visible_apps)} visible apps in {len(sorted_groups)} groups)") + print(f"📄 Generated {services_yaml_path}") + + +def main(): + if len(sys.argv) < 2: + sys.exit(1) + + command = sys.argv[1] + args = sys.argv[2:] + + if command == "list": + cmd_list(args) + elif command == "info": + cmd_info(args) + elif command == "resolve": + cmd_resolve(args) + elif command == "sync": + cmd_sync_homepage(args) + else: + sys.exit(1) + + +if __name__ == "__main__": + main()