|
| 1 | +# CodeIntel Deployment Guide |
| 2 | + |
| 3 | +Complete guide for deploying CodeIntel to production and local development. |
| 4 | + |
| 5 | +## 🏠 Local Development with Docker Compose |
| 6 | + |
| 7 | +### Prerequisites |
| 8 | +- Docker Desktop installed |
| 9 | +- `.env` file configured (copy from `.env.example`) |
| 10 | + |
| 11 | +### Quick Start |
| 12 | +```bash |
| 13 | +# Clone and navigate to project |
| 14 | +cd pebble |
| 15 | + |
| 16 | +# Copy environment file |
| 17 | +cp backend/.env.example backend/.env |
| 18 | +# Edit backend/.env with your actual API keys |
| 19 | + |
| 20 | +# Build and start all services |
| 21 | +docker compose up -d |
| 22 | + |
| 23 | +# View logs |
| 24 | +docker compose logs -f backend |
| 25 | + |
| 26 | +# Stop all services |
| 27 | +docker compose down |
| 28 | +``` |
| 29 | + |
| 30 | +### Services Running |
| 31 | +- **Frontend**: http://localhost:3000 |
| 32 | +- **Backend API**: http://localhost:8000 |
| 33 | +- **API Docs**: http://localhost:8000/docs |
| 34 | +- **Redis**: localhost:6379 |
| 35 | + |
| 36 | +### Development Commands |
| 37 | +```bash |
| 38 | +# Rebuild after code changes |
| 39 | +docker compose up -d --build backend |
| 40 | + |
| 41 | +# View specific service logs |
| 42 | +docker compose logs -f backend |
| 43 | +docker compose logs -f frontend |
| 44 | +docker compose logs -f redis |
| 45 | + |
| 46 | +# Execute commands in containers |
| 47 | +docker compose exec backend python -c "print('Hello')" |
| 48 | +docker compose exec redis redis-cli ping |
| 49 | + |
| 50 | +# Stop and remove volumes (clean slate) |
| 51 | +docker compose down -v |
| 52 | +``` |
| 53 | + |
| 54 | +--- |
| 55 | + |
| 56 | +## ☁️ Production Deployment |
| 57 | + |
| 58 | +### Railway (Backend + Redis) |
| 59 | + |
| 60 | +#### 1. Initial Setup |
| 61 | +1. Sign up at [railway.app](https://railway.app) |
| 62 | +2. Install Railway CLI: `npm i -g @railway/cli` |
| 63 | +3. Login: `railway login` |
| 64 | + |
| 65 | +#### 2. Create Project |
| 66 | +```bash |
| 67 | +# Initialize Railway project |
| 68 | +railway init |
| 69 | + |
| 70 | +# Link to existing project (if you created one in dashboard) |
| 71 | +railway link |
| 72 | +``` |
| 73 | + |
| 74 | +#### 3. Deploy Backend |
| 75 | +```bash |
| 76 | +# Deploy from root directory |
| 77 | +railway up |
| 78 | + |
| 79 | +# OR use dashboard: |
| 80 | +# 1. Connect GitHub repo |
| 81 | +# 2. Select "Backend" service |
| 82 | +# 3. Set root directory to "./backend" |
| 83 | +# 4. Railway auto-detects Dockerfile |
| 84 | +``` |
| 85 | + |
| 86 | +#### 4. Add Redis |
| 87 | +In Railway dashboard: |
| 88 | +1. Click "New" → "Database" → "Add Redis" |
| 89 | +2. Railway automatically sets `REDIS_URL` environment variable |
| 90 | +3. Update backend to use `REDIS_URL` if provided: |
| 91 | + |
| 92 | +```python |
| 93 | +# In services/cache.py |
| 94 | +import os |
| 95 | +redis_url = os.getenv("REDIS_URL") |
| 96 | +if redis_url: |
| 97 | + redis_client = redis.from_url(redis_url) |
| 98 | +else: |
| 99 | + redis_client = redis.Redis(host=REDIS_HOST, port=REDIS_PORT) |
| 100 | +``` |
| 101 | + |
| 102 | +#### 5. Environment Variables (Railway Dashboard) |
| 103 | +Set these in Railway dashboard for Backend service: |
| 104 | +``` |
| 105 | +OPENAI_API_KEY=sk-... |
| 106 | +PINECONE_API_KEY=... |
| 107 | +PINECONE_INDEX_NAME=codeintel |
| 108 | +SUPABASE_URL=https://your-project.supabase.co |
| 109 | +SUPABASE_KEY=eyJ... |
| 110 | +API_KEY=production-secret-key-change-this |
| 111 | +BACKEND_API_URL=https://your-backend.railway.app |
| 112 | +``` |
| 113 | + |
| 114 | +#### 6. Custom Domain (Optional) |
| 115 | +1. Railway Dashboard → Backend Service → Settings |
| 116 | +2. Generate domain or add custom domain |
| 117 | +3. Update CORS in `backend/main.py` to allow your frontend domain |
| 118 | + |
| 119 | +--- |
| 120 | + |
| 121 | +### Vercel (Frontend) |
| 122 | + |
| 123 | +#### 1. Install Vercel CLI |
| 124 | +```bash |
| 125 | +npm i -g vercel |
| 126 | +``` |
| 127 | + |
| 128 | +#### 2. Deploy Frontend |
| 129 | +```bash |
| 130 | +cd frontend |
| 131 | + |
| 132 | +# Deploy to Vercel |
| 133 | +vercel |
| 134 | + |
| 135 | +# Production deployment |
| 136 | +vercel --prod |
| 137 | +``` |
| 138 | + |
| 139 | +#### 3. Environment Variables (Vercel Dashboard) |
| 140 | +Set in Vercel project settings: |
| 141 | +``` |
| 142 | +VITE_API_URL=https://your-backend.railway.app |
| 143 | +``` |
| 144 | + |
| 145 | +#### 4. Build Settings (Vercel Dashboard) |
| 146 | +- **Framework Preset**: Vite |
| 147 | +- **Build Command**: `npm run build` |
| 148 | +- **Output Directory**: `dist` |
| 149 | +- **Install Command**: `npm ci` |
| 150 | + |
| 151 | +--- |
| 152 | + |
| 153 | +## 🔧 Configuration Updates |
| 154 | + |
| 155 | +### Backend CORS |
| 156 | +Update `backend/main.py` with your frontend URL: |
| 157 | +```python |
| 158 | +app.add_middleware( |
| 159 | + CORSMiddleware, |
| 160 | + allow_origins=[ |
| 161 | + "https://your-frontend.vercel.app", |
| 162 | + "http://localhost:3000" # Keep for local dev |
| 163 | + ], |
| 164 | + allow_credentials=True, |
| 165 | + allow_methods=["*"], |
| 166 | + allow_headers=["*"], |
| 167 | +) |
| 168 | +``` |
| 169 | + |
| 170 | +### Health Check Endpoint |
| 171 | +Ensure `/health` endpoint exists (already implemented): |
| 172 | +```python |
| 173 | +@app.get("/health") |
| 174 | +async def health(): |
| 175 | + return {"status": "healthy", "timestamp": datetime.now().isoformat()} |
| 176 | +``` |
| 177 | + |
| 178 | +--- |
| 179 | + |
| 180 | +## 🔍 Monitoring & Debugging |
| 181 | + |
| 182 | +### Railway Logs |
| 183 | +```bash |
| 184 | +# View logs in terminal |
| 185 | +railway logs |
| 186 | + |
| 187 | +# Or use dashboard |
| 188 | +# Railway → Backend Service → Deployments → View Logs |
| 189 | +``` |
| 190 | + |
| 191 | +### Vercel Logs |
| 192 | +```bash |
| 193 | +# View logs |
| 194 | +vercel logs |
| 195 | + |
| 196 | +# Or use dashboard |
| 197 | +# Vercel → Project → Deployments → Logs |
| 198 | +``` |
| 199 | + |
| 200 | +### Redis Monitoring |
| 201 | +```bash |
| 202 | +# Connect to Railway Redis |
| 203 | +railway run redis-cli |
| 204 | + |
| 205 | +# Monitor commands |
| 206 | +MONITOR |
| 207 | + |
| 208 | +# Check memory usage |
| 209 | +INFO memory |
| 210 | + |
| 211 | +# View all keys |
| 212 | +KEYS * |
| 213 | +``` |
| 214 | + |
| 215 | +--- |
| 216 | + |
| 217 | +## 🐛 Common Issues |
| 218 | + |
| 219 | +### Issue: Backend can't connect to Redis |
| 220 | +**Solution**: Ensure `REDIS_URL` is set in Railway or Docker: |
| 221 | +```bash |
| 222 | +# Railway automatically sets this |
| 223 | +# For Docker, use docker-compose networking: |
| 224 | +REDIS_HOST=redis |
| 225 | +REDIS_PORT=6379 |
| 226 | +``` |
| 227 | + |
| 228 | +### Issue: Frontend can't reach backend |
| 229 | +**Solution**: |
| 230 | +1. Check `VITE_API_URL` in frontend environment |
| 231 | +2. Verify CORS settings in backend |
| 232 | +3. Check Railway backend is actually running |
| 233 | + |
| 234 | +### Issue: Build fails on Railway |
| 235 | +**Solution**: |
| 236 | +1. Check Dockerfile path in `railway.json` |
| 237 | +2. Verify all dependencies in `requirements.txt` |
| 238 | +3. Check Railway build logs for specific error |
| 239 | + |
| 240 | +### Issue: Port already in use (local Docker) |
| 241 | +**Solution**: |
| 242 | +```bash |
| 243 | +# Change ports in docker-compose.yml |
| 244 | +ports: |
| 245 | + - "3001:80" # Frontend |
| 246 | + - "8001:8000" # Backend |
| 247 | +``` |
| 248 | + |
| 249 | +--- |
| 250 | + |
| 251 | +## 📊 Production Checklist |
| 252 | + |
| 253 | +Before going live: |
| 254 | +- [ ] Change `API_KEY` from default value |
| 255 | +- [ ] Set up Supabase RLS policies |
| 256 | +- [ ] Configure rate limiting thresholds |
| 257 | +- [ ] Set up monitoring (Railway built-in + Sentry/LogRocket) |
| 258 | +- [ ] Add custom domain to Railway backend |
| 259 | +- [ ] Add custom domain to Vercel frontend |
| 260 | +- [ ] Test all endpoints with production data |
| 261 | +- [ ] Set up backup strategy for Redis data |
| 262 | +- [ ] Configure WAF/DDoS protection (Cloudflare) |
| 263 | +- [ ] Set up SSL certificates (auto with Railway/Vercel) |
| 264 | + |
| 265 | +--- |
| 266 | + |
| 267 | +## 🚀 Scaling |
| 268 | + |
| 269 | +### Railway |
| 270 | +- Automatic scaling based on traffic |
| 271 | +- Upgrade plan for more resources |
| 272 | +- Add replicas in dashboard |
| 273 | + |
| 274 | +### Vercel |
| 275 | +- Automatic CDN distribution |
| 276 | +- Serverless edge functions |
| 277 | +- Upgrade for more bandwidth |
| 278 | + |
| 279 | +### Redis |
| 280 | +- Railway Redis Pro for persistence |
| 281 | +- Consider Redis Cloud for production |
| 282 | +- Enable AOF persistence for data durability |
| 283 | + |
| 284 | +--- |
| 285 | + |
| 286 | +## 💰 Cost Estimates |
| 287 | + |
| 288 | +**Free Tier (Hobby Projects)** |
| 289 | +- Railway: $5/month credit, backend + Redis |
| 290 | +- Vercel: Free for personal projects |
| 291 | +- Total: ~$0-5/month |
| 292 | + |
| 293 | +**Production (Paid)** |
| 294 | +- Railway Pro: $20/month (backend + Redis) |
| 295 | +- Vercel Pro: $20/month (team features) |
| 296 | +- OpenAI API: ~$10-50/month (depending on usage) |
| 297 | +- Pinecone: $70/month (starter) |
| 298 | +- Total: ~$120-160/month |
| 299 | + |
| 300 | +--- |
| 301 | + |
| 302 | +## 📝 Next Steps |
| 303 | + |
| 304 | +1. **Deploy Backend to Railway** |
| 305 | + ```bash |
| 306 | + railway login |
| 307 | + railway init |
| 308 | + railway up |
| 309 | + ``` |
| 310 | + |
| 311 | +2. **Deploy Frontend to Vercel** |
| 312 | + ```bash |
| 313 | + cd frontend |
| 314 | + vercel --prod |
| 315 | + ``` |
| 316 | + |
| 317 | +3. **Test Everything** |
| 318 | + - Hit health endpoint |
| 319 | + - Test search functionality |
| 320 | + - Check Redis caching |
| 321 | + - Monitor logs |
| 322 | + |
| 323 | +4. **Set up CI/CD** |
| 324 | + - Connect GitHub to Railway (auto-deploys) |
| 325 | + - Connect GitHub to Vercel (auto-deploys) |
| 326 | + - Both platforms support automatic deployments on push |
| 327 | + |
| 328 | +--- |
| 329 | + |
| 330 | +## 🔗 Useful Links |
| 331 | + |
| 332 | +- [Railway Docs](https://docs.railway.app) |
| 333 | +- [Vercel Docs](https://vercel.com/docs) |
| 334 | +- [Docker Compose Docs](https://docs.docker.com/compose/) |
| 335 | +- [FastAPI Deployment](https://fastapi.tiangolo.com/deployment/) |
| 336 | +- [Vite Deployment](https://vitejs.dev/guide/static-deploy.html) |
0 commit comments