fix(prod): production startup fixes — health endpoint, serveStatic path, entrypoint, docker config

- Add /api/health endpoint for Docker healthchecks
- Fix serveStatic path: dist/public instead of ../public
- Fix entrypoint.sh: DB wait check, npx drizzle-kit migrate, add netcat
- Fix Dockerfile: add bash/netcat, fix COPY order, add tsconfig.node.json
- Fix docker-compose.yml: add OLLAMA/LLM env vars for Node.js fallback
- Fix docker-stack.yml: remove template vars, use env vars instead of secrets
- Fix drizzle.config.ts: add migrations prefix
- Update .env.example with full LLM provider documentation
This commit is contained in:
¨NW¨
2026-04-08 23:09:28 +01:00
parent cee297b4db
commit 322cebf475
8 changed files with 119 additions and 67 deletions

View File

@@ -1,18 +1,48 @@
#!/bin/sh
# GoClaw Control Center entrypoint
# Runs Drizzle migrations before starting the server
# Runs database migrations before starting the server
set -e
echo "[Entrypoint] Running database migrations..."
echo "[Entrypoint] Waiting for database connectivity..."
# Wait for database to be reachable (max 30 attempts = 60 seconds)
DB_READY=false
ATTEMPT=0
MAX_ATTEMPTS=30
# Parse DATABASE_URL for connection check
# Supports: mysql://user:pass@host:port/dbname
if [ -n "$DATABASE_URL" ]; then
# Extract host and port from DATABASE_URL
DB_HOST=$(echo "$DATABASE_URL" | sed -E 's|.*@([^:/]+)(:[0-9]+)?/.*|\1|')
DB_PORT=$(echo "$DATABASE_URL" | sed -E 's|.*@[^:/]+:([0-9]+)/.*|\1|')
if [ -z "$DB_PORT" ]; then DB_PORT=3306; fi
while [ $ATTEMPT -lt $MAX_ATTEMPTS ]; do
ATTEMPT=$((ATTEMPT + 1))
if nc -z "$DB_HOST" "$DB_PORT" 2>/dev/null || timeout 2 sh -c "echo > /dev/tcp/$DB_HOST/$DB_PORT" 2>/dev/null; then
DB_READY=true
echo "[Entrypoint] Database is reachable (attempt $ATTEMPT/$MAX_ATTEMPTS)"
break
fi
echo "[Entrypoint] Waiting for database at $DB_HOST:$DB_PORT... (attempt $ATTEMPT/$MAX_ATTEMPTS)"
sleep 2
done
fi
if [ "$DB_READY" = "false" ] && [ -n "$DATABASE_URL" ]; then
echo "[Entrypoint] WARNING: Database not reachable after $MAX_ATTEMPTS attempts. Continuing anyway..."
fi
echo "[Entrypoint] Running database migrations (via drizzle-kit)..."
# Run drizzle-kit migrate — applies all pending migrations idempotently
# drizzle.config.ts and drizzle/migrations/ are copied into /app during build
cd /app && node_modules/.bin/drizzle-kit migrate 2>&1
cd /app && npx drizzle-kit migrate 2>&1
MIGRATE_EXIT=$?
if [ $MIGRATE_EXIT -ne 0 ]; then
echo "[Entrypoint] WARNING: Migration failed (exit $MIGRATE_EXIT). Starting server anyway..."
echo "[Entrypoint] WARNING: Migration failed (exit $MIGRATE_EXIT). Starting server anyway — seed will handle schema..."
else
echo "[Entrypoint] Migrations applied successfully."
fi