feat: plantilla base workspace SaaS
This commit is contained in:
50
backend/docker-entrypoint.sh
Normal file
50
backend/docker-entrypoint.sh
Normal file
@@ -0,0 +1,50 @@
|
||||
#!/bin/bash
|
||||
set -e
|
||||
|
||||
# Arranque del contenedor: espera a dependencias, luego ejecuta CMD (uvicorn, gunicorn, celery, …)
|
||||
|
||||
# Función para esperar a un puerto TCP usando Python
|
||||
wait_for_tcp() {
|
||||
local host=$1
|
||||
local port=$2
|
||||
local service=$3
|
||||
local max_attempts=30
|
||||
local attempt=1
|
||||
|
||||
echo "Esperando a que $service esté disponible en ${host}:${port}..."
|
||||
|
||||
while [ $attempt -le $max_attempts ]; do
|
||||
if python3 -c "import socket; s = socket.socket(); s.settimeout(3); s.connect(('$host', $port)); s.close()" 2>/dev/null; then
|
||||
echo "✓ $service está listo y accesible"
|
||||
return 0
|
||||
fi
|
||||
|
||||
echo "$service no está listo aún... (intento $attempt/$max_attempts)"
|
||||
attempt=$((attempt + 1))
|
||||
sleep 2
|
||||
done
|
||||
|
||||
echo "⚠ WARNING: $service no estuvo disponible después de $max_attempts intentos"
|
||||
echo " Continuando de todas formas..."
|
||||
return 0
|
||||
}
|
||||
|
||||
DB_HOST_PRIMARY="${CORE_DB_HOST:-postgres-a76}"
|
||||
DB_PORT="${CORE_DB_PORT:-5432}"
|
||||
|
||||
if ! wait_for_tcp "$DB_HOST_PRIMARY" "$DB_PORT" "PostgreSQL"; then
|
||||
# Fallback para entornos donde Docker solo registra el nombre del contenedor.
|
||||
if [[ "$DB_HOST_PRIMARY" == "postgres-a76" ]]; then
|
||||
wait_for_tcp "anexo76-postgres-a76" "$DB_PORT" "PostgreSQL" || true
|
||||
else
|
||||
echo " Continuando de todas formas..."
|
||||
fi
|
||||
fi
|
||||
|
||||
# Keycloak solo se espera si se habilita explícitamente (ej. entorno Hub completo).
|
||||
if [[ "${WAIT_FOR_KEYCLOAK:-0}" == "1" ]]; then
|
||||
wait_for_tcp "${KEYCLOAK_SERVICE_HOST:-keycloak}" "${KEYCLOAK_SERVICE_PORT:-8080}" "Keycloak" || true
|
||||
fi
|
||||
|
||||
echo "Iniciando proceso: $*"
|
||||
exec "$@"
|
||||
Reference in New Issue
Block a user