66 lines
1.8 KiB
Bash
Executable File
66 lines
1.8 KiB
Bash
Executable File
#!/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" "$APPFACTORY_DIR" <<'PY'
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
catalog_file = sys.argv[1]
|
|
compose_file = sys.argv[2]
|
|
appfactory_dir = sys.argv[3]
|
|
|
|
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", "")
|
|
env_file = f"{appfactory_dir}/data/apps/{app_id}/.env"
|
|
|
|
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")
|
|
f.write(" env_file:\n")
|
|
f.write(f" - {env_file}\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
|