Detect external DB/Redis via flags; sanitize URLs

Improve entrypoint handling for external services and startup wrappers. entrypoint.sh now more robustly parses REDIS_URL (handles optional :password@host) and masks credentials when printing DATABASE_URL/REDIS_URL. It exports USE_EXTERNAL_POSTGRES and USE_EXTERNAL_REDIS so supervisor wrappers can decide behavior without re-parsing URLs. The temporary PostgreSQL shutdown was moved to after Prisma migrations and a warning was added when pushing schema to an external DB. postgres-start.sh and redis-start.sh were simplified to check the USE_EXTERNAL_* flags and sleep if an external service is configured. Also cleaned up formatting of the PostgreSQL ownership error message.
This commit is contained in:
kikootwo
2026-02-12 15:59:09 -05:00
parent a145dc9877
commit 6f0d71ee9b
3 changed files with 58 additions and 78 deletions
+5 -21
View File
@@ -1,10 +1,7 @@
#!/bin/bash
# Redis startup wrapper for unified container
# Smart supervisor: detects external Redis and sleeps instead of starting local instance
#
# Behavior:
# - If REDIS_URL points to external host (not 127.0.0.1/localhost), sleep infinity
# - Otherwise, start local Redis instance
# Checks USE_EXTERNAL_REDIS flag (set by entrypoint) to decide whether
# to start the local instance or sleep to keep supervisord happy.
#
# Uses gosu to ensure correct PUID:PGID for file operations
#
@@ -21,22 +18,9 @@ if [ -f /etc/environment ]; then
set +a
fi
echo "[Redis] Checking for external Redis configuration..."
# Extract host from REDIS_URL
# Format: redis://host:port or redis://:password@host:port
if [ -n "$REDIS_URL" ]; then
# Extract the host part (between :// or @, and :port or end)
REDIS_HOST=$(echo "$REDIS_URL" | sed -n 's|redis://\([^:@]*@\)\?\([^:/]*\).*|\2|p')
echo "[Redis] Detected REDIS_URL host: $REDIS_HOST"
# Check if host is external (not localhost or 127.0.0.1)
if [ "$REDIS_HOST" != "127.0.0.1" ] && [ "$REDIS_HOST" != "localhost" ]; then
echo "[Redis] ✅ External Redis detected at $REDIS_HOST"
echo "[Redis] Skipping local Redis startup - sleeping to keep supervisord happy"
exec sleep infinity
fi
if [ "$USE_EXTERNAL_REDIS" = "true" ]; then
echo "[Redis] External Redis configured - skipping local instance"
exec sleep infinity
fi
echo "[Redis] Starting local Redis server..."