main #11

Merged
mstoeck3 merged 66 commits from main into forensic-ai 2025-08-11 12:02:56 +00:00
Showing only changes of commit dff78cbe0a - Show all commits

217
deploy.sh Normal file → Executable file
View File

@ -0,0 +1,217 @@
#!/bin/bash
# ForensicPathways Deployment Script
# Usage: sudo ./deploy.sh
set -e
WEBROOT="/var/www/forensic-pathways"
BACKUP_DIR="/var/backups/forensic-pathways"
LOG_DIR="$WEBROOT/logs"
DATA_DIR="$WEBROOT/data"
UPLOADS_DIR="$WEBROOT/public/uploads"
echo "🚀 ForensicPathways Deployment Starting..."
echo "📅 $(date '+%Y-%m-%d %H:%M:%S')"
echo ""
# Check if running as root
if [ "$EUID" -ne 0 ]; then
echo "❌ Error: This script must be run as root (use sudo)"
exit 1
fi
# Check prerequisites
echo "🔍 Checking prerequisites..."
if ! command -v npm &> /dev/null; then
echo "❌ Error: npm is not installed"
exit 1
fi
echo "✅ npm found: $(npm --version)"
if ! command -v node &> /dev/null; then
echo "❌ Error: Node.js is not installed"
exit 1
fi
echo "✅ Node.js found: $(node --version)"
# Check if dist directory exists or can be built
if [ ! -d "dist" ]; then
echo "📦 Building application..."
npm run build
echo "✅ Build completed successfully"
else
echo "📦 Found existing dist/ directory"
read -p "🤔 Rebuild application? (y/N): " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
echo "📦 Rebuilding application..."
npm run build
echo "✅ Rebuild completed successfully"
else
echo "📦 Using existing build"
fi
fi
# Create backup if existing deployment exists
if [ -d "$WEBROOT" ]; then
BACKUP_TIMESTAMP=$(date +%Y%m%d_%H%M%S)
BACKUP_PATH="$BACKUP_DIR/$BACKUP_TIMESTAMP"
echo "💾 Creating backup at $BACKUP_PATH..."
mkdir -p "$BACKUP_DIR"
cp -r "$WEBROOT" "$BACKUP_PATH"
echo "✅ Backup created successfully"
# Preserve existing .env if it exists
if [ -f "$WEBROOT/.env" ]; then
cp "$WEBROOT/.env" "/tmp/forensic-pathways.env.backup"
echo "💾 Preserved existing .env configuration"
fi
# Clean old backups (keep last 5)
cd "$BACKUP_DIR"
ls -1t | tail -n +6 | xargs -r rm -rf
echo "🧹 Cleaned old backups (keeping last 5)"
fi
# Create webroot and subdirectories
echo "📁 Setting up directory structure..."
mkdir -p "$WEBROOT"
mkdir -p "$LOG_DIR"
mkdir -p "$DATA_DIR"
mkdir -p "$UPLOADS_DIR"
mkdir -p "$WEBROOT/src/data"
mkdir -p "$WEBROOT/public"
mkdir -p "$WEBROOT/server"
echo "✅ Directory structure created"
# Copy built application
echo "📋 Copying application files..."
if [ -d "dist" ]; then
cp -r dist/* "$WEBROOT/"
echo "✅ Application files copied"
else
echo "❌ Error: dist/ directory not found"
exit 1
fi
# Copy essential data files
echo "🗂️ Setting up data files..."
if [ -f "src/data/tools.yaml" ]; then
cp src/data/tools.yaml "$WEBROOT/src/data/"
echo "✅ tools.yaml copied"
else
echo "❌ Error: src/data/tools.yaml not found"
exit 1
fi
# Copy any existing knowledgebase content
if [ -d "src/content/knowledgebase" ]; then
mkdir -p "$WEBROOT/src/content"
cp -r src/content/knowledgebase "$WEBROOT/src/content/"
echo "✅ Knowledgebase content copied"
fi
# Handle environment configuration
if [ -f "/tmp/forensic-pathways.env.backup" ]; then
echo "🔧 Restoring existing .env configuration..."
cp "/tmp/forensic-pathways.env.backup" "$WEBROOT/.env"
rm "/tmp/forensic-pathways.env.backup"
echo "✅ Existing configuration restored"
else
echo "🔧 Setting up new environment configuration..."
cp .env.example "$WEBROOT/.env"
echo "⚠️ IMPORTANT: Edit $WEBROOT/.env with your configuration"
fi
# Create additional required files and directories
echo "📝 Creating additional files..."
# Create embeddings data directory
mkdir -p "$DATA_DIR/embeddings"
# Create logs directory with proper structure
mkdir -p "$LOG_DIR/access"
mkdir -p "$LOG_DIR/error"
mkdir -p "$LOG_DIR/ai"
# Create placeholder log files
touch "$LOG_DIR/access.log"
touch "$LOG_DIR/error.log"
touch "$LOG_DIR/ai-pipeline.log"
echo "✅ Additional files and directories created"
# Set proper permissions
echo "🔐 Setting permissions..."
chown -R www-data:www-data "$WEBROOT"
chmod -R 755 "$WEBROOT"
chmod 600 "$WEBROOT/.env"
# Specific permissions for data directories
chmod 755 "$DATA_DIR"
chmod 755 "$UPLOADS_DIR"
chmod 755 "$LOG_DIR"
chmod 644 "$LOG_DIR"/*.log
# Make server entry point executable
if [ -f "$WEBROOT/server/entry.mjs" ]; then
chmod 755 "$WEBROOT/server/entry.mjs"
echo "✅ Server entry point permissions set"
fi
echo "✅ Permissions configured successfully"
# Display deployment summary
echo ""
echo "═══════════════════════════════════════════════════════════════"
echo "✅ ForensicPathways Deployment Complete!"
echo "═══════════════════════════════════════════════════════════════"
echo ""
echo "📊 Deployment Summary:"
echo " 🎯 Target: $WEBROOT"
echo " 💾 Backup: $BACKUP_DIR"
echo " 📁 Logs: $LOG_DIR"
echo " 📤 Uploads: $UPLOADS_DIR"
echo " 🗃️ Data: $DATA_DIR"
echo ""
echo "📋 Required Next Steps:"
echo " 1. 🔧 Edit $WEBROOT/.env with your configuration"
echo " - Set PUBLIC_BASE_URL to your domain"
echo " - Configure AI_ANALYZER_* settings"
echo " - Set AUTH_SECRET to a secure value"
echo ""
echo " 2. 🔄 Restart services:"
echo " sudo systemctl restart forensic-pathways"
echo " sudo systemctl reload nginx"
echo ""
echo " 3. 🔍 Check status:"
echo " sudo systemctl status forensic-pathways"
echo " sudo tail -f $LOG_DIR/error.log"
echo ""
echo "🌐 Once configured, access at: http://your-domain.com"
echo ""
# Final validation
echo "🔍 Post-deployment validation..."
if [ -f "$WEBROOT/.env" ]; then
echo "✅ Environment configuration exists"
else
echo "❌ Environment configuration missing"
fi
if [ -f "$WEBROOT/src/data/tools.yaml" ]; then
echo "✅ Tools database exists"
else
echo "❌ Tools database missing"
fi
if [ -d "$WEBROOT/server" ]; then
echo "✅ Server directory exists"
else
echo "❌ Server directory missing"
fi
echo ""
echo "🎉 Deployment script completed at $(date '+%Y-%m-%d %H:%M:%S')"