diff --git a/scripts/generate-apps-compose.sh b/scripts/generate-apps-compose.sh index 5514b81..73f3ff7 100755 --- a/scripts/generate-apps-compose.sh +++ b/scripts/generate-apps-compose.sh @@ -11,20 +11,50 @@ cat > "$COMPOSE_FILE" <<'EOF_COMPOSE' services: EOF_COMPOSE -awk ' - /- id:/ { app=$3 } - /status:/ { - if (app != "") { - print " " app ":" - print " image: " app ":latest" - print " container_name: " app - print " restart: unless-stopped" - print " environment:" - print " - APP_NAME=" app - print " - ROOT_PATH=/apps/" app - print " networks:" - print " - appfactory" - print "" - } - } -' "$CATALOG_FILE" >> "$COMPOSE_FILE" +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