3.3 KiB
3.3 KiB
🐳 Docker Architecture for Last-In AI
Overview
This document outlines the containerization strategy for the Last-In AI application, including multi-stage builds, service dependencies, and security considerations.
Base Image Selection
# Build stage
FROM python:3.8-slim-bullseye as builder
# Slim-bullseye chosen for:
# - Minimal size while maintaining compatibility
# - Security updates and stability
# - Python 3.8+ compatibility
Multi-Stage Build Strategy
-
Builder Stage
- Install build dependencies
- Install Python packages
- Compile any necessary components
-
Production Stage
- Copy only necessary files from builder
- Minimal runtime dependencies
- Non-root user setup
Dependencies and Requirements
- Python packages from requirements.txt
- System dependencies:
- build-essential (for some Python packages)
- libpq-dev (for PostgreSQL)
- Optional: tesseract-ocr (for PDF processing)
Directory Structure
/app
├── src/ # Application code
├── config/ # Configuration files
├── cache/ # Paper cache directory
├── data/ # Vector store data
└── logs/ # Application logs
Environment Configuration
- Source: .env.example
- Runtime variables:
- Database credentials
- API keys
- Redis configuration
- Storage paths
- Security settings
Service Dependencies
-
PostgreSQL
- Primary database
- Persistent volume for data
- Environment: POSTGRES_* variables
-
Redis
- Caching layer
- Port: 6379
- No persistence needed
Security Considerations
- Non-root user execution
- Secret management via Docker secrets
- Read-only filesystem where possible
- Minimal base image
- Regular security updates
- Proper file permissions
Docker Compose Configuration
Services:
- Main application
- PostgreSQL database
- Redis cache
- Optional: Monitoring
Resource Management
- Memory limits
- CPU allocation
- Volume mounts for:
- Paper cache
- Vector store
- Logs
Health Checks
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
CMD curl -f http://localhost:8000/health || exit 1
Build and Run Commands
# Build
docker build --tag lastin-ai:prod --target production .
# Run
docker run -p 8000:8000 \
--env-file .env.prod \
--volume ./cache:/app/cache \
--volume ./data:/app/data \
--volume ./logs:/app/logs \
lastin-ai:prod
File Exclusions (.dockerignore)
.git
.env*
__pycache__
*.pyc
.pytest_cache
.coverage
htmlcov
.vscode
*.log
cache/*
data/*
logs/*
Implementation Steps
- Switch to Code mode
- Create Dockerfile
- Create docker-compose.yml
- Create .dockerignore
- Test build and deployment
- Implement health checks
- Configure monitoring
Security Hardening Steps
- Implement least privilege principle
- Regular dependency updates
- Image vulnerability scanning
- Secrets management
- Network security policies
Recommendations
- Use multi-stage builds for minimal production image
- Implement proper logging configuration
- Regular security audits
- Backup strategy for persistent data
- Monitoring and alerting setup
This containerization strategy ensures:
- Efficient builds
- Secure runtime
- Scalable deployment
- Proper resource management
- Easy maintenance