Generate app ports in catalog and gateway
This commit is contained in:
@@ -29,16 +29,42 @@ cat > "$CADDY_FILE" <<EOF_CADDY
|
|||||||
EOF_CADDY
|
EOF_CADDY
|
||||||
|
|
||||||
if [ -f "$CATALOG_FILE" ]; then
|
if [ -f "$CATALOG_FILE" ]; then
|
||||||
awk '
|
python3 - "$CATALOG_FILE" "$CADDY_FILE" <<'PY'
|
||||||
/^[[:space:]]*-[[:space:]]id:/ {
|
import sys
|
||||||
app=$3
|
|
||||||
|
|
||||||
print " handle_path /apps/" app "/* {"
|
catalog_file = sys.argv[1]
|
||||||
print " reverse_proxy " app ":8000"
|
caddy_file = sys.argv[2]
|
||||||
print " }"
|
|
||||||
print ""
|
apps = []
|
||||||
}
|
current = None
|
||||||
' "$CATALOG_FILE" >> "$CADDY_FILE"
|
|
||||||
|
with open(catalog_file, "r", encoding="utf-8") as f:
|
||||||
|
for raw in f:
|
||||||
|
stripped = raw.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(caddy_file, "a", encoding="utf-8") as f:
|
||||||
|
for app in apps:
|
||||||
|
app_id = app.get("id")
|
||||||
|
port = app.get("container_port") or app.get("port") or "8000"
|
||||||
|
|
||||||
|
if not app_id:
|
||||||
|
continue
|
||||||
|
|
||||||
|
f.write(f" handle_path /apps/{app_id}/* {{\n")
|
||||||
|
f.write(f" reverse_proxy {app_id}:{port}\n")
|
||||||
|
f.write(" }\n\n")
|
||||||
|
PY
|
||||||
fi
|
fi
|
||||||
|
|
||||||
cat >> "$CADDY_FILE" <<EOF_CADDY
|
cat >> "$CADDY_FILE" <<EOF_CADDY
|
||||||
|
|||||||
@@ -24,24 +24,49 @@ SELECT
|
|||||||
version,
|
version,
|
||||||
status,
|
status,
|
||||||
COALESCE(memory, ''),
|
COALESCE(memory, ''),
|
||||||
COALESCE(cpus, '')
|
COALESCE(cpus, ''),
|
||||||
|
COALESCE(container_port, 8000),
|
||||||
|
COALESCE(health_url, '/health'),
|
||||||
|
COALESCE(runtime, ''),
|
||||||
|
COALESCE(template, '')
|
||||||
FROM apps
|
FROM apps
|
||||||
|
WHERE is_enabled = 1
|
||||||
ORDER BY id
|
ORDER BY id
|
||||||
""").fetchall()
|
""").fetchall()
|
||||||
|
|
||||||
lines = ["apps:"]
|
lines = ["apps:"]
|
||||||
|
|
||||||
for row in rows:
|
for row in rows:
|
||||||
app_id, name, language, version, status, memory, cpus = row
|
(
|
||||||
|
app_id,
|
||||||
|
name,
|
||||||
|
language,
|
||||||
|
version,
|
||||||
|
status,
|
||||||
|
memory,
|
||||||
|
cpus,
|
||||||
|
container_port,
|
||||||
|
health_url,
|
||||||
|
runtime,
|
||||||
|
template,
|
||||||
|
) = row
|
||||||
|
|
||||||
|
if not str(health_url).startswith("/"):
|
||||||
|
health_path = "/health"
|
||||||
|
else:
|
||||||
|
health_path = health_url
|
||||||
|
|
||||||
lines.append("")
|
lines.append("")
|
||||||
lines.append(f" - id: {app_id}")
|
lines.append(f" - id: {app_id}")
|
||||||
lines.append(f" name: {name}")
|
lines.append(f" name: {name}")
|
||||||
lines.append(f" language: {language}")
|
lines.append(f" language: {language}")
|
||||||
|
lines.append(f" runtime: {runtime}")
|
||||||
|
lines.append(f" template: {template}")
|
||||||
lines.append(f" version: {version}")
|
lines.append(f" version: {version}")
|
||||||
|
lines.append(f" container_port: {container_port}")
|
||||||
lines.append(f" base_path: /apps/{app_id}")
|
lines.append(f" base_path: /apps/{app_id}")
|
||||||
lines.append(f" docs: /apps/{app_id}/docs")
|
lines.append(f" docs: /apps/{app_id}/docs")
|
||||||
lines.append(f" health: /apps/{app_id}/health")
|
lines.append(f" health: /apps/{app_id}{health_path}")
|
||||||
lines.append(f" status: {status}")
|
lines.append(f" status: {status}")
|
||||||
|
|
||||||
if memory:
|
if memory:
|
||||||
|
|||||||
Reference in New Issue
Block a user