Update port configuration for multi-tenant deployment to avoid conflicts

Co-authored-by: Copilot <copilot@github.com>
This commit is contained in:
2026-04-28 13:21:34 +02:00
parent 5a5af5375d
commit d567ba583b
5 changed files with 41 additions and 48 deletions
+1 -1
View File
@@ -14,7 +14,7 @@ Die optimierte Multi-Tenant-Architektur unterstützt **mehrere isolierte Instanz
└─────────────────────────────────────────────────────────────┘
↓ ↓ ↓
┌──────────────┐ ┌──────────────┐ ┌──────────────┐
│ App :8001 │ │ App :8002 │ │ App :8003
│ App :10000 │ │ App :10002 │ │ App :10004
│ schule1 │ │ schule2 │ │ schule3 │
│ Tenant: t1 │ │ Tenant: t2 │ │ Tenant: t3 │
│ 20 Users │ │ 20 Users │ │ 20 Users │
+2 -2
View File
@@ -45,8 +45,8 @@ services:
redis:
condition: service_started
ports:
- "${INVENTAR_HTTP_PORT:-80}:80"
- "${INVENTAR_HTTPS_PORT:-8000}:8000"
- "${INVENTAR_HTTP_PORT:-10000}:80"
- "${INVENTAR_HTTPS_PORT:-10001}:8000"
volumes:
- ./docker/nginx/multitenant.conf:/etc/nginx/conf.d/default.conf
- ./certs:/etc/nginx/certs:ro
+2 -2
View File
@@ -473,8 +473,8 @@ EOF
if [ ! -f "$PROJECT_DIR/.docker-build.env" ]; then
cat > "$TMP_DIR/.docker-build.env" <<EOF
NUITKA_BUILD=0
INVENTAR_HTTP_PORT=80
INVENTAR_HTTPS_PORT=443
INVENTAR_HTTP_PORT=10000
INVENTAR_HTTPS_PORT=10001
INVENTAR_APP_IMAGE=ghcr.io/aiirondev/legendary-octo-garbanzo:$tag
EOF
sudo install -m 644 "$TMP_DIR/.docker-build.env" "$PROJECT_DIR/.docker-build.env"
+34 -41
View File
@@ -15,8 +15,10 @@ if [ "$(id -u)" -ne 0 ] && command -v sudo >/dev/null 2>&1; then
fi
NUITKA_BUILD_VALUE="0"
HTTP_PORT_VALUE="8001"
HTTPS_PORT_VALUE="8443"
HTTP_PORT_VALUE="10000"
HTTPS_PORT_VALUE="10001"
DEFAULT_TENANT_PORT_START="${INVENTAR_TENANT_PORT_START:-10000}"
DEFAULT_TENANT_TLS_OFFSET="${INVENTAR_TENANT_TLS_OFFSET:-1}"
CRON_SETUP_VALUE="${INVENTAR_SETUP_CRON:-1}"
APP_IMAGE_VALUE="${INVENTAR_APP_IMAGE:-$APP_IMAGE_REPO:latest}"
COMPOSE_FILE="docker-compose-multitenant.yml"
@@ -509,58 +511,49 @@ stop_host_nginx_services() {
return 1
}
find_free_port_pair() {
local port="${1:-$DEFAULT_TENANT_PORT_START}"
while port_in_use "$port" || port_in_use "$((port + DEFAULT_TENANT_TLS_OFFSET))"; do
port=$((port + 2))
done
echo "$port"
}
configure_host_ports() {
local requested_http requested_https
local requested_http requested_https base_port
requested_http=""
if [ -f "$ENV_FILE" ]; then
requested_http="$(awk -F= '/^INVENTAR_HTTP_PORT=/{print $2}' "$ENV_FILE" | tr -d ' ' || true)"
fi
if [ -z "$requested_http" ]; then
requested_http="8001"
fi
if stack_owns_host_port "$requested_http" "80"; then
HTTP_PORT_VALUE="$requested_http"
elif port_in_use "$requested_http"; then
if ! port_in_use "$requested_http"; then
HTTP_PORT_VALUE="$requested_http"
echo "Freed HTTP port $requested_http by stopping host nginx service"
else
HTTP_PORT_VALUE="$(find_free_port 8080)"
echo "HTTP port is in use. Using fallback HTTP port: $HTTP_PORT_VALUE"
fi
else
HTTP_PORT_VALUE="$requested_http"
fi
requested_https=""
if [ -f "$ENV_FILE" ]; then
requested_http="$(awk -F= '/^INVENTAR_HTTP_PORT=/{print $2}' "$ENV_FILE" | tr -d ' ' || true)"
requested_https="$(awk -F= '/^INVENTAR_HTTPS_PORT=/{print $2}' "$ENV_FILE" | tr -d ' ' || true)"
fi
if [ -z "$requested_http" ]; then
requested_http="$DEFAULT_TENANT_PORT_START"
fi
if [ -z "$requested_https" ]; then
requested_https="8443"
requested_https="$((requested_http + DEFAULT_TENANT_TLS_OFFSET))"
fi
if stack_owns_host_port "$requested_https" "443"; then
HTTPS_PORT_VALUE="$requested_https"
elif port_in_use "$requested_https"; then
if ! port_in_use "$requested_https"; then
HTTPS_PORT_VALUE="$requested_https"
echo "Freed HTTPS port $requested_https by stopping host nginx service"
return
fi
HTTPS_PORT_VALUE="$(find_free_port 8443)"
echo "HTTPS port is in use. Using fallback HTTPS port: $HTTPS_PORT_VALUE"
else
if stack_owns_host_port "$requested_http" "80" && stack_owns_host_port "$requested_https" "443"; then
HTTP_PORT_VALUE="$requested_http"
HTTPS_PORT_VALUE="$requested_https"
return
fi
if ! port_in_use "$requested_http" && ! port_in_use "$requested_https"; then
HTTP_PORT_VALUE="$requested_http"
HTTPS_PORT_VALUE="$requested_https"
return
fi
base_port="$(find_free_port_pair "$DEFAULT_TENANT_PORT_START")"
HTTP_PORT_VALUE="$base_port"
HTTPS_PORT_VALUE="$((base_port + DEFAULT_TENANT_TLS_OFFSET))"
echo "Tenant host ports are already occupied. Assigned new tenant ports: $HTTP_PORT_VALUE and $HTTPS_PORT_VALUE"
}
ensure_min_docker_disk_space() {
+2 -2
View File
@@ -469,8 +469,8 @@ deploy() {
if [ ! -f "$ENV_FILE" ]; then
cat > "$ENV_FILE" <<EOF
NUITKA_BUILD=0
INVENTAR_HTTP_PORT=80
INVENTAR_HTTPS_PORT=443
INVENTAR_HTTP_PORT=10000
INVENTAR_HTTPS_PORT=10001
INVENTAR_APP_IMAGE=$app_image
EOF
elif grep -q '^INVENTAR_APP_IMAGE=' "$ENV_FILE"; then