Files
you-music/dev-stack.sh
T

220 lines
6.5 KiB
Bash
Executable File

#!/bin/bash
# YouMusic Development Stack - Complete Setup & Start
# Handles: dependency checks, installation, migrations, and server startup
set -e
echo "🚀 YouMusic - Starting Development Stack"
echo "========================================="
echo ""
# Colors
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# ============================================================================
# 1. Check System Dependencies
# ============================================================================
echo "🔍 Checking system dependencies..."
# Check Python 3.13
if ! command -v python3.13 &> /dev/null; then
echo -e "${RED}❌ Python 3.13 is required but not installed${NC}"
echo "Install: brew install python@3.13 (macOS) or apt-get install python3.13 (Linux)"
exit 1
fi
echo -e "${GREEN}✅ Python 3.13 found${NC}"
# Check uv
if ! command -v uv &> /dev/null; then
echo -e "${YELLOW}⚠️ uv not found, installing...${NC}"
curl -LsSf https://astral.sh/uv/install.sh | sh
export PATH="$HOME/.cargo/bin:$PATH"
if ! command -v uv &> /dev/null; then
echo -e "${RED}❌ Failed to install uv${NC}"
exit 1
fi
fi
echo -e "${GREEN}✅ uv found${NC}"
# Check Node.js
if ! command -v node &> /dev/null; then
echo -e "${RED}❌ Node.js is required but not installed${NC}"
echo "Please install Node.js 18 or higher"
exit 1
fi
echo -e "${GREEN}✅ Node.js found${NC}"
# Check FFmpeg
if ! command -v ffmpeg &> /dev/null; then
echo -e "${YELLOW}⚠️ FFmpeg not found${NC}"
echo "FFmpeg is required for audio processing"
echo "Install: brew install ffmpeg (macOS) or apt-get install ffmpeg (Linux)"
read -p "Continue anyway? (y/n) " -n 1 -r
echo
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
exit 1
fi
else
echo -e "${GREEN}✅ FFmpeg found${NC}"
fi
echo ""
# ============================================================================
# 2. Setup Project Directories
# ============================================================================
echo "📁 Setting up project directories..."
mkdir -p data/music data/uploads data/temp logs
echo -e "${GREEN}✅ Directories ready${NC}"
echo ""
# ============================================================================
# 3. Backend Setup
# ============================================================================
echo "🔧 Setting up Backend..."
# Create virtual environment if needed
if [ ! -d "backend/.venv" ]; then
echo "Creating Python 3.13 virtual environment..."
cd backend
uv venv --python 3.13
cd ..
fi
# Install/update Python dependencies
echo "Installing Python dependencies with uv..."
uv sync
cd ..
# Create backend .env if needed
if [ ! -f "backend/.env" ]; then
echo "Creating backend .env file..."
cp backend/.env.example backend/.env 2>/dev/null || echo "Warning: .env.example not found"
fi
echo -e "${GREEN}✅ Backend setup complete${NC}"
echo ""
# ============================================================================
# 4. Frontend Setup
# ============================================================================
echo "🎨 Setting up Frontend..."
# Install/update npm dependencies
if [ ! -d "frontend/node_modules" ] || [ ! -f "frontend/node_modules/.bin/vite" ]; then
echo "Installing npm dependencies..."
cd frontend
NODE_ENV= npm install --include=dev
cd ..
else
echo "npm dependencies already installed"
fi
# Create frontend .env if needed
if [ ! -f "frontend/.env" ]; then
echo "Creating frontend .env file..."
cp frontend/.env.example frontend/.env 2>/dev/null || echo "Warning: .env.example not found"
fi
echo -e "${GREEN}✅ Frontend setup complete${NC}"
echo ""
# ============================================================================
# 5. Run Database Migrations
# ============================================================================
echo "🔄 Running database migrations..."
cd backend
source .venv/bin/activate
if [ -d "alembic" ]; then
alembic upgrade head
echo -e "${GREEN}✅ Database migrations complete${NC}"
else
echo -e "${YELLOW}⚠️ No alembic directory found, skipping migrations${NC}"
fi
cd ..
echo ""
# ============================================================================
# 6. Start Development Servers
# ============================================================================
echo "🚀 Starting development servers..."
echo ""
# Clean up overmind socket if it exists
rm -f .overmind.sock
# Check for process managers (in order of preference)
if command -v overmind &> /dev/null; then
echo -e "${GREEN}✅ Using overmind (best option)${NC}"
echo ""
echo -e "${BLUE}Shortcuts:${NC}"
echo " Ctrl+C - Stop all"
echo " overmind c - Connect to services (in another terminal)"
echo " overmind r - Restart a service"
echo ""
echo "Starting services..."
exec overmind start -f Procfile.dev
elif command -v hivemind &> /dev/null; then
echo -e "${GREEN}✅ Using hivemind${NC}"
echo ""
echo "Starting services..."
exec hivemind Procfile.dev
elif command -v foreman &> /dev/null; then
echo -e "${GREEN}✅ Using foreman${NC}"
echo ""
echo "Starting services..."
exec foreman start -f Procfile.dev
elif command -v nf &> /dev/null; then
echo -e "${GREEN}✅ Using node-foreman${NC}"
echo ""
echo "Starting services..."
exec nf start -j Procfile.dev
else
echo -e "${YELLOW}⚠️ No process manager found. Running in foreground mode...${NC}"
echo ""
echo -e "${BLUE}Press Ctrl+C to stop all services${NC}"
echo ""
# Cleanup function
cleanup() {
echo ""
echo -e "${YELLOW}Stopping services...${NC}"
kill $BACKEND_PID $FRONTEND_PID 2>/dev/null
wait $BACKEND_PID $FRONTEND_PID 2>/dev/null
echo -e "${GREEN}✅ All services stopped${NC}"
exit 0
}
trap cleanup SIGINT SIGTERM
# Start backend in background with output to console
cd backend
source .venv/bin/activate
uv run uvicorn main:app --reload --host 0.0.0.0 --port 8000 2>&1 | sed 's/^/backend | /' &
BACKEND_PID=$!
cd ..
# Start frontend in background with output to console
cd frontend
npm run dev 2>&1 | sed 's/^/frontend | /' &
FRONTEND_PID=$!
cd ..
echo -e "${GREEN}✅ Services started${NC}"
echo ""
echo "Frontend: http://localhost:3000"
echo "Backend: http://localhost:8000"
echo "API Docs: http://localhost:8000/docs"
echo ""
# Wait for both processes
wait
fi