* fixed blocking call * fixed blocking call * fixed r2r flows * fastapi wrapper and containerization * chore: add langgraph-checkpoint-postgres as a dependency in pyproject.toml - Included "langgraph-checkpoint-postgres>=2.0.23" in the dependencies section to enhance project capabilities. * feat: add .env.example for environment variable configuration - Introduced a new .env.example file to provide a template for required and optional API keys. - Updated .env.production to ensure consistent formatting. - Enhanced deploy.sh with a project name variable and improved health check logic. - Modified docker-compose.production.yml to enforce required POSTGRES_PASSWORD environment variable. - Updated README.md and devcontainer scripts to reflect changes in .env file creation. - Improved code formatting and consistency across various files. * fix: update .gitignore and clean up imports in webapp.py and rag_agent.py - Modified .gitignore to include task files for better organization. - Cleaned up unused imports and improved function calls in webapp.py for better readability. - Updated rag_agent.py to streamline import statements and enhance type safety in function definitions. - Refactored validation logic in check_duplicate.py to simplify checks for sanitized names. * Update src/biz_bud/webapp.py Co-authored-by: qodo-merge-pro[bot] <151058649+qodo-merge-pro[bot]@users.noreply.github.com> * Update src/biz_bud/agents/rag/retriever.py Co-authored-by: qodo-merge-pro[bot] <151058649+qodo-merge-pro[bot]@users.noreply.github.com> * Update Dockerfile.production Co-authored-by: qodo-merge-pro[bot] <151058649+qodo-merge-pro[bot]@users.noreply.github.com> * Update packages/business-buddy-tools/src/bb_tools/r2r/tools.py Co-authored-by: qodo-merge-pro[bot] <151058649+qodo-merge-pro[bot]@users.noreply.github.com> * Update src/biz_bud/agents/rag_agent.py Co-authored-by: qodo-merge-pro[bot] <151058649+qodo-merge-pro[bot]@users.noreply.github.com> * feat: add BaseCheckpointSaver interface documentation and enhance singleton pattern guidelines - Introduced new documentation for the BaseCheckpointSaver interface, detailing core methods for checkpoint management. - Updated check_singletons.md to include additional singleton patterns and best practices for resource management. - Enhanced error handling in create_research_graph to log failures when creating the Postgres checkpointer. --------- Co-authored-by: qodo-merge-pro[bot] <151058649+qodo-merge-pro[bot]@users.noreply.github.com>
215 lines
6.3 KiB
Bash
Executable File
215 lines
6.3 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
# Business Buddy Production Deployment Script
|
|
|
|
set -e
|
|
|
|
echo "🚀 Starting Business Buddy production deployment..."
|
|
|
|
# Colors for output
|
|
RED='\033[0;31m'
|
|
GREEN='\033[0;32m'
|
|
YELLOW='\033[1;33m'
|
|
NC='\033[0m' # No Color
|
|
|
|
# Configuration
|
|
COMPOSE_FILE="docker-compose.production.yml"
|
|
ENV_FILE=".env.production"
|
|
BACKUP_DIR="./backups"
|
|
PROJECT_NAME="biz-bud"
|
|
|
|
# Functions
|
|
log_info() {
|
|
echo -e "${GREEN}[INFO]${NC} $1"
|
|
}
|
|
|
|
log_warning() {
|
|
echo -e "${YELLOW}[WARNING]${NC} $1"
|
|
}
|
|
|
|
log_error() {
|
|
echo -e "${RED}[ERROR]${NC} $1"
|
|
}
|
|
|
|
# Check prerequisites
|
|
check_prerequisites() {
|
|
log_info "Checking prerequisites..."
|
|
|
|
if ! command -v docker &> /dev/null; then
|
|
log_error "Docker is not installed"
|
|
exit 1
|
|
fi
|
|
|
|
if ! command -v docker-compose &> /dev/null; then
|
|
log_error "Docker Compose is not installed"
|
|
exit 1
|
|
fi
|
|
|
|
if [ ! -f "$ENV_FILE" ]; then
|
|
log_error "Environment file $ENV_FILE not found"
|
|
log_info "Copy .env.production to .env and configure your settings"
|
|
exit 1
|
|
fi
|
|
|
|
log_info "Prerequisites check passed"
|
|
}
|
|
|
|
# Create backup
|
|
create_backup() {
|
|
if [ "$1" == "--skip-backup" ]; then
|
|
log_info "Skipping backup as requested"
|
|
return
|
|
fi
|
|
|
|
log_info "Creating backup..."
|
|
mkdir -p "$BACKUP_DIR"
|
|
|
|
# Backup database if running
|
|
if docker-compose -f "$COMPOSE_FILE" ps -q postgres > /dev/null && \
|
|
docker inspect $(docker-compose -f "$COMPOSE_FILE" ps -q postgres) --format='{{.State.Status}}' | grep -q "running"; then
|
|
log_info "Backing up database..."
|
|
docker-compose -f "$COMPOSE_FILE" exec -T postgres pg_dump -U app business_buddy > "$BACKUP_DIR/db_backup_$(date +%Y%m%d_%H%M%S).sql"
|
|
fi
|
|
|
|
# Backup volumes
|
|
log_info "Backing up volumes..."
|
|
docker run --rm -v ${PROJECT_NAME}_postgres_data:/data -v $(pwd)/$BACKUP_DIR:/backup alpine tar czf /backup/postgres_data_$(date +%Y%m%d_%H%M%S).tar.gz -C /data .
|
|
docker run --rm -v ${PROJECT_NAME}_redis_data:/data -v $(pwd)/$BACKUP_DIR:/backup alpine tar czf /backup/redis_data_$(date +%Y%m%d_%H%M%S).tar.gz -C /data .
|
|
docker run --rm -v ${PROJECT_NAME}_qdrant_data:/data -v $(pwd)/$BACKUP_DIR:/backup alpine tar czf /backup/qdrant_data_$(date +%Y%m%d_%H%M%S).tar.gz -C /data .
|
|
|
|
log_info "Backup completed"
|
|
}
|
|
|
|
# Deploy application
|
|
deploy() {
|
|
log_info "Deploying Business Buddy application..."
|
|
|
|
# Build and start services
|
|
log_info "Building Docker images..."
|
|
docker-compose -f "$COMPOSE_FILE" build --no-cache
|
|
|
|
log_info "Starting services..."
|
|
docker-compose -f "$COMPOSE_FILE" up -d
|
|
|
|
# Wait for services to be healthy
|
|
log_info "Waiting for services to be healthy..."
|
|
|
|
HEALTH_URL="http://localhost:8000/health"
|
|
MAX_WAIT=60 # seconds
|
|
WAIT_INTERVAL=2
|
|
WAITED=0
|
|
|
|
until curl -f "$HEALTH_URL" > /dev/null 2>&1; do
|
|
if [ "$WAITED" -ge "$MAX_WAIT" ]; then
|
|
log_error "❌ Application health check timed out after ${MAX_WAIT}s"
|
|
log_info "Checking logs..."
|
|
docker-compose -f "$COMPOSE_FILE" logs app
|
|
exit 1
|
|
fi
|
|
sleep "$WAIT_INTERVAL"
|
|
WAITED=$((WAITED + WAIT_INTERVAL))
|
|
log_info "Waiting for application to become healthy... (${WAITED}s elapsed)"
|
|
done
|
|
|
|
log_info "✅ Application is healthy and running"
|
|
}
|
|
|
|
# Show status
|
|
show_status() {
|
|
log_info "Application Status:"
|
|
docker-compose -f "$COMPOSE_FILE" ps
|
|
|
|
log_info "Service URLs:"
|
|
echo " • Application: http://localhost:8000"
|
|
echo " • API Documentation: http://localhost:8000/docs"
|
|
echo " • Health Check: http://localhost:8000/health"
|
|
echo " • Application Info: http://localhost:8000/info"
|
|
|
|
if docker-compose -f "$COMPOSE_FILE" --profile with-nginx ps nginx | grep -q "Up"; then
|
|
echo " • Nginx Proxy: http://localhost:80"
|
|
fi
|
|
}
|
|
|
|
# Clean up old resources
|
|
cleanup() {
|
|
log_info "Cleaning up old resources..."
|
|
|
|
# Remove old unused images
|
|
docker image prune -f
|
|
|
|
# Remove old unused volumes (be careful with this)
|
|
if [ "$1" == "--clean-volumes" ]; then
|
|
log_warning "Cleaning unused volumes..."
|
|
docker volume prune -f
|
|
fi
|
|
|
|
log_info "Cleanup completed"
|
|
}
|
|
|
|
# Main deployment logic
|
|
main() {
|
|
case "${1:-deploy}" in
|
|
"deploy")
|
|
check_prerequisites
|
|
create_backup "$2"
|
|
deploy
|
|
show_status
|
|
;;
|
|
"status")
|
|
show_status
|
|
;;
|
|
"backup")
|
|
create_backup
|
|
;;
|
|
"cleanup")
|
|
cleanup "$2"
|
|
;;
|
|
"logs")
|
|
docker-compose -f "$COMPOSE_FILE" logs -f "${2:-app}"
|
|
;;
|
|
"stop")
|
|
log_info "Stopping services..."
|
|
docker-compose -f "$COMPOSE_FILE" down
|
|
;;
|
|
"restart")
|
|
log_info "Restarting services..."
|
|
docker-compose -f "$COMPOSE_FILE" restart
|
|
;;
|
|
"with-nginx")
|
|
log_info "Deploying with Nginx proxy..."
|
|
check_prerequisites
|
|
create_backup "$2"
|
|
docker-compose -f "$COMPOSE_FILE" --profile with-nginx up -d --build
|
|
show_status
|
|
;;
|
|
"help"|*)
|
|
echo "Business Buddy Deployment Script"
|
|
echo ""
|
|
echo "Usage: $0 [command] [options]"
|
|
echo ""
|
|
echo "Commands:"
|
|
echo " deploy Deploy the application (default)"
|
|
echo " deploy --skip-backup Deploy without creating backup"
|
|
echo " with-nginx Deploy with Nginx reverse proxy"
|
|
echo " status Show application status"
|
|
echo " backup Create backup only"
|
|
echo " cleanup Clean up old Docker resources"
|
|
echo " cleanup --clean-volumes Clean up including volumes"
|
|
echo " logs [service] Show logs for service (default: app)"
|
|
echo " stop Stop all services"
|
|
echo " restart Restart all services"
|
|
echo " help Show this help message"
|
|
echo ""
|
|
echo "Examples:"
|
|
echo " $0 deploy"
|
|
echo " $0 deploy --skip-backup"
|
|
echo " $0 with-nginx"
|
|
echo " $0 logs app"
|
|
echo " $0 status"
|
|
;;
|
|
esac
|
|
}
|
|
|
|
# Run main function
|
|
main "$@"
|