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:
@@ -56,6 +56,7 @@ WORKERS_PID_FILE="$PID_DIR/workers-${TASK_ID}.pid"
|
||||
# Set environment variables for API
|
||||
export ASPNETCORE_ENVIRONMENT=Development
|
||||
export ASPNETCORE_URLS="http://localhost:${API_PORT}"
|
||||
export EnableSwagger=true
|
||||
export RUN_ORLEANS_GRAINS=true
|
||||
export SILO_ROLE=Trading
|
||||
export TASK_SLOT=${TASK_SLOT}
|
||||
@@ -93,8 +94,28 @@ fi
|
||||
|
||||
echo "🚀 Starting API on port $API_PORT..."
|
||||
echo "📁 Running from: $PROJECT_ROOT"
|
||||
echo "📚 Swagger enabled: true"
|
||||
cd "$PROJECT_ROOT/src/Managing.Api"
|
||||
|
||||
# Try to build first to catch build errors early
|
||||
echo "🔨 Building API project..."
|
||||
if ! dotnet build --no-incremental > "$PID_DIR/api-${TASK_ID}-build.log" 2>&1; then
|
||||
echo "❌ Build failed! Showing build errors:"
|
||||
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
|
||||
tail -n 50 "$PID_DIR/api-${TASK_ID}-build.log" 2>/dev/null || cat "$PID_DIR/api-${TASK_ID}-build.log" 2>/dev/null
|
||||
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
|
||||
echo ""
|
||||
echo "💡 Try:"
|
||||
echo " 1. Clean build: cd $PROJECT_ROOT/src/Managing.Api && dotnet clean && dotnet build"
|
||||
echo " 2. Disable parallel builds: export DOTNET_CLI_MSBUILD_PARALLEL=0"
|
||||
echo " 3. Check for compilation errors in the log above"
|
||||
exit 1
|
||||
fi
|
||||
echo "✅ Build successful"
|
||||
|
||||
# Write all output to log file (warnings will be filtered when displaying)
|
||||
# Disable parallel MSBuild nodes to avoid child node crashes
|
||||
export DOTNET_CLI_MSBUILD_PARALLEL=0
|
||||
dotnet run > "$PID_DIR/api-${TASK_ID}.log" 2>&1 &
|
||||
API_PID=$!
|
||||
echo $API_PID > "$API_PID_FILE"
|
||||
@@ -105,18 +126,39 @@ sleep 3
|
||||
|
||||
echo "🚀 Starting Workers..."
|
||||
cd "$PROJECT_ROOT/src/Managing.Workers"
|
||||
# Set workers environment variables (separate from API)
|
||||
# Write all output to log file (warnings will be filtered when displaying)
|
||||
ASPNETCORE_ENVIRONMENT=Development \
|
||||
PostgreSql__ConnectionString="Host=localhost;Port=${POSTGRES_PORT};Database=${DB_NAME};Username=postgres;Password=postgres" \
|
||||
InfluxDb__Url="http://localhost:8086/" \
|
||||
InfluxDb__Token="Fw2FPL2OwTzDHzSbR2Sd5xs0EKQYy00Q-hYKYAhr9cC1_q5YySONpxuf_Ck0PTjyUiF13xXmi__bu_pXH-H9zA==" \
|
||||
KAIGEN_SECRET_KEY="KaigenXCowchain" \
|
||||
Flagsmith__ApiKey="ser.ShJJJMtWYS9fwuzd83ejwR" \
|
||||
dotnet run > "$PID_DIR/workers-${TASK_ID}.log" 2>&1 &
|
||||
WORKERS_PID=$!
|
||||
echo $WORKERS_PID > "$WORKERS_PID_FILE"
|
||||
echo "✅ Workers started (PID: $WORKERS_PID) from worktree: $PROJECT_ROOT"
|
||||
|
||||
# Try to build first to catch build errors early
|
||||
echo "🔨 Building Workers project..."
|
||||
if ! dotnet build --no-incremental > "$PID_DIR/workers-${TASK_ID}-build.log" 2>&1; then
|
||||
echo "❌ Build failed! Showing build errors:"
|
||||
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
|
||||
tail -n 50 "$PID_DIR/workers-${TASK_ID}-build.log" 2>/dev/null || cat "$PID_DIR/workers-${TASK_ID}-build.log" 2>/dev/null
|
||||
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
|
||||
echo ""
|
||||
echo "💡 Try:"
|
||||
echo " 1. Clean build: cd $PROJECT_ROOT/src/Managing.Workers && dotnet clean && dotnet build"
|
||||
echo " 2. Disable parallel builds: export DOTNET_CLI_MSBUILD_PARALLEL=0"
|
||||
echo " 3. Check for compilation errors in the log above"
|
||||
# Don't exit - API might still be running
|
||||
echo "⚠️ Continuing without Workers..."
|
||||
else
|
||||
echo "✅ Build successful"
|
||||
|
||||
# Set workers environment variables (separate from API)
|
||||
# Write all output to log file (warnings will be filtered when displaying)
|
||||
# Disable parallel MSBuild nodes to avoid child node crashes
|
||||
export DOTNET_CLI_MSBUILD_PARALLEL=0
|
||||
ASPNETCORE_ENVIRONMENT=Development \
|
||||
PostgreSql__ConnectionString="Host=localhost;Port=${POSTGRES_PORT};Database=${DB_NAME};Username=postgres;Password=postgres" \
|
||||
InfluxDb__Url="http://localhost:8086/" \
|
||||
InfluxDb__Token="Fw2FPL2OwTzDHzSbR2Sd5xs0EKQYy00Q-hYKYAhr9cC1_q5YySONpxuf_Ck0PTjyUiF13xXmi__bu_pXH-H9zA==" \
|
||||
KAIGEN_SECRET_KEY="KaigenXCowchain" \
|
||||
Flagsmith__ApiKey="ser.ShJJJMtWYS9fwuzd83ejwR" \
|
||||
dotnet run > "$PID_DIR/workers-${TASK_ID}.log" 2>&1 &
|
||||
WORKERS_PID=$!
|
||||
echo $WORKERS_PID > "$WORKERS_PID_FILE"
|
||||
echo "✅ Workers started (PID: $WORKERS_PID) from worktree: $PROJECT_ROOT"
|
||||
fi
|
||||
|
||||
echo ""
|
||||
echo "✅ API and Workers started!"
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user