diff --git a/scripts/start-web.sh b/scripts/start-web.sh index a30d148..a8c2735 100644 --- a/scripts/start-web.sh +++ b/scripts/start-web.sh @@ -2,84 +2,32 @@ set -euo pipefail echo "[start-web] Starting web service..." -echo "[start-web] Node: $(node -v || true)" +echo "[start-web] Bun: $(bun --version || true)" cd /app -# Ensure pnpm available in this base image -ensure_pnpm() { - if command -v pnpm >/dev/null 2>&1; then - return 0 - fi +export BUN_INSTALL_CACHE_DIR="${BUN_INSTALL_CACHE_DIR:-/tmp/bun-cache}" +mkdir -p "$BUN_INSTALL_CACHE_DIR" - local runtime_home="${HOME:-}" - if [ -z "$runtime_home" ] || [ ! -d "$runtime_home" ] || [ ! -w "$runtime_home" ]; then - runtime_home="$(getent passwd "$(id -u)" | cut -d: -f6 2>/dev/null || true)" - fi - if [ -z "$runtime_home" ] || [ ! -d "$runtime_home" ] || [ ! -w "$runtime_home" ]; then - runtime_home="/tmp" - fi - - local local_bin="${runtime_home}/.local/bin" - local pnpm_prefix="${runtime_home}/.local/share/pnpm" - local corepack_home="${runtime_home}/.local/share/corepack" - - export PATH="${local_bin}:$PATH" - export COREPACK_HOME="${corepack_home}" - - mkdir -p "$local_bin" "$pnpm_prefix" "$corepack_home" >/dev/null 2>&1 || true - - if command -v pnpm >/dev/null 2>&1; then - return 0 - fi - - if command -v corepack >/dev/null 2>&1; then - corepack prepare pnpm@10.20.0 --activate >/dev/null 2>&1 || true - corepack enable --install-directory "$local_bin" pnpm >/dev/null 2>&1 || true - fi - - if command -v pnpm >/dev/null 2>&1; then - return 0 - fi - - if command -v npm >/dev/null 2>&1; then - npm install --prefix "$pnpm_prefix" pnpm@10.20.0 >/dev/null 2>&1 || true - if [ -x "${pnpm_prefix}/node_modules/.bin/pnpm" ]; then - ln -sf "${pnpm_prefix}/node_modules/.bin/pnpm" "${local_bin}/pnpm" >/dev/null 2>&1 || true - fi - fi - - if command -v pnpm >/dev/null 2>&1; then - return 0 - fi - - echo "[start-web] pnpm not available; aborting startup" >&2 - exit 1 -} - -ensure_pnpm - -echo "[start-web] pnpm version: $(pnpm -v 2>/dev/null || echo 'unavailable')" -echo "[start-web] pnpm path: $(command -v pnpm || echo 'not found')" +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:-}" -echo "[start-web] PNPM_STORE_DIR=${PNPM_STORE_DIR:-/tmp/pnpm-store}" -# Ensure pnpm uses container-local store (not host bind mount) -pnpm config set store-dir "${PNPM_STORE_DIR:-/tmp/pnpm-store}" >/dev/null 2>&1 || true +# 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" -pnpm prisma:generate +bun run prisma:generate echo "[start-web] prisma migrate deploy" -pnpm exec prisma migrate deploy +bunx prisma migrate deploy # Seed Better Auth users safely (ensure-only by default) echo "[start-web] seeding Better Auth users (ensure-only)" -pnpm auth:seed || true +bun run auth:seed || true echo "[start-web] launching Next.js" -exec pnpm start -p 3000 +exec bun run start -- --port 3000 diff --git a/stack.yml b/stack.yml index 64f9b35..7c86fb7 100644 --- a/stack.yml +++ b/stack.yml @@ -3,7 +3,7 @@ version: "3.8" services: web: - image: node:20-bullseye + image: oven/bun:1.3.1 # Run as non-root to avoid creating root-owned files on host mounts user: "1000:1000" working_dir: /app @@ -14,7 +14,7 @@ services: - sistema_db:/app/data environment: NODE_ENV: "production" - PNPM_STORE_DIR: "/tmp/pnpm-store" + BUN_INSTALL_CACHE_DIR: "/tmp/bun-cache" # Garante instalação de devDependencies para o build (prisma CLI) NPM_CONFIG_PRODUCTION: "false" # IMPORTANTE: "NEXT_PUBLIC_*" é consumida pelo navegador (cliente). Use a URL pública do Convex. @@ -35,6 +35,9 @@ services: parallelism: 1 order: start-first failure_action: rollback + resources: + limits: + memory: "2G" restart_policy: condition: any placement: @@ -78,6 +81,9 @@ services: parallelism: 1 order: start-first failure_action: rollback + resources: + limits: + memory: "4G" restart_policy: condition: any placement: