Skip to content

Latest commit

 

History

History
168 lines (128 loc) · 4.47 KB

File metadata and controls

168 lines (128 loc) · 4.47 KB

Production Deployment Guide

Container Model Deployment

The container is now production-ready with pre-cached ML models and intelligent analysis capabilities.

Key Changes Made

1. Transformer Model Pre-caching 🤖

  • Model: all-MiniLM-L6-v2 (384-dimensional embeddings)
  • Container Path: /app/models/embeddings/
  • Cache Strategy: Downloaded and cached during Docker build
  • Fallback: TF-IDF vectorizer if transformer unavailable

2. Environment Configuration ⚙️

# Set in Dockerfile for container deployment:
TRANSFORMERS_CACHE=/app/models/embeddings
SENTENCE_TRANSFORMERS_HOME=/app/models/embeddings
INTELLIGENT_ANALYZER_MODEL_PATH=/app/models/embeddings
INTELLIGENT_ANALYZER_DB_PATH=/app/data/learning/security_learning.db

3. Persistent Storage Volumes 💾

volumes:
  ml-models:           # Transformer weights and embeddings cache
  learning-data:       # Database and learning system data
  codeql-cache:        # CodeQL query packs (existing)
  scanner-cache:       # General tool cache (existing)

4. Configuration Enhancements 📋

  • Environment variable override support
  • Container-aware path resolution
  • Production database configuration with async support
  • Structured logging with JSON format

Build Verification

The container now includes a test script that verifies:

  • ✅ Model loading and caching
  • ✅ Configuration management
  • ✅ Database connectivity
  • ✅ Embeddings system functionality

Deployment Commands

Development Build

docker-compose build
docker-compose up

Production Build

# Build with model caching verification
docker build -t secscan-mcp:latest .

# Deploy with persistent volumes
docker-compose -f docker-compose.yml up -d

Test Model Loading

# Run container test
docker run --rm secscan-mcp:latest python3 test_container_models.py

# Or within running container
docker-compose exec scanner python3 test_container_models.py

Performance Benefits

Build Time

  • First Build: +2-3 minutes (model download)
  • Subsequent Builds: Cached (fast layer reuse)

Runtime Performance

  • Cold Start: ~2-3 seconds (models pre-loaded)
  • Analysis Speed: 300-500ms per scan (vs 10-15s with runtime download)
  • Memory Usage: +200MB (model weights in memory)

Configuration Override Examples

Override Model Path

docker run -e INTELLIGENT_ANALYZER_MODEL_PATH=/custom/models secscan-mcp

Override Database Location

docker run -e INTELLIGENT_ANALYZER_DB_PATH=/custom/db/security.db secscan-mcp

Development Mode (Download Models at Runtime)

docker run -e INTELLIGENT_ANALYZER_MODEL_PATH=/tmp/models secscan-mcp

Monitoring & Logs

Structured Logging

# View model loading logs
docker-compose logs scanner | grep "component.*embeddings"

# View database operations
docker-compose logs scanner | grep "component.*async_database"

# View analysis performance
docker-compose logs scanner | grep "duration_ms"

Health Checks

# Check embeddings system health
curl http://localhost:8000/health

# Get model cache information
curl http://localhost:8000/api/v1/system/status

Troubleshooting

Model Not Found

# Check model cache
docker-compose exec scanner ls -la /app/models/embeddings/

# Verify environment variables
docker-compose exec scanner env | grep INTELLIGENT_ANALYZER

Database Issues

# Check database directory
docker-compose exec scanner ls -la /app/data/learning/

# Verify database connectivity
docker-compose exec scanner python3 -c "from analyzers.intelligent.services.async_database import AsyncDatabaseManager; print('DB OK')"

Security Considerations

  • Models are cached during build (no runtime downloads)
  • Database uses SQLite with file-based storage (persistent volumes)
  • All paths are containerized and not exposed to host
  • Scanner runs as non-root user with minimal permissions

Resource Requirements

Minimum

  • CPU: 2 cores
  • Memory: 3GB (2GB app + 1GB models)
  • Storage: 5GB (2GB models + 3GB cache)

Recommended

  • CPU: 4 cores
  • Memory: 6GB (4GB app + 2GB models)
  • Storage: 10GB (5GB models + 5GB cache)

Next Steps

  1. Load Testing: Verify performance under concurrent scans
  2. Model Updates: Process for updating transformer models
  3. Monitoring: Set up metrics collection for analysis performance
  4. Scaling: Configure horizontal scaling if needed