fix: use spawn_multi_container instead of spawn_container for multi-container support
CRITICAL FIX for container routing bug: - Replace all spawn_container() calls with spawn_multi_container() - spawn_container() was overwriting primary container ID with single ID - This caused all containers to route to same container-id - Now each container_type gets its own route: - spawner.wieland.org/slug-template-01 - spawner.wieland.org/slug-template-02 - spawner.wieland.org/slug-template-next - Affects: Signup, Login, Container Restart endpoints - Fixes: #CONTAINER-ROUTING
This commit is contained in:
parent
64bf15bbe3
commit
c5c2678b65
49
api.py
49
api.py
|
|
@ -220,15 +220,23 @@ def api_verify_signup():
|
||||||
magic_token.mark_as_used()
|
magic_token.mark_as_used()
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
|
|
||||||
# Container spawnen (nur beim ersten Signup)
|
# Container spawnen (nur beim ersten Signup) - Multi-Container kompatibel
|
||||||
if not user.container_id:
|
if not user.container_id:
|
||||||
try:
|
try:
|
||||||
container_mgr = ContainerManager()
|
container_mgr = ContainerManager()
|
||||||
container_id, port = container_mgr.spawn_container(user.id, user.slug)
|
# Nutze spawn_multi_container mit Standard-Template (template-01)
|
||||||
user.container_id = container_id
|
default_template = list(current_app.config['CONTAINER_TEMPLATES'].keys())[0]
|
||||||
user.container_port = port
|
container_id, port = container_mgr.spawn_multi_container(
|
||||||
|
user.id,
|
||||||
|
user.slug,
|
||||||
|
default_template
|
||||||
|
)
|
||||||
|
# Speichere in Primary Container (backwards compatibility)
|
||||||
|
if user.containers:
|
||||||
|
user.containers[0].container_id = container_id
|
||||||
|
user.containers[0].container_port = port
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
current_app.logger.info(f"[SPAWNER] Container erstellt für User {user.id} (slug: {user.slug})")
|
current_app.logger.info(f"[SPAWNER] Container {default_template} erstellt für User {user.id} (slug: {user.slug})")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
current_app.logger.error(f"Container-Spawn fehlgeschlagen: {str(e)}")
|
current_app.logger.error(f"Container-Spawn fehlgeschlagen: {str(e)}")
|
||||||
# User ist trotzdem erstellt, Container kann später manuell erstellt werden
|
# User ist trotzdem erstellt, Container kann später manuell erstellt werden
|
||||||
|
|
@ -307,18 +315,24 @@ def api_verify_login():
|
||||||
# Container existiert nicht mehr - neuen erstellen
|
# Container existiert nicht mehr - neuen erstellen
|
||||||
current_app.logger.warning(f"Container {user.container_id[:12]} nicht gefunden, erstelle neuen: {str(e)}")
|
current_app.logger.warning(f"Container {user.container_id[:12]} nicht gefunden, erstelle neuen: {str(e)}")
|
||||||
try:
|
try:
|
||||||
container_id, port = container_mgr.spawn_container(user.id, user.slug)
|
# Nutze spawn_multi_container für Primary Container
|
||||||
user.container_id = container_id
|
default_template = list(current_app.config['CONTAINER_TEMPLATES'].keys())[0]
|
||||||
user.container_port = port
|
container_id, port = container_mgr.spawn_multi_container(user.id, user.slug, default_template)
|
||||||
current_app.logger.info(f"[LOGIN] Neuer Container erstellt für User {user.email} (slug: {user.slug})")
|
if user.containers:
|
||||||
|
user.containers[0].container_id = container_id
|
||||||
|
user.containers[0].container_port = port
|
||||||
|
current_app.logger.info(f"[LOGIN] Neuer Container {default_template} erstellt für User {user.email} (slug: {user.slug})")
|
||||||
except Exception as spawn_error:
|
except Exception as spawn_error:
|
||||||
current_app.logger.error(f"Container-Spawn fehlgeschlagen: {str(spawn_error)}")
|
current_app.logger.error(f"Container-Spawn fehlgeschlagen: {str(spawn_error)}")
|
||||||
else:
|
else:
|
||||||
# Kein Container vorhanden - neu erstellen
|
# Kein Container vorhanden - neu erstellen
|
||||||
try:
|
try:
|
||||||
container_id, port = container_mgr.spawn_container(user.id, user.slug)
|
# Nutze spawn_multi_container für Primary Container
|
||||||
user.container_id = container_id
|
default_template = list(current_app.config['CONTAINER_TEMPLATES'].keys())[0]
|
||||||
user.container_port = port
|
container_id, port = container_mgr.spawn_multi_container(user.id, user.slug, default_template)
|
||||||
|
if user.containers:
|
||||||
|
user.containers[0].container_id = container_id
|
||||||
|
user.containers[0].container_port = port
|
||||||
current_app.logger.info(f"[LOGIN] Container erstellt für User {user.email} (slug: {user.slug})")
|
current_app.logger.info(f"[LOGIN] Container erstellt für User {user.email} (slug: {user.slug})")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
current_app.logger.error(f"Container-Spawn fehlgeschlagen: {str(e)}")
|
current_app.logger.error(f"Container-Spawn fehlgeschlagen: {str(e)}")
|
||||||
|
|
@ -447,11 +461,14 @@ def api_container_restart():
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
current_app.logger.warning(f"Alter Container konnte nicht gestoppt werden: {str(e)}")
|
current_app.logger.warning(f"Alter Container konnte nicht gestoppt werden: {str(e)}")
|
||||||
|
|
||||||
# Neuen Container starten
|
# Neuen Container starten - Multi-Container kompatibel
|
||||||
try:
|
try:
|
||||||
container_id, port = container_mgr.spawn_container(user.id, user.slug)
|
# Nutze spawn_multi_container für Primary Container
|
||||||
user.container_id = container_id
|
default_template = list(current_app.config['CONTAINER_TEMPLATES'].keys())[0]
|
||||||
user.container_port = port
|
container_id, port = container_mgr.spawn_multi_container(user.id, user.slug, default_template)
|
||||||
|
if user.containers:
|
||||||
|
user.containers[0].container_id = container_id
|
||||||
|
user.containers[0].container_port = port
|
||||||
|
|
||||||
# State auf ACTIVE setzen bei Container-Start (falls noch VERIFIED)
|
# State auf ACTIVE setzen bei Container-Start (falls noch VERIFIED)
|
||||||
if user.state == UserState.VERIFIED.value:
|
if user.state == UserState.VERIFIED.value:
|
||||||
|
|
|
||||||
11
app.py
11
app.py
|
|
@ -152,11 +152,14 @@ def restart_container():
|
||||||
container_mgr.stop_container(current_user.container_id)
|
container_mgr.stop_container(current_user.container_id)
|
||||||
container_mgr.remove_container(current_user.container_id)
|
container_mgr.remove_container(current_user.container_id)
|
||||||
|
|
||||||
# Neuen Container starten
|
# Neuen Container starten - Multi-Container kompatibel
|
||||||
try:
|
try:
|
||||||
container_id, port = container_mgr.spawn_container(current_user.id, current_user.slug)
|
# Nutze spawn_multi_container für Primary Container
|
||||||
current_user.container_id = container_id
|
default_template = list(app.config['CONTAINER_TEMPLATES'].keys())[0]
|
||||||
current_user.container_port = port
|
container_id, port = container_mgr.spawn_multi_container(current_user.id, current_user.slug, default_template)
|
||||||
|
if current_user.containers:
|
||||||
|
current_user.containers[0].container_id = container_id
|
||||||
|
current_user.containers[0].container_port = port
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
app.logger.error(f"Container-Restart fehlgeschlagen: {str(e)}")
|
app.logger.error(f"Container-Restart fehlgeschlagen: {str(e)}")
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user