Deploy: Stack-Auflösung mit Rückfall über die Projekt-UUID und aussagekräftiger Fehlermeldung; CORTECS_API_KEY aus der Admin-Env zählt als gesetzt

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
RubenRWU
2026-10-15 16:08:56 +02:00
parent 8c3795ec8c
commit fd5f12a8ca
3 changed files with 58 additions and 2 deletions

View File

@@ -83,13 +83,21 @@ class Mittwald:
stacks = self.api("GET", f"/projects/{project_id}/stacks/", write=False)
except DryRunSkip:
return "<STACK_ID>"
items = stacks if isinstance(stacks, list) else (stacks or {}).get("items", [])
items = stacks if isinstance(stacks, list) else ((stacks or {}).get("items") or (stacks or {}).get("stacks") or [])
for s in items:
if str(s.get("description") or s.get("name") or "").lower() == "default":
return s["id"]
if items:
return items[0]["id"]
raise DeployError("Kein Stack im Projekt gefunden.")
# Rückfall: Jedes Mittwald-Projekt hat einen Standard-Stack, dessen ID der UUID des Projekts entspricht
proj = self.try_api("GET", f"/projects/{project_id}/", write=False, fatal=False)
uuid = (proj or {}).get("id")
if uuid and self.try_api("GET", f"/stacks/{uuid}/", write=False, fatal=False) is not None:
self.log(f"Stack über die Projekt-UUID gefunden: {uuid}")
return uuid
raw = json.dumps(stacks, ensure_ascii=False)[:200]
raise DeployError(f"Kein Stack im Projekt gefunden (Antwort der API: {raw}). STACK_ID in den Einstellungen von Hand eintragen "
f"(mStudio bzw. GET /v2/projects/{project_id}/stacks) und Token-Rechte für Container/Stacks prüfen.")
def get_stack(self, stack_id: str) -> dict | None:
return self.try_api("GET", f"/stacks/{stack_id}/", write=False)