diff --git a/docker/entrypoint.sh b/docker/entrypoint.sh index 44d4ba3..60e7bb7 100644 --- a/docker/entrypoint.sh +++ b/docker/entrypoint.sh @@ -1,50 +1,19 @@ #!/bin/sh # GoClaw Control Center entrypoint -# Runs database migrations before starting the server +# Starts the Node.js server — migrations handled by drizzle-kit push or seed set -e -echo "[Entrypoint] Waiting for database connectivity..." +echo "[Entrypoint] GoClaw Control Center starting..." -# 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 -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 — seed will handle schema..." +# Run drizzle-kit migrate if available (non-fatal — tables may already exist) +if command -v npx >/dev/null 2>&1; then + echo "[Entrypoint] Running database migrations..." + cd /app && npx drizzle-kit migrate 2>&1 || { + echo "[Entrypoint] Migration failed or not needed — continuing startup" + } else - echo "[Entrypoint] Migrations applied successfully." + echo "[Entrypoint] npx not available — skipping migrations" fi echo "[Entrypoint] Starting server..."