Files
plantillas-proyectos/frontend/docker-entrypoint.sh
Kevin_Ramirez bdd089954b
Some checks failed
Build Producción & Push a Harbor / test (push) Failing after 3s
Build Producción & Push a Harbor / build (push) Has been skipped
Aduanasoft/plantillas-proyectos/pipeline/head There was a failure building this commit
feat: plantilla base workspace SaaS
2026-07-21 13:59:00 -05:00

45 lines
1.4 KiB
Bash

#!/bin/sh
set -e
# Arranque del contenedor: opcionalmente espera al health del backend, luego ejecuta CMD (pnpm dev / start, …)
wait_for_backend() {
local url=$1
local max_attempts=30
local attempt=1
echo "Esperando a que el backend esté disponible en ${url}..."
while [ $attempt -le $max_attempts ]; do
# NOTA: usar la URL tal cual la pasa el caller. Antes esta función agregaba
# un "/health" extra al final (resultando en /api/health/health → 404), lo
# que provocaba que el entrypoint esperara 30 intentos en vano antes de
# arrancar Vite, sumando ~90 s muertos al arranque del frontend.
if wget -q -O /dev/null "${url}" 2>/dev/null; then
echo "✓ Backend está listo"
return 0
fi
echo "Backend no está listo aún... (intento $attempt/$max_attempts)"
attempt=$((attempt + 1))
sleep 3
done
echo "⚠ WARNING: Backend no estuvo disponible, continuando de todas formas"
return 0
}
# compose usa INTERNAL_API_URL; alias opcional BACKEND_INTERNAL_URL
_api_base="${INTERNAL_API_URL:-${BACKEND_INTERNAL_URL:-http://backend:8000/api}}"
_api_base="${_api_base%/}"
wait_for_backend "${_api_base}/health"
# En desarrollo (volumen montado) reinstala deps si cambia package.json
if [ "$NODE_ENV" = "development" ]; then
echo "Instalando dependencias (development)..."
CI=true pnpm install
fi
echo "Iniciando: $*"
exec "$@"