Skip to content

🪢 Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.

fix(self-hosting): respect DATABASE_PORT when composing DATABASE_URL in entrypoints (#16605)

qwerty29441172c4eae661
diff --git a/web/entrypoint.sh b/web/entrypoint.sh
index 9061847427..aaf947916d 100644
--- a/web/entrypoint.sh
+++ b/web/entrypoint.sh
@@ -61,8 +61,25 @@ check_clickhouse_password() {
if [ -z "$DATABASE_URL" ]; then
# Check if all required variables are provided
if [ -n "$DATABASE_HOST" ] && [ -n "$DATABASE_USERNAME" ] && [ -n "$DATABASE_PASSWORD" ] && [ -n "$DATABASE_NAME" ]; then
+ # Append DATABASE_PORT only when it is explicitly set, so existing
+ # deployments that embed the port in DATABASE_HOST keep working.
+ db_host_with_port="${DATABASE_HOST}"
+ if [ -n "$DATABASE_PORT" ]; then
+ case "$DATABASE_PORT" in
+ *[!0-9]*)
+ # e.g. Kubernetes service links can inject DATABASE_PORT=tcp://ip:port
+ echo "Warning: ignoring non-numeric DATABASE_PORT '${DATABASE_PORT}'"
+ ;;
+ *)
+ case "${DATABASE_HOST##*\]}" in
+ *:*) echo "Info: DATABASE_HOST already contains a port; ignoring DATABASE_PORT." ;;
+ *) db_host_with_port="${DATABASE_HOST}:${DATABASE_PORT}" ;;
+ esac
+ ;;
+ esac
+ fi
# Construct DATABASE_URL from the provided variables
- DATABASE_URL="postgresql://${DATABASE_USERNAME}:${DATABASE_PASSWORD}@${DATABASE_HOST}/${DATABASE_NAME}"
+ DATABASE_URL="postgresql://${DATABASE_USERNAME}:${DATABASE_PASSWORD}@${db_host_with_port}/${DATABASE_NAME}"
export DATABASE_URL
else
echo "Error: Required database environment variables are not set. Provide a postgres url for DATABASE_URL."
diff --git a/worker/entrypoint.sh b/worker/entrypoint.sh
index a372cfab32..6c6cbce9ff 100644
--- a/worker/entrypoint.sh
+++ b/worker/entrypoint.sh
@@ -5,8 +5,25 @@
if [ -z "$DATABASE_URL" ]; then
# Check if all required variables are provided
if [ -n "$DATABASE_HOST" ] && [ -n "$DATABASE_USERNAME" ] && [ -n "$DATABASE_PASSWORD" ] && [ -n "$DATABASE_NAME" ]; then
+ # Append DATABASE_PORT only when it is explicitly set, so existing
+ # deployments that embed the port in DATABASE_HOST keep working.
+ db_host_with_port="${DATABASE_HOST}"
+ if [ -n "$DATABASE_PORT" ]; then
+ case "$DATABASE_PORT" in
+ *[!0-9]*)
+ # e.g. Kubernetes service links can inject DATABASE_PORT=tcp://ip:port
+ echo "Warning: ignoring non-numeric DATABASE_PORT '${DATABASE_PORT}'"
+ ;;
+ *)
+ case "${DATABASE_HOST##*\]}" in
+ *:*) echo "Info: DATABASE_HOST already contains a port; ignoring DATABASE_PORT." ;;
+ *) db_host_with_port="${DATABASE_HOST}:${DATABASE_PORT}" ;;
+ esac
+ ;;
+ esac
+ fi
# Construct DATABASE_URL from the provided variables
- DATABASE_URL="postgresql://${DATABASE_USERNAME}:${DATABASE_PASSWORD}@${DATABASE_HOST}/${DATABASE_NAME}"
+ DATABASE_URL="postgresql://${DATABASE_USERNAME}:${DATABASE_PASSWORD}@${db_host_with_port}/${DATABASE_NAME}"
export DATABASE_URL
else
echo "Error: Required database environment variables are not set. Provide a postgres url for DATABASE_URL."