Fix postgres DNS: put both services on dokploy-network

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-07-25 20:48:13 +03:00
co-authored by Cursor
parent d78797db82
commit dcdd1f6898
3 changed files with 53 additions and 21 deletions
+39 -6
View File
@@ -3,19 +3,50 @@ set -e
echo "==> VpnPanel starting"
# Always build DATABASE_URL from POSTGRES_* (Dokploy-friendly)
DB_HOST="${POSTGRES_HOST:-postgres}"
DB_PORT="${POSTGRES_PORT:-5432}"
DB_USER="${POSTGRES_USER:-vpn}"
DB_PASS="${POSTGRES_PASSWORD:-vpn}"
DB_NAME="${POSTGRES_DB:-vpn_panel}"
export DATABASE_URL="$(
POSTGRES_HOST="$DB_HOST" \
POSTGRES_PORT="$DB_PORT" \
POSTGRES_USER="$DB_USER" \
POSTGRES_PASSWORD="$DB_PASS" \
POSTGRES_DB="$DB_NAME" \
python - <<'PY'
import os
from urllib.parse import quote_plus
user = os.environ.get("POSTGRES_USER", "vpn")
password = os.environ.get("POSTGRES_PASSWORD", "vpn")
db = os.environ.get("POSTGRES_DB", "vpn_panel")
print(f"postgresql+asyncpg://{quote_plus(user)}:{quote_plus(password)}@postgres:5432/{db}")
host = os.environ["POSTGRES_HOST"]
port = os.environ["POSTGRES_PORT"]
user = os.environ["POSTGRES_USER"]
password = os.environ["POSTGRES_PASSWORD"]
db = os.environ["POSTGRES_DB"]
print(
f"postgresql+asyncpg://{quote_plus(user)}:{quote_plus(password)}"
f"@{host}:{port}/{db}"
)
PY
)"
echo "DB target: ${DB_USER}@${DB_HOST}:${DB_PORT}/${DB_NAME}"
echo "DNS check..."
python - <<'PY'
import os
import socket
host = os.environ.get("POSTGRES_HOST", "postgres")
try:
infos = socket.getaddrinfo(host, None)
addrs = sorted({i[4][0] for i in infos})
print(f"Resolved {host} -> {', '.join(addrs)}")
except Exception as exc: # noqa: BLE001
print(f"WARNING: cannot resolve '{host}': {exc}")
PY
echo "Waiting for database..."
python - <<'PY'
import asyncio
@@ -38,9 +69,11 @@ async def wait_db(retries: int = 60) -> None:
return
except Exception as exc: # noqa: BLE001
print(f"DB not ready ({i + 1}/{retries}): {exc}")
await asyncio.sleep(1)
await asyncio.sleep(2)
await engine.dispose()
print("ERROR: database did not become ready", file=sys.stderr)
print("HINT: both panel and postgres must be on dokploy-network", file=sys.stderr)
print("HINT: in Dokploy set POSTGRES_HOST if DB service name differs", file=sys.stderr)
sys.exit(1)