-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlaunch.sh
More file actions
executable file
Β·497 lines (428 loc) Β· 15.6 KB
/
launch.sh
File metadata and controls
executable file
Β·497 lines (428 loc) Β· 15.6 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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
#!/bin/bash
# Hackd Complete Launch & Test Script
# One command to rule them all - setup, validate, start, and test everything
set -e
# Check if running interactively
INTERACTIVE="false"
if [ -t 0 ]; then
INTERACTIVE="true"
fi
# Colors
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
PURPLE='\033[0;35m'
CYAN='\033[0;36m'
NC='\033[0m'
# Global variables
SETUP_NEEDED=false
MISSING_APIS=()
BACKEND_PID=""
FRONTEND_PID=""
log_info() { echo -e "${BLUE}[INFO]${NC} $1"; }
log_success() { echo -e "${GREEN}[SUCCESS]${NC} $1"; }
log_warning() { echo -e "${YELLOW}[WARNING]${NC} $1"; }
log_error() { echo -e "${RED}[ERROR]${NC} $1"; }
log_header() { echo -e "\n${PURPLE}π $1${NC}\n"; }
log_step() { echo -e "${CYAN}βΆ $1${NC}"; }
# Cleanup function
cleanup() {
log_warning "Shutting down services..."
if [ ! -z "$BACKEND_PID" ]; then
kill $BACKEND_PID 2>/dev/null || true
log_info "Backend stopped"
fi
if [ ! -z "$FRONTEND_PID" ]; then
kill $FRONTEND_PID 2>/dev/null || true
log_info "Frontend stopped"
fi
exit 0
}
trap cleanup SIGINT SIGTERM EXIT
# Global Python command variable
PYTHON_CMD=""
# Find compatible Python version
find_python() {
local python_candidates=(
"python3.13"
"python3.12"
"python3.11"
"/opt/homebrew/bin/python3.13"
"/opt/homebrew/bin/python3.12"
"/opt/homebrew/bin/python3.11"
"/usr/local/bin/python3.13"
"/usr/local/bin/python3.12"
"/usr/local/bin/python3.11"
"python3"
)
for cmd in "${python_candidates[@]}"; do
if command -v "$cmd" >/dev/null 2>&1; then
if $cmd -c "import sys; exit(0 if sys.version_info >= (3, 11) else 1)" 2>/dev/null; then
PYTHON_CMD="$cmd"
return 0
fi
fi
done
return 1
}
# System requirements check
check_system_requirements() {
log_header "SYSTEM REQUIREMENTS CHECK"
local all_good=true
# Find and check Python 3.11+
if find_python; then
local python_version=$($PYTHON_CMD --version | cut -d " " -f 2)
log_success "Python $python_version β (using $PYTHON_CMD)"
else
log_error "Need Python 3.11+ but found incompatible versions"
echo " Available Python versions:"
for cmd in python3 python3.9 python3.10 python3.11 python3.12 python3.13; do
if command -v "$cmd" >/dev/null 2>&1; then
local ver=$($cmd --version 2>/dev/null | cut -d " " -f 2)
echo " $cmd: $ver"
fi
done
echo " Install Python 3.11+: https://www.python.org/downloads/"
all_good=false
fi
# Check Node.js 18+
if command -v node >/dev/null 2>&1; then
local node_version=$(node --version | sed 's/v//')
if node -e "process.exit(parseInt(process.version.slice(1)) >= 18 ? 0 : 1)" 2>/dev/null; then
log_success "Node.js $node_version β"
else
log_error "Need Node.js 18+, found $node_version"
echo " Install: https://nodejs.org/"
all_good=false
fi
else
log_error "Node.js not found"
echo " Install: https://nodejs.org/"
all_good=false
fi
# Check/install pnpm
if ! command -v pnpm >/dev/null 2>&1; then
log_warning "pnpm not found, installing..."
npm install -g pnpm
log_success "pnpm installed β"
else
log_success "pnpm $(pnpm --version) β"
fi
if [ "$all_good" = false ]; then
log_error "β System requirements not met. Please install missing components."
exit 1
fi
log_success "π All system requirements met!"
}
# Environment setup
setup_environment() {
log_header "ENVIRONMENT SETUP"
# Backend setup
log_step "Setting up backend environment..."
cd backend
# Check if virtual environment exists and is working
if [ -d "venv" ] && [ -f "venv/setup_complete" ]; then
log_info "Virtual environment exists, checking if it's working..."
source venv/bin/activate
# Quick test to see if dependencies are installed
if python -c "import flask, cohere, github" 2>/dev/null; then
log_success "β
Virtual environment is ready! Skipping setup."
else
log_warning "Dependencies missing, reinstalling..."
pip install --upgrade pip
pip install -r requirements.txt
touch venv/setup_complete
fi
else
log_info "Setting up fresh virtual environment with $PYTHON_CMD..."
# Remove old venv if it exists but is incomplete
[ -d "venv" ] && rm -rf venv
$PYTHON_CMD -m venv venv
source venv/bin/activate
log_info "Installing Python dependencies..."
pip install --upgrade pip
pip install -r requirements.txt
touch venv/setup_complete
fi
# Create logs directory
mkdir -p logs
# Create .env if missing
if [ ! -f ".env" ]; then
log_warning "Creating backend .env file..."
cat > .env << 'EOF'
FLASK_ENV=development
FLASK_DEBUG=true
FLASK_APP=api/main.py
PORT=5000
HOST=0.0.0.0
LOG_LEVEL=DEBUG
# REQUIRED API KEYS - PLEASE SET THESE
GITHUB_TOKEN=your_github_personal_access_token_here
COHERE_API_KEY=your_cohere_api_key_here
EOF
fi
cd ..
# Frontend setup
log_step "Setting up frontend environment..."
cd frontend/hackd-web
if [ ! -f "node_modules/.setup_complete" ] || [ ! -d "node_modules" ]; then
log_info "Installing frontend dependencies..."
pnpm install
mkdir -p node_modules && touch node_modules/.setup_complete
else
log_success "β
Frontend dependencies ready! Skipping npm install."
fi
# Create .env.local if missing
if [ ! -f ".env.local" ]; then
log_warning "Creating frontend .env.local file..."
cat > .env.local << 'EOF'
# REQUIRED CONVEX CONFIGURATION
CONVEX_DEPLOYMENT=your_convex_deployment_url_here
NEXT_PUBLIC_CONVEX_URL=your_convex_public_url_here
# API Configuration
NEXT_PUBLIC_API_BASE_URL=http://localhost:5000
# Development
NEXT_PUBLIC_APP_ENV=development
EOF
fi
cd ../..
log_success "Environment setup complete!"
}
# API Keys validation
validate_api_keys() {
log_header "API KEYS VALIDATION"
local backend_env="backend/.env"
local frontend_env="frontend/hackd-web/.env.local"
# Check backend API keys
if [ -f "$backend_env" ]; then
source $backend_env
if [ "$GITHUB_TOKEN" = "your_github_personal_access_token_here" ] || [ -z "$GITHUB_TOKEN" ]; then
MISSING_APIS+=("GITHUB_TOKEN")
log_warning "β GITHUB_TOKEN not configured (value: '${GITHUB_TOKEN:-<empty>}')"
else
log_success "β GitHub token configured"
fi
if [ "$COHERE_API_KEY" = "your_cohere_api_key_here" ] || [ -z "$COHERE_API_KEY" ]; then
MISSING_APIS+=("COHERE_API_KEY")
log_warning "β COHERE_API_KEY not configured (value: '${COHERE_API_KEY:-<empty>}')"
else
log_success "β Cohere API key configured"
fi
fi
# Check frontend config
if [ -f "$frontend_env" ]; then
local convex_deployment=$(grep "CONVEX_DEPLOYMENT=" $frontend_env | cut -d= -f2)
if [ "$convex_deployment" = "your_convex_deployment_url_here" ] || [ -z "$convex_deployment" ]; then
MISSING_APIS+=("CONVEX_DEPLOYMENT")
else
log_success "Convex deployment configured β"
fi
fi
if [ ${#MISSING_APIS[@]} -gt 0 ]; then
log_warning "β οΈ Missing API configurations detected"
show_api_setup_guide
else
log_success "π All API keys configured!"
fi
}
# API setup guide
show_api_setup_guide() {
echo -e "\n${YELLOW}π API SETUP GUIDE${NC}"
echo -e "${YELLOW}==================${NC}\n"
for api in "${MISSING_APIS[@]}"; do
case $api in
"GITHUB_TOKEN")
echo -e "${CYAN}π§ GITHUB_TOKEN Setup:${NC}"
echo " 1. Go to: https://github.com/settings/tokens"
echo " 2. Click 'Generate new token (classic)'"
echo " 3. Give it a name like 'Hackd Development'"
echo " 4. Select scope: 'public_repo'"
echo " 5. Copy the token"
echo " 6. Edit backend/.env and replace:"
echo " GITHUB_TOKEN=your_github_personal_access_token_here"
echo " with:"
echo " GITHUB_TOKEN=ghp_your_actual_token_here"
echo ""
;;
"COHERE_API_KEY")
echo -e "${CYAN}π€ COHERE_API_KEY Setup:${NC}"
echo " 1. Go to: https://cohere.ai/"
echo " 2. Sign up for a free account"
echo " 3. Go to your dashboard"
echo " 4. Copy your API key"
echo " 5. Edit backend/.env and replace:"
echo " COHERE_API_KEY=your_cohere_api_key_here"
echo " with:"
echo " COHERE_API_KEY=your_actual_cohere_key_here"
echo ""
;;
"CONVEX_DEPLOYMENT")
echo -e "${CYAN}ποΈ CONVEX_DEPLOYMENT Setup:${NC}"
echo " 1. Go to: https://convex.dev/"
echo " 2. Sign up and create a new project"
echo " 3. Copy your deployment URL"
echo " 4. Edit frontend/hackd-web/.env.local and replace:"
echo " CONVEX_DEPLOYMENT=your_convex_deployment_url_here"
echo " with:"
echo " CONVEX_DEPLOYMENT=https://your-project.convex.cloud"
echo ""
;;
esac
done
echo -e "${YELLOW}β‘ QUICK SETUP COMMANDS:${NC}"
echo " nano backend/.env # Edit backend config"
echo " nano frontend/hackd-web/.env.local # Edit frontend config"
echo ""
echo -e "${GREEN}π‘ TIP:${NC} The system will work partially without API keys, but full functionality requires them."
echo ""
if [ "$INTERACTIVE" != "false" ]; then
read -p "Press Enter to continue with current setup, or Ctrl+C to exit and configure APIs..."
else
log_warning "Non-interactive mode: Continuing with current setup..."
sleep 2
fi
}
# Start services
start_services() {
log_header "STARTING SERVICES"
# Start backend
log_step "Starting backend on port 5000..."
cd backend
source venv/bin/activate
$PYTHON_CMD api/main.py &
BACKEND_PID=$!
cd ..
sleep 3
# Check backend health
if curl -s http://localhost:5000/health >/dev/null 2>&1; then
log_success "Backend started successfully β"
else
log_error "Backend failed to start"
return 1
fi
# Start frontend
log_step "Starting frontend on port 3000..."
cd frontend/hackd-web
pnpm dev &
FRONTEND_PID=$!
cd ../..
# Give frontend time to start
log_info "Waiting for frontend to start..."
for i in {1..30}; do
if curl -s http://localhost:3000 >/dev/null 2>&1; then
log_success "Frontend started successfully β"
break
fi
sleep 1
if [ $i -eq 30 ]; then
log_warning "Frontend taking longer than expected to start"
fi
done
}
# Run comprehensive tests
run_tests() {
log_header "COMPREHENSIVE TESTING"
# Backend health check
log_step "Backend health check..."
if curl -s http://localhost:5000/health > /dev/null; then
log_success "Backend health check passed"
else
log_error "Backend health check failed"
fi
# Test job description analysis
log_step "Testing job description analysis..."
if curl -s -X POST http://localhost:5000/api/analyze-job-description \
-H "Content-Type: application/json" \
-d "{\"job_description\": \"We need a Senior Python Developer\", \"candidates\": [\"octocat\"]}" \
> /dev/null; then
log_success "Job analysis endpoint responding"
else
log_warning "Job analysis endpoint issues (may need API keys)"
fi
# Test frontend accessibility
log_step "Testing frontend accessibility..."
if curl -s http://localhost:3000 >/dev/null 2>&1; then
log_success "Frontend accessible β"
else
log_error "Frontend not accessible"
fi
# Run unit tests
log_step "Running unit tests..."
cd backend
source venv/bin/activate
if $PYTHON_CMD -m pytest tests/test_api.py -v --tb=short 2>/dev/null; then
log_success "Unit tests passed β"
else
log_warning "Unit tests completed (some may require API keys)"
fi
cd ..
}
# System status dashboard
show_system_status() {
log_header "SYSTEM STATUS DASHBOARD"
echo -e "${GREEN}π― HACKD SYSTEM STATUS${NC}"
echo -e "${GREEN}=====================${NC}\n"
# Services status
echo -e "${BLUE}π§ Services:${NC}"
if curl -s http://localhost:5000/health >/dev/null 2>&1; then
echo " Backend (port 5000): β
RUNNING"
else
echo " Backend (port 5000): β NOT RUNNING"
fi
if curl -s http://localhost:3000 >/dev/null 2>&1; then
echo " Frontend (port 3000): β
RUNNING"
else
echo " Frontend (port 3000): β NOT RUNNING"
fi
# API status
echo -e "\n${BLUE}π API Configuration:${NC}"
if [ ${#MISSING_APIS[@]} -eq 0 ]; then
echo " All APIs: β
CONFIGURED"
else
echo " Missing APIs: β οΈ ${MISSING_APIS[*]}"
fi
# URLs
echo -e "\n${BLUE}π Access URLs:${NC}"
echo " Frontend: http://localhost:3000"
echo " Backend API: http://localhost:5000"
echo " Health Check: http://localhost:5000/health"
echo -e "\n${YELLOW}π READY TO USE!${NC}"
echo -e "${YELLOW}=================${NC}"
echo "1. Open http://localhost:3000 in your browser"
echo "2. Go to the \"Recruiting\" section"
echo "3. Enter a job description"
echo "4. Click \"Find My Perfect Matches\""
echo "5. View the candidate results!"
echo ""
echo -e "${CYAN}π‘ Pro Tips:${NC}"
echo "β’ Try: \"We need a Senior Python developer with Django and React experience\""
echo "β’ The system will analyze GitHub profiles and provide match scores"
echo "β’ Click on candidate cards to see detailed breakdowns"
echo ""
echo -e "${GREEN}Press Ctrl+C to stop all services${NC}"
}
# Main execution
main() {
echo -e "${PURPLE}"
echo "βββ βββ ββββββ ββββββββββ ββββββββββ "
echo "βββ ββββββββββββββββββββββ ββββββββββββ"
echo "βββββββββββββββββββ βββββββ βββ βββ"
echo "βββββββββββββββββββ βββββββ βββ βββ"
echo "βββ ββββββ ββββββββββββββ βββββββββββ"
echo "βββ ββββββ βββ ββββββββββ ββββββββββ "
echo -e "${NC}"
echo -e "${CYAN}π Complete Launch & Test Suite${NC}\n"
check_system_requirements
setup_environment
validate_api_keys
start_services
run_tests
show_system_status
# Keep running until interrupted
while true; do
sleep 1
done
}
# Run main function
main "$@"