sistema-de-chamados/scripts/start-web.sh

53 lines
1.8 KiB
Bash

#!/usr/bin/env bash
set -euo pipefail
echo "[start-web] Starting web service..."
echo "[start-web] Bun: $(bun --version || true)"
cd /app
export BUN_INSTALL_CACHE_DIR="${BUN_INSTALL_CACHE_DIR:-/tmp/bun-cache}"
mkdir -p "$BUN_INSTALL_CACHE_DIR"
echo "[start-web] Using bun cache dir: $BUN_INSTALL_CACHE_DIR"
echo "[start-web] Using APP_DIR=$(pwd)"
echo "[start-web] NEXT_PUBLIC_APP_URL=${NEXT_PUBLIC_APP_URL:-}"
echo "[start-web] NEXT_PUBLIC_CONVEX_URL=${NEXT_PUBLIC_CONVEX_URL:-}"
# Ensure system deps for native modules (best-effort, idempotent)
if command -v apt-get >/dev/null 2>&1; then
if ! command -v openssl >/dev/null 2>&1; then
echo "[start-web] openssl not found; installing via apt-get (requires root)"
apt-get update -y >/dev/null 2>&1 || true
apt-get install -y openssl >/dev/null 2>&1 || true
fi
if ! command -v node >/dev/null 2>&1; then
echo "[start-web] node not found; installing via apt-get (requires root)"
apt-get update -y >/dev/null 2>&1 || true
apt-get install -y nodejs npm >/dev/null 2>&1 || true
fi
else
echo "[start-web] apt-get unavailable; skipping system deps install" >&2
fi
# Bun keeps its store in node_modules/.bun by default; ensure it exists and is writable
mkdir -p node_modules/.bun >/dev/null 2>&1 || true
# Prisma generate (idempotent) and apply DB migrations
echo "[start-web] prisma generate"
bun run prisma:generate
echo "[start-web] prisma migrate deploy"
bunx prisma migrate deploy
# Seed Better Auth users safely (ensure-only by default)
if [ "${SKIP_AUTH_SEED:-false}" != "true" ]; then
echo "[start-web] seeding Better Auth users (ensure-only)"
bun run auth:seed || true
else
echo "[start-web] skipping auth seed (SKIP_AUTH_SEED=true)"
fi
echo "[start-web] launching Next.js"
exec bun run start -- --port 3000