Spaces:
Runtime error
Runtime error
File size: 6,201 Bytes
e9cd410 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 | # π³ Docker Deployment Guide
This guide covers Docker deployment options for the AI Notes Summarizer application.
## π Prerequisites
- Docker Engine 20.10+
- Docker Compose 2.0+
- At least 4GB RAM available for Docker
- Internet connection for downloading AI models
## π Quick Start
### Using Docker Compose (Recommended)
```bash
# Clone the repository
git clone <repository-url>
cd ai-notes-summarizer
# Start the application
docker-compose up -d
# Access at http://localhost:8501
```
### Using Docker Scripts
```bash
# Build the image
./docker-build.sh
# Run the container
./docker-run.sh
# Test the deployment
./docker-test.sh
```
## π Docker Files Overview
| File | Purpose |
|------|---------|
| `Dockerfile` | Standard multi-stage build |
| `Dockerfile.prod` | Production-optimized build |
| `docker-compose.yml` | Production deployment |
| `docker-compose.dev.yml` | Development environment |
| `docker-build.sh` | Build script |
| `docker-run.sh` | Run script |
| `docker-dev.sh` | Development script |
| `docker-test.sh` | Testing script |
## π§ Configuration
### Environment Variables
| Variable | Default | Description |
|----------|---------|-------------|
| `STREAMLIT_SERVER_PORT` | 8501 | Application port |
| `STREAMLIT_SERVER_ADDRESS` | 0.0.0.0 | Bind address |
| `TRANSFORMERS_CACHE` | /app/.cache/huggingface | Model cache directory |
| `MAX_FILE_SIZE_MB` | 10 | Maximum PDF file size |
| `TORCH_HOME` | /app/.cache/torch | PyTorch cache |
### Volume Mounts
| Volume | Purpose |
|--------|---------|
| `model_cache` | Persistent AI model storage |
| `logs` | Application logs |
| `uploads` | Temporary file storage |
## ποΈ Build Options
### Standard Build
```bash
docker build -t ai-notes-summarizer .
```
### Production Build
```bash
docker build -f Dockerfile.prod -t ai-notes-summarizer:prod .
```
### Development Build
```bash
docker build --target dependencies -t ai-notes-summarizer:dev .
```
## π Deployment Options
### 1. Docker Compose (Production)
```yaml
# docker-compose.yml
version: '3.8'
services:
ai-notes-summarizer:
image: ai-notes-summarizer:latest
ports:
- "8501:8501"
volumes:
- model_cache:/app/.cache
- logs:/app/logs
restart: unless-stopped
```
### 2. Docker Swarm
```bash
# Initialize swarm
docker swarm init
# Deploy stack
docker stack deploy -c docker-compose.yml ai-notes-stack
```
### 3. Kubernetes
```yaml
# k8s-deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: ai-notes-summarizer
spec:
replicas: 2
selector:
matchLabels:
app: ai-notes-summarizer
template:
metadata:
labels:
app: ai-notes-summarizer
spec:
containers:
- name: ai-notes-summarizer
image: ai-notes-summarizer:latest
ports:
- containerPort: 8501
resources:
limits:
memory: "4Gi"
cpu: "2"
requests:
memory: "2Gi"
cpu: "1"
```
## π Monitoring and Logging
### Health Checks
```bash
# Check container health
docker ps --filter "name=ai-notes-summarizer"
# View health check logs
docker inspect ai-notes-summarizer | grep -A 10 Health
```
### Logs
```bash
# View application logs
docker-compose logs -f
# View specific service logs
docker logs -f ai-notes-summarizer
```
### Metrics
```bash
# Container stats
docker stats ai-notes-summarizer
# Resource usage
docker exec ai-notes-summarizer df -h
docker exec ai-notes-summarizer free -h
```
## π οΈ Development
### Development Environment
```bash
# Start development environment with live reload
docker-compose -f docker-compose.dev.yml up
# Or use the script
./docker-dev.sh
```
### Debugging
```bash
# Access container shell
docker exec -it ai-notes-summarizer bash
# View application files
docker exec ai-notes-summarizer ls -la /app
# Check Python environment
docker exec ai-notes-summarizer pip list
```
## π Security
### Security Features
- Non-root user execution
- Minimal base image
- No unnecessary packages
- Health checks enabled
- Resource limits configured
### Security Scanning
```bash
# Scan for vulnerabilities (if you have docker scan)
docker scan ai-notes-summarizer:latest
# Check running processes
docker exec ai-notes-summarizer ps aux
```
## π¨ Troubleshooting
### Common Issues
1. **Container won't start**
```bash
docker logs ai-notes-summarizer
```
2. **Out of memory**
```bash
# Increase Docker memory limit
docker update --memory=4g ai-notes-summarizer
```
3. **Model download fails**
```bash
# Check internet connectivity
docker exec ai-notes-summarizer curl -I https://huggingface.co
```
4. **Permission issues**
```bash
# Fix ownership
docker exec -u root ai-notes-summarizer chown -R app:app /app
```
### Performance Optimization
1. **Use multi-stage builds** (already implemented)
2. **Enable BuildKit**:
```bash
export DOCKER_BUILDKIT=1
docker build .
```
3. **Use .dockerignore** (already included)
4. **Pin dependency versions** (see requirements.docker.txt)
## π Resource Requirements
### Minimum Requirements
- CPU: 1 core
- RAM: 2GB
- Storage: 5GB
### Recommended Requirements
- CPU: 2 cores
- RAM: 4GB
- Storage: 10GB
### Production Requirements
- CPU: 4 cores
- RAM: 8GB
- Storage: 20GB
- Load balancer for multiple instances
## π Updates and Maintenance
### Updating the Application
```bash
# Pull latest changes
git pull
# Rebuild and restart
docker-compose up --build -d
# Or use rolling update
docker-compose up -d --force-recreate
```
### Backup and Restore
```bash
# Backup volumes
docker run --rm -v ai-notes-model-cache:/data -v $(pwd):/backup alpine tar czf /backup/model-cache-backup.tar.gz -C /data .
# Restore volumes
docker run --rm -v ai-notes-model-cache:/data -v $(pwd):/backup alpine tar xzf /backup/model-cache-backup.tar.gz -C /data
```
## π Support
For Docker-specific issues:
1. Check container logs: `docker logs ai-notes-summarizer`
2. Verify resource limits: `docker stats`
3. Test connectivity: `docker exec ai-notes-summarizer curl localhost:8501`
4. Review Docker documentation: https://docs.docker.com
|