#!/usr/bin/env bash set -euo pipefail CONFIG_FILE="/opt/appfactory/config/appfactory.env" source "$CONFIG_FILE" CATALOG_FILE="$APPFACTORY_DIR/apps/catalog.yml" COMPOSE_FILE="$APPFACTORY_DIR/deploy/apps-compose.yml" cat > "$COMPOSE_FILE" <<'EOF_COMPOSE' services: EOF_COMPOSE python3 - "$CATALOG_FILE" "$COMPOSE_FILE" <<'PY' import sys catalog_file = sys.argv[1] compose_file = sys.argv[2] apps = [] current = None with open(catalog_file, "r", encoding="utf-8") as f: for raw in f: line = raw.rstrip("\n") stripped = line.strip() if stripped.startswith("- id:"): if current: apps.append(current) current = {"id": stripped.split(":", 1)[1].strip()} elif current and ":" in stripped: key, value = stripped.split(":", 1) current[key.strip()] = value.strip().strip('"') if current: apps.append(current) with open(compose_file, "a", encoding="utf-8") as f: for app in apps: app_id = app["id"] memory = app.get("memory", "") cpus = app.get("cpus", "") f.write(f" {app_id}:\n") f.write(f" image: {app_id}:latest\n") f.write(f" container_name: {app_id}\n") f.write(" restart: unless-stopped\n") if memory: f.write(f" mem_limit: {memory}\n") if cpus: f.write(f" cpus: \"{cpus}\"\n") f.write(" environment:\n") f.write(f" - APP_NAME={app_id}\n") f.write(f" - ROOT_PATH=/apps/{app_id}\n") f.write(" networks:\n") f.write(" - appfactory\n\n") PY