chore: run web service with bun runtime

This commit is contained in:
Esdras Renan 2025-11-05 19:04:09 -03:00
parent 2b9bc77228
commit aec9b1ff85
2 changed files with 18 additions and 64 deletions

View file

@ -2,84 +2,32 @@
set -euo pipefail set -euo pipefail
echo "[start-web] Starting web service..." echo "[start-web] Starting web service..."
echo "[start-web] Node: $(node -v || true)" echo "[start-web] Bun: $(bun --version || true)"
cd /app cd /app
# Ensure pnpm available in this base image export BUN_INSTALL_CACHE_DIR="${BUN_INSTALL_CACHE_DIR:-/tmp/bun-cache}"
ensure_pnpm() { mkdir -p "$BUN_INSTALL_CACHE_DIR"
if command -v pnpm >/dev/null 2>&1; then
return 0
fi
local runtime_home="${HOME:-}" echo "[start-web] Using bun cache dir: $BUN_INSTALL_CACHE_DIR"
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 APP_DIR=$(pwd)" echo "[start-web] Using APP_DIR=$(pwd)"
echo "[start-web] NEXT_PUBLIC_APP_URL=${NEXT_PUBLIC_APP_URL:-}" 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] 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) # Bun keeps its store in node_modules/.bun by default; ensure it exists and is writable
pnpm config set store-dir "${PNPM_STORE_DIR:-/tmp/pnpm-store}" >/dev/null 2>&1 || true mkdir -p node_modules/.bun >/dev/null 2>&1 || true
# Prisma generate (idempotent) and apply DB migrations # Prisma generate (idempotent) and apply DB migrations
echo "[start-web] prisma generate" echo "[start-web] prisma generate"
pnpm prisma:generate bun run prisma:generate
echo "[start-web] prisma migrate deploy" echo "[start-web] prisma migrate deploy"
pnpm exec prisma migrate deploy bunx prisma migrate deploy
# Seed Better Auth users safely (ensure-only by default) # Seed Better Auth users safely (ensure-only by default)
echo "[start-web] seeding Better Auth users (ensure-only)" echo "[start-web] seeding Better Auth users (ensure-only)"
pnpm auth:seed || true bun run auth:seed || true
echo "[start-web] launching Next.js" echo "[start-web] launching Next.js"
exec pnpm start -p 3000 exec bun run start -- --port 3000

View file

@ -3,7 +3,7 @@ version: "3.8"
services: services:
web: web:
image: node:20-bullseye image: oven/bun:1.3.1
# Run as non-root to avoid creating root-owned files on host mounts # Run as non-root to avoid creating root-owned files on host mounts
user: "1000:1000" user: "1000:1000"
working_dir: /app working_dir: /app
@ -14,7 +14,7 @@ services:
- sistema_db:/app/data - sistema_db:/app/data
environment: environment:
NODE_ENV: "production" 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) # Garante instalação de devDependencies para o build (prisma CLI)
NPM_CONFIG_PRODUCTION: "false" NPM_CONFIG_PRODUCTION: "false"
# IMPORTANTE: "NEXT_PUBLIC_*" é consumida pelo navegador (cliente). Use a URL pública do Convex. # IMPORTANTE: "NEXT_PUBLIC_*" é consumida pelo navegador (cliente). Use a URL pública do Convex.
@ -35,6 +35,9 @@ services:
parallelism: 1 parallelism: 1
order: start-first order: start-first
failure_action: rollback failure_action: rollback
resources:
limits:
memory: "2G"
restart_policy: restart_policy:
condition: any condition: any
placement: placement:
@ -78,6 +81,9 @@ services:
parallelism: 1 parallelism: 1
order: start-first order: start-first
failure_action: rollback failure_action: rollback
resources:
limits:
memory: "4G"
restart_policy: restart_policy:
condition: any condition: any
placement: placement: