changes to the removal process
Release Inventarsystem / release-docker (push) Successful in 2m15s

This commit is contained in:
2026-08-25 00:07:06 +02:00
parent d609775eb6
commit 73db5c5fe0
+22 -9
View File
@@ -873,13 +873,16 @@ case "$COMMAND" in
remove) remove)
FORCE_REMOVE=false FORCE_REMOVE=false
TENANT_ARG="${2:-}"
if [ "$TENANT_ARG" = "--yes" ] || [ "$TENANT_ARG" = "-y" ]; then # Fix: Prüfe sowohl Position 2 als auch 3 auf das -y Flag
if [ "${2:-}" = "--yes" ] || [ "${2:-}" = "-y" ]; then
FORCE_REMOVE=true FORCE_REMOVE=true
TENANT_ID="${3:-}" TENANT_ID="${3:-}"
elif [ "${3:-}" = "--yes" ] || [ "${3:-}" = "-y" ]; then
FORCE_REMOVE=true
TENANT_ID="${2:-}"
else else
TENANT_ID="$TENANT_ARG" TENANT_ID="${2:-}"
fi fi
if [ -z "$TENANT_ID" ]; then if [ -z "$TENANT_ID" ]; then
@@ -902,20 +905,27 @@ case "$COMMAND" in
if [ -n "$APP_CONTAINER" ]; then if [ -n "$APP_CONTAINER" ]; then
# MongoDB-Datenbank via PyMongo direkt im Container droppen # MongoDB-Datenbank via PyMongo direkt im Container droppen
# Fix 1: Wir hängen '|| true' an, damit das Skript nicht abstürzt, falls der Befehl fehlschlägt.
docker exec -i "$APP_CONTAINER" python3 -c ' docker exec -i "$APP_CONTAINER" python3 -c '
import sys, os import sys, os
try: try:
import pymongo import pymongo
tenant_id = sys.argv[1] tenant_id = sys.argv[1]
mongo_uri = os.environ.get("MONGO_URI", "mongodb://localhost:27017/") # In Docker Compose heißt der Host oft "mongodb" statt "localhost"
mongo_uri = os.environ.get("MONGO_URI", "mongodb://mongodb:27017/")
client = pymongo.MongoClient(mongo_uri, serverSelectionTimeoutMS=2000) client = pymongo.MongoClient(mongo_uri, serverSelectionTimeoutMS=2000)
db_name = f"inventar_{tenant_id}"
if db_name in client.list_database_names(): # Fix 2: Wir versuchen beide Formate zu löschen, da "list" zeigt, dass sie "test" und nicht "inventar_test" heißen.
dbs_to_drop = [f"inventar_{tenant_id}", tenant_id]
existing_dbs = client.list_database_names()
for db_name in dbs_to_drop:
if db_name in existing_dbs:
client.drop_database(db_name) client.drop_database(db_name)
print(f"Dropped database: {db_name}") print(f"Dropped database: {db_name}")
except Exception as e: except Exception as e:
print(f"Error dropping database: {e}", file=sys.stderr) print(f"Error dropping database: {e}", file=sys.stderr)
' "$TENANT_ID" > /dev/null 2>&1 ' "$TENANT_ID" > /dev/null 2>&1 || true
# Konfiguration und Port via Host-Funktion bereinigen und Port ermitteln # Konfiguration und Port via Host-Funktion bereinigen und Port ermitteln
if port_to_remove="$(remove_tenant_port "$TENANT_ID" 2>/dev/null)"; then if port_to_remove="$(remove_tenant_port "$TENANT_ID" 2>/dev/null)"; then
@@ -935,13 +945,16 @@ case "$COMMAND" in
fi fi
if [ -n "$port_to_remove" ]; then if [ -n "$port_to_remove" ]; then
remove_runtime_port "$port_to_remove" remove_runtime_port "$port_to_remove" 2>/dev/null || true
fi fi
remove_tenant_nginx_config "$TENANT_ID" remove_tenant_nginx_config "$TENANT_ID"
sync_tenant_port_map sync_tenant_port_map
if [ -n "$(docker ps -qf 'name=app' | head -n 1)" ]; then if [ -n "$(docker ps -qf 'name=app' | head -n 1)" ]; then
restart_app_container restart_app_container || true
fi fi
if [ -n "$port_to_remove" ]; then if [ -n "$port_to_remove" ]; then
echo "Removed tenant '$TENANT_ID' and cleaned runtime port $port_to_remove." echo "Removed tenant '$TENANT_ID' and cleaned runtime port $port_to_remove."
else else