Add resource limits to app compose generation
This commit is contained in:
@@ -11,20 +11,50 @@ cat > "$COMPOSE_FILE" <<'EOF_COMPOSE'
|
|||||||
services:
|
services:
|
||||||
EOF_COMPOSE
|
EOF_COMPOSE
|
||||||
|
|
||||||
awk '
|
python3 - "$CATALOG_FILE" "$COMPOSE_FILE" <<'PY'
|
||||||
/- id:/ { app=$3 }
|
import sys
|
||||||
/status:/ {
|
|
||||||
if (app != "") {
|
catalog_file = sys.argv[1]
|
||||||
print " " app ":"
|
compose_file = sys.argv[2]
|
||||||
print " image: " app ":latest"
|
|
||||||
print " container_name: " app
|
apps = []
|
||||||
print " restart: unless-stopped"
|
current = None
|
||||||
print " environment:"
|
|
||||||
print " - APP_NAME=" app
|
with open(catalog_file, "r", encoding="utf-8") as f:
|
||||||
print " - ROOT_PATH=/apps/" app
|
for raw in f:
|
||||||
print " networks:"
|
line = raw.rstrip("\n")
|
||||||
print " - appfactory"
|
stripped = line.strip()
|
||||||
print ""
|
|
||||||
}
|
if stripped.startswith("- id:"):
|
||||||
}
|
if current:
|
||||||
' "$CATALOG_FILE" >> "$COMPOSE_FILE"
|
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
|
||||||
|
|||||||
Reference in New Issue
Block a user