-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathrun.sh
More file actions
executable file
·180 lines (152 loc) · 5.38 KB
/
Copy pathrun.sh
File metadata and controls
executable file
·180 lines (152 loc) · 5.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
#!/bin/bash
# Graph-RCA Master Startup Script
# This script handles everything: Docker services, backend, and frontend
set -e # Exit on error
PROJECT_DIR="$(cd "$(dirname "$0")" && pwd)"
cd "$PROJECT_DIR"
echo ""
echo "╔════════════════════════════════════════════╗"
echo "║ Graph-RCA Startup Script ║"
echo "╚════════════════════════════════════════════╝"
echo ""
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# Check if Docker is running
echo -e "${BLUE}[1/6]${NC} Checking Docker..."
if ! docker info > /dev/null 2>&1; then
echo -e "${RED}❌ Docker is not running!${NC}"
echo " Please start Docker Desktop and try again."
exit 1
fi
echo -e "${GREEN}✓${NC} Docker is running"
# Clean up any existing containers first
echo ""
echo -e "${BLUE}[2/6]${NC} Cleaning up old containers..."
docker-compose down > /dev/null 2>&1 || true
# Start Docker services
echo -e "${BLUE}[3/6]${NC} Starting Docker services (MongoDB, ChromaDB, Ollama)..."
docker-compose up -d
echo -e "${GREEN}✓${NC} Docker services started"
# Check/Install Ollama model
echo ""
echo -e "${BLUE}[4/6]${NC} Checking Ollama model..."
if ! docker exec $(docker ps -qf "name=ollama") ollama list | grep -q "llama3.2:3b"; then
echo -e "${YELLOW}⚠${NC} Model llama3.2:3b not found. Installing..."
docker exec -it $(docker ps -qf "name=ollama") ollama pull llama3.2:3b
echo -e "${GREEN}✓${NC} Model installed"
else
echo -e "${GREEN}✓${NC} Model llama3.2:3b already installed"
fi
# Setup Python backend
echo ""
echo -e "${BLUE}[5/6]${NC} Setting up Python backend..."
cd backend
# Detect the best available Python (3.11, 3.12, or 3.13)
PYTHON_CMD=""
for ver in python3.13 python3.12 python3.11 python3; do
if command -v "$ver" &>/dev/null; then
PYVER=$("$ver" -c 'import sys; print("%d.%d" % sys.version_info[:2])' 2>/dev/null)
MAJOR=${PYVER%%.*}
MINOR=${PYVER##*.}
if [ "$MAJOR" -ge 3 ] && [ "$MINOR" -ge 11 ]; then
PYTHON_CMD="$ver"
break
fi
fi
done
if [ -z "$PYTHON_CMD" ]; then
echo -e "${RED}❌ Python 3.11+ not found!${NC}"
echo " Please install Python 3.11 or newer."
echo " Visit: https://www.python.org/downloads/"
exit 1
fi
echo -e "${GREEN}✓${NC} Using $("$PYTHON_CMD" --version)"
if [ ! -d "venv" ]; then
echo " Creating virtual environment with $PYTHON_CMD..."
"$PYTHON_CMD" -m venv venv
fi
# Source the venv for dependency installation
source venv/bin/activate
# Always ensure pip is up to date
pip install -q --upgrade pip
# Check if requirements need to be installed/updated
echo " Checking Python dependencies..."
pip install -q -r requirements.txt
echo -e "${GREEN}✓${NC} Python dependencies installed/verified"
# Deactivate venv
deactivate
cd ..
# Setup Node.js frontend
echo ""
echo -e "${BLUE}[6/6]${NC} Setting up Node.js frontend..."
cd frontend
if [ ! -d "node_modules" ]; then
echo " Installing Node dependencies..."
npm install --silent
echo -e "${GREEN}✓${NC} Node dependencies installed"
else
echo -e "${GREEN}✓${NC} Node dependencies already installed"
fi
cd ..
# Wait for services to be ready
echo ""
echo "Waiting for services to be ready..."
sleep 3
echo -e "${GREEN}✓${NC} All services ready"
# Print summary
echo ""
echo "╔════════════════════════════════════════════╗"
echo "║ Setup Complete! 🚀 ║"
echo "╚════════════════════════════════════════════╝"
echo ""
echo -e "${GREEN}Python Environment:${NC}"
echo " • Version: Python 3.11+ (auto-detected: $PYTHON_CMD)"
echo " • Location: backend/venv (auto-activated by start script)"
echo ""
echo -e "${GREEN}Docker Services:${NC}"
echo " • MongoDB: localhost:27017"
echo " • ChromaDB: localhost:8000"
echo " • Ollama: localhost:11435"
echo ""
echo -e "${YELLOW}To start the application:${NC}"
echo ""
echo " ${BLUE}Terminal 1${NC} - Backend API:"
echo " cd backend"
echo " source venv/bin/activate"
echo " python -m uvicorn main:app --host 0.0.0.0 --port 8010 --reload"
echo ""
echo " ${BLUE}Terminal 2${NC} - Frontend UI:"
echo " cd frontend"
echo " npm run dev"
echo ""
echo -e "${GREEN}URLs:${NC}"
echo " • Frontend: http://localhost:5173"
echo " • Backend: http://localhost:8010"
echo " • API Docs: http://localhost:8010/docs"
echo ""
echo -e "${YELLOW}Quick start (in separate terminals):${NC}"
echo " ./start-backend.sh"
echo " ./start-frontend.sh"
echo ""
# Create convenience scripts
cat > start-backend.sh << 'EOF'
#!/bin/bash
cd "$(dirname "$0")/backend"
source venv/bin/activate
echo "Starting backend on http://localhost:8010"
echo "API docs: http://localhost:8010/docs"
python -m uvicorn main:app --host 0.0.0.0 --port 8010 --reload
EOF
cat > start-frontend.sh << 'EOF'
#!/bin/bash
cd "$(dirname "$0")/frontend"
echo "Starting frontend on http://localhost:5173"
npm run dev
EOF
chmod +x start-backend.sh start-frontend.sh
echo -e "${GREEN}✓${NC} Created start-backend.sh and start-frontend.sh"
echo ""