diff --git a/Makefile b/Makefile new file mode 100644 index 00000000..74df8d40 --- /dev/null +++ b/Makefile @@ -0,0 +1,210 @@ +# OpenRAG Development Makefile +# Provides easy commands for development workflow + +.PHONY: help dev dev-cpu dev-local infra stop clean build logs shell-backend shell-frontend install test backend frontend install-be install-fe build-be build-fe logs-be logs-fe logs-lf logs-os shell-be shell-lf shell-os restart status health db-reset flow-upload quick setup + +# Default target +help: + @echo "OpenRAG Development Commands" + @echo "" + @echo "Development:" + @echo " dev - Start full stack with GPU support (docker compose)" + @echo " dev-cpu - Start full stack with CPU only (docker compose)" + @echo " dev-local - Start infrastructure only, run backend/frontend locally" + @echo " infra - Start infrastructure services only (alias for dev-local)" + @echo " stop - Stop all containers" + @echo " restart - Restart all containers" + @echo "" + @echo "Local Development:" + @echo " backend - Run backend locally (requires infrastructure)" + @echo " frontend - Run frontend locally" + @echo " install - Install all dependencies" + @echo " install-be - Install backend dependencies (uv)" + @echo " install-fe - Install frontend dependencies (npm)" + @echo "" + @echo "Utilities:" + @echo " build - Build all Docker images" + @echo " clean - Stop containers and remove volumes" + @echo " logs - Show logs from all containers" + @echo " logs-be - Show backend container logs" + @echo " logs-lf - Show langflow container logs" + @echo " shell-be - Shell into backend container" + @echo " shell-lf - Shell into langflow container" + @echo "" + @echo "Testing:" + @echo " test - Run backend tests" + @echo " lint - Run linting checks" + @echo "" + +# Development environments +dev: + @echo "๐Ÿš€ Starting OpenRAG with GPU support..." + docker-compose up -d + @echo "โœ… Services started!" + @echo " Backend: http://localhost:8000" + @echo " Frontend: http://localhost:3000" + @echo " Langflow: http://localhost:7860" + @echo " OpenSearch: http://localhost:9200" + @echo " Dashboards: http://localhost:5601" + +dev-cpu: + @echo "๐Ÿš€ Starting OpenRAG with CPU only..." + docker-compose -f docker-compose-cpu.yml up -d + @echo "โœ… Services started!" + @echo " Backend: http://localhost:8000" + @echo " Frontend: http://localhost:3000" + @echo " Langflow: http://localhost:7860" + @echo " OpenSearch: http://localhost:9200" + @echo " Dashboards: http://localhost:5601" + +dev-local: + @echo "๐Ÿ”ง Starting infrastructure only (for local development)..." + docker-compose up -d opensearch dashboards langflow + @echo "โœ… Infrastructure started!" + @echo " Langflow: http://localhost:7860" + @echo " OpenSearch: http://localhost:9200" + @echo " Dashboards: http://localhost:5601" + @echo "" + @echo "Now run 'make backend' and 'make frontend' in separate terminals" + +infra: + @echo "๐Ÿ”ง Starting infrastructure services only..." + docker-compose up -d opensearch dashboards langflow + @echo "โœ… Infrastructure services started!" + @echo " Langflow: http://localhost:7860" + @echo " OpenSearch: http://localhost:9200" + @echo " Dashboards: http://localhost:5601" + +# Container management +stop: + @echo "๐Ÿ›‘ Stopping all containers..." + docker-compose down + docker-compose -f docker-compose-cpu.yml down 2>/dev/null || true + +restart: stop dev + +clean: stop + @echo "๐Ÿงน Cleaning up containers and volumes..." + docker-compose down -v --remove-orphans + docker-compose -f docker-compose-cpu.yml down -v --remove-orphans 2>/dev/null || true + docker system prune -f + +# Local development +backend: + @echo "๐Ÿ Starting backend locally..." + @if [ ! -f .env ]; then echo "โš ๏ธ .env file not found. Copy .env.example to .env first"; exit 1; fi + cd src && uv run python main.py + +frontend: + @echo "โš›๏ธ Starting frontend locally..." + @if [ ! -d "frontend/node_modules" ]; then echo "๐Ÿ“ฆ Installing frontend dependencies first..."; cd frontend && npm install; fi + cd frontend && npx next dev + +# Installation +install: install-be install-fe + @echo "โœ… All dependencies installed!" + +install-be: + @echo "๐Ÿ“ฆ Installing backend dependencies..." + uv sync + +install-fe: + @echo "๐Ÿ“ฆ Installing frontend dependencies..." + cd frontend && npm install + +# Building +build: + @echo "๐Ÿ”จ Building Docker images..." + docker-compose build + +build-be: + @echo "๐Ÿ”จ Building backend image..." + docker build -t openrag-backend -f Dockerfile.backend . + +build-fe: + @echo "๐Ÿ”จ Building frontend image..." + docker build -t openrag-frontend -f Dockerfile.frontend . + +# Logging and debugging +logs: + @echo "๐Ÿ“‹ Showing all container logs..." + docker-compose logs -f + +logs-be: + @echo "๐Ÿ“‹ Showing backend logs..." + docker-compose logs -f openrag-backend + +logs-fe: + @echo "๐Ÿ“‹ Showing frontend logs..." + docker-compose logs -f openrag-frontend + +logs-lf: + @echo "๐Ÿ“‹ Showing langflow logs..." + docker-compose logs -f langflow + +logs-os: + @echo "๐Ÿ“‹ Showing opensearch logs..." + docker-compose logs -f opensearch + +# Shell access +shell-be: + @echo "๐Ÿš Opening shell in backend container..." + docker-compose exec openrag-backend /bin/bash + +shell-lf: + @echo "๐Ÿš Opening shell in langflow container..." + docker-compose exec langflow /bin/bash + +shell-os: + @echo "๐Ÿš Opening shell in opensearch container..." + docker-compose exec opensearch /bin/bash + +# Testing and quality +test: + @echo "๐Ÿงช Running backend tests..." + uv run pytest + +lint: + @echo "๐Ÿ” Running linting checks..." + cd frontend && npm run lint + @echo "Frontend linting complete" + +# Service status +status: + @echo "๐Ÿ“Š Container status:" + @docker-compose ps 2>/dev/null || echo "No containers running" + +health: + @echo "๐Ÿฅ Health check:" + @echo "Backend: $$(curl -s http://localhost:8000/health 2>/dev/null || echo 'Not responding')" + @echo "Langflow: $$(curl -s http://localhost:7860/health 2>/dev/null || echo 'Not responding')" + @echo "OpenSearch: $$(curl -s -k -u admin:$(shell grep OPENSEARCH_PASSWORD .env | cut -d= -f2) https://localhost:9200 2>/dev/null | jq -r .tagline 2>/dev/null || echo 'Not responding')" + +# Database operations +db-reset: + @echo "๐Ÿ—„๏ธ Resetting OpenSearch indices..." + curl -X DELETE "http://localhost:9200/documents" -u admin:$$(grep OPENSEARCH_PASSWORD .env | cut -d= -f2) || true + curl -X DELETE "http://localhost:9200/knowledge_filters" -u admin:$$(grep OPENSEARCH_PASSWORD .env | cut -d= -f2) || true + @echo "Indices reset. Restart backend to recreate." + +# Flow management +flow-upload: + @echo "๐Ÿ“ Uploading flow to Langflow..." + @if [ -z "$(FLOW_FILE)" ]; then echo "Usage: make flow-upload FLOW_FILE=path/to/flow.json"; exit 1; fi + curl -X POST "http://localhost:7860/api/v1/flows" \ + -H "Content-Type: application/json" \ + -d @$(FLOW_FILE) + +# Quick development shortcuts +quick: dev-local + @echo "๐Ÿš€ Quick start: infrastructure running!" + @echo "Run these in separate terminals:" + @echo " make backend" + @echo " make frontend" + +# Environment setup +setup: + @echo "โš™๏ธ Setting up development environment..." + @if [ ! -f .env ]; then cp .env.example .env && echo "๐Ÿ“ Created .env from template"; fi + @$(MAKE) install + @echo "โœ… Setup complete! Run 'make dev' to start." \ No newline at end of file