Enhance start-api-and-workers.sh and vibe-dev-server.sh scripts

- Added support for Swagger in the API by setting EnableSwagger environment variable.
- Implemented build error handling for both API and Workers, providing detailed feedback and suggestions for resolution.
- Updated vibe-dev-server.sh to start the API and Workers using Aspire, including improved logging and dashboard URL extraction.
- Enhanced waiting mechanisms for API readiness and Aspire dashboard availability, ensuring smoother startup experience.
This commit is contained in:
2025-12-31 05:23:07 +07:00
parent ab08e0241b
commit cef86a5025
9 changed files with 357 additions and 135 deletions

View File

@@ -1,6 +1,6 @@
#!/bin/bash
# scripts/vibe-kanban/vibe-dev-server.sh
# Simplified script for Vibe Kanban - starts API and Workers only
# Simplified script for Vibe Kanban - starts API and Workers using Aspire
# Assumes database setup is already done by vibe-setup.sh
# Detect worktree root
@@ -89,21 +89,22 @@ MAIN_REPO_PATHS=(
MAIN_REPO=""
for path in "${MAIN_REPO_PATHS[@]}"; do
if [ -n "$path" ] && [ -d "$path" ] && [ -d "$path/scripts" ] && [ -f "$path/scripts/start-api-and-workers.sh" ]; then
if [ -n "$path" ] && [ -d "$path" ] && [ -d "$path/src/Managing.AppHost" ]; then
MAIN_REPO="$path"
break
fi
done
if [ -z "$MAIN_REPO" ]; then
echo "❌ Cannot find main repository with scripts"
echo "❌ Cannot find main repository with Aspire AppHost"
exit 1
fi
echo "📁 Main repository: $MAIN_REPO"
echo "🚀 Starting API and Workers..."
echo "🚀 Starting API and Workers using Aspire..."
echo " Task ID: $TASK_ID"
echo " Port offset: $PORT_OFFSET"
echo " Task Slot: $TASK_SLOT"
# Verify database is ready
if [ -n "$POSTGRES_PORT" ]; then
@@ -116,93 +117,163 @@ if [ -n "$POSTGRES_PORT" ]; then
echo "✅ Database is ready"
fi
# Export worktree path so main repo scripts know where to run dotnet from
export VIBE_WORKTREE_ROOT="$WORKTREE_PROJECT_ROOT"
# Ensure API_PORT is set (should be from config, but fallback if needed)
if [ -z "$API_PORT" ]; then
API_PORT=$((5000 + PORT_OFFSET))
fi
# Start API and Workers only (database setup is already done)
bash "$MAIN_REPO/scripts/start-api-and-workers.sh" "$TASK_ID" "$PORT_OFFSET"
# Set environment variables for Aspire
export TASK_ID="$TASK_ID"
export PORT_OFFSET="$PORT_OFFSET"
export TASK_SLOT="$TASK_SLOT"
# Determine log file paths (logs are created in the worktree root)
PID_DIR="$WORKTREE_PROJECT_ROOT/.task-pids"
API_LOG="$PID_DIR/api-${TASK_ID}.log"
WORKERS_LOG="$PID_DIR/workers-${TASK_ID}.log"
# Change to AppHost directory
cd "$MAIN_REPO/src/Managing.AppHost"
# Wait for log files to be created
# Run Aspire (this will start the API and Workers)
echo ""
echo "⏳ Waiting for services to start and log files to be created..."
for i in {1..30}; do
if [ -f "$API_LOG" ] && [ -f "$WORKERS_LOG" ]; then
echo "✅ Log files found"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo "🚀 Starting Aspire..."
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo ""
# Run Aspire in the background and capture output
ASPIRE_LOG="$WORKTREE_PROJECT_ROOT/.task-pids/aspire-${TASK_ID}.log"
mkdir -p "$(dirname "$ASPIRE_LOG")"
# Start Aspire
dotnet run > "$ASPIRE_LOG" 2>&1 &
ASPIRE_PID=$!
# Save PID
echo $ASPIRE_PID > "$WORKTREE_PROJECT_ROOT/.task-pids/aspire-${TASK_ID}.pid"
echo "✅ Aspire started (PID: $ASPIRE_PID)"
echo "📋 Log: $ASPIRE_LOG"
echo ""
echo "⏳ Aspire is starting (this may take 30-60 seconds on first run)..."
echo " Building projects and starting services..."
# Wait a bit for Aspire to start writing to the log
sleep 3
# Try to extract the dashboard URL from the log (Aspire prints it when it starts)
ASPIRE_DASHBOARD_URL=""
ASPIRE_DASHBOARD_PORT=""
# Common Aspire dashboard ports to try
POSSIBLE_PORTS=(15242 15000 15888 17247)
echo ""
echo "⏳ Waiting for Aspire dashboard to be ready..."
for i in {1..120}; do
# Try to extract dashboard URL from log
if [ -f "$ASPIRE_LOG" ]; then
# Look for "Now listening on: http://localhost:PORT" or similar patterns
DASHBOARD_LINE=$(grep -i "listening\|dashboard\|http://localhost" "$ASPIRE_LOG" 2>/dev/null | tail -1)
if [ -n "$DASHBOARD_LINE" ]; then
# Extract port from the line
EXTRACTED_PORT=$(echo "$DASHBOARD_LINE" | grep -oE 'localhost:[0-9]+' | head -1 | cut -d: -f2)
if [ -n "$EXTRACTED_PORT" ]; then
ASPIRE_DASHBOARD_PORT="$EXTRACTED_PORT"
ASPIRE_DASHBOARD_URL="http://localhost:${ASPIRE_DASHBOARD_PORT}"
fi
fi
fi
# If we don't have a URL yet, try common ports
if [ -z "$ASPIRE_DASHBOARD_URL" ]; then
for port in "${POSSIBLE_PORTS[@]}"; do
if curl -s -f "http://localhost:${port}" > /dev/null 2>&1; then
ASPIRE_DASHBOARD_PORT="$port"
ASPIRE_DASHBOARD_URL="http://localhost:${port}"
break
fi
done
fi
# If we found the dashboard, break
if [ -n "$ASPIRE_DASHBOARD_URL" ] && curl -s -f "$ASPIRE_DASHBOARD_URL" > /dev/null 2>&1; then
echo "✅ Aspire dashboard is ready at $ASPIRE_DASHBOARD_URL!"
break
fi
if [ $i -eq 30 ]; then
echo "⚠️ Log files not found after 30 seconds"
echo " API log: $API_LOG"
echo " Workers log: $WORKERS_LOG"
echo " Continuing anyway..."
# Show progress every 10 seconds
if [ $((i % 10)) -eq 0 ]; then
echo " Still starting... (${i}/120 seconds)"
# Show last few lines of log for progress
if [ -f "$ASPIRE_LOG" ]; then
LAST_LINE=$(tail -1 "$ASPIRE_LOG" 2>/dev/null | cut -c1-80)
if [ -n "$LAST_LINE" ]; then
echo " Latest: $LAST_LINE"
fi
fi
fi
if [ $i -eq 120 ]; then
echo "⚠️ Aspire dashboard did not become ready after 120 seconds"
echo "💡 Check the log: $ASPIRE_LOG"
echo "💡 Last 10 lines of log:"
tail -10 "$ASPIRE_LOG" 2>/dev/null || echo " (log file not found)"
# Try to use default port anyway
if [ -z "$ASPIRE_DASHBOARD_URL" ]; then
ASPIRE_DASHBOARD_PORT=15242
ASPIRE_DASHBOARD_URL="http://localhost:15242"
echo "💡 Using default port: $ASPIRE_DASHBOARD_URL"
fi
fi
sleep 1
done
# Show logs with labels
# Wait for API to be ready (give it more time since Aspire needs to build first)
echo ""
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo "📋 Showing API and Workers logs (Press Ctrl+C to stop)"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo ""
# Check if log files exist
if [ ! -f "$API_LOG" ] && [ ! -f "$WORKERS_LOG" ]; then
echo "❌ No log files found"
echo " API log: $API_LOG"
echo " Workers log: $WORKERS_LOG"
echo "💡 Services may still be starting. You can manually view logs with:"
echo " tail -f $API_LOG"
echo " tail -f $WORKERS_LOG"
exit 1
fi
# Use multitail if available for better viewing, otherwise use simple tail
if command -v multitail >/dev/null 2>&1; then
echo "📋 Using multitail for split-screen log viewing..."
if [ -f "$API_LOG" ] && [ -f "$WORKERS_LOG" ]; then
multitail -s 2 \
-ci green -T "API" "$API_LOG" \
-ci yellow -T "Workers" "$WORKERS_LOG"
elif [ -f "$API_LOG" ]; then
tail -f "$API_LOG"
elif [ -f "$WORKERS_LOG" ]; then
tail -f "$WORKERS_LOG"
echo "⏳ Waiting for API to be ready..."
API_READY=false
for i in {1..90}; do
if curl -s -f "http://localhost:${API_PORT}/alive" > /dev/null 2>&1; then
API_READY=true
echo "✅ API is ready!"
break
fi
# Show progress every 15 seconds
if [ $((i % 15)) -eq 0 ]; then
echo " Still waiting for API... (${i}/90 seconds)"
fi
if [ $i -eq 90 ]; then
echo "⚠️ API did not become ready after 90 seconds"
echo "💡 Check the log: $ASPIRE_LOG"
echo "💡 The API may still be building or starting"
fi
sleep 1
done
# Print the Aspire dashboard URL in the format Vibe Kanban expects
# This must be printed so Vibe Kanban can detect the server is running
echo ""
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
if [ "$API_READY" = true ]; then
echo "✅ Dev server is running"
else
# Simple approach: tail both files with prefixes
# Use a subshell to manage background processes
(
# Start tailing API logs in background (filter out NuGet build warnings)
if [ -f "$API_LOG" ]; then
tail -f "$API_LOG" 2>/dev/null | grep -vE "(warning NU|\.csproj : warning)" | while IFS= read -r line; do
echo "[API] $line"
done &
TAIL_API_PID=$!
fi
# Start tailing Workers logs in background (filter out NuGet build warnings)
if [ -f "$WORKERS_LOG" ]; then
tail -f "$WORKERS_LOG" 2>/dev/null | grep -vE "(warning NU|\.csproj : warning)" | while IFS= read -r line; do
echo "[WORKERS] $line"
done &
TAIL_WORKERS_PID=$!
fi
# Clean up background processes on exit
cleanup() {
[ -n "$TAIL_API_PID" ] && kill "$TAIL_API_PID" 2>/dev/null
[ -n "$TAIL_WORKERS_PID" ] && kill "$TAIL_WORKERS_PID" 2>/dev/null
exit
}
trap cleanup INT TERM EXIT
# Wait for background processes
wait
)
echo "⚠️ Dev server started (API may still be initializing)"
fi
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo "$ASPIRE_DASHBOARD_URL"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo ""
echo "📊 Additional URLs:"
echo " API: http://localhost:${API_PORT}"
echo " Swagger UI: http://localhost:${API_PORT}/swagger"
echo " Health check: http://localhost:${API_PORT}/alive"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo ""
# Tail the Aspire log
echo "📋 Showing Aspire logs (Press Ctrl+C to stop)"
echo ""
tail -f "$ASPIRE_LOG" 2>/dev/null || {
echo "❌ Cannot read Aspire log: $ASPIRE_LOG"
echo "💡 Aspire may still be starting. Check the log manually."
exit 1
}