# Docker Deployment
Deploy Polymathy and its dependencies using Docker.
## Prerequisites
- Docker
- Docker Compose
## Docker Compose Setup
Create a `docker-compose.yml`:
```yaml
version: '3.8'
services:
polymathy:
build: .
ports:
- "8080:8080"
environment:
- SEARXNG_URL=http://searxng:8080/search
- PROCESSOR_URL=http://processor:8081/v1/process
- SERVER_HOST=0.0.0.0
- SERVER_PORT=8080
- RUST_LOG=info
depends_on:
- searxng
- processor
searxng:
image: searxng/searxng:latest
ports:
- "8888:8080"
volumes:
- ./searxng:/etc/searxng
environment:
- SEARXNG_BASE_URL=http://localhost:8888/
processor:
image: your-processor-image:latest
ports:
- "8081:8081"
environment:
- EMBEDDING_MODEL=AllMiniLML6V2
```
## Dockerfile
Create a `Dockerfile` for Polymathy:
```dockerfile
# Build stage
FROM rust:1.75 as builder
WORKDIR /app
COPY . .
RUN cargo build --release
# Runtime stage
FROM debian:bookworm-slim
RUN apt-get update && apt-get install -y \
ca-certificates \
libssl3 \
&& rm -rf /var/lib/apt/lists/*
COPY --from=builder /app/target/release/polymathy /usr/local/bin/
ENV RUST_LOG=info
EXPOSE 8080
CMD ["polymathy"]
```
## SearxNG Configuration
Create `searxng/settings.yml`:
```yaml
general:
debug: false
instance_name: "Polymathy Search"
search:
safe_search: 0
autocomplete: ""
default_lang: "en"
formats:
- html
- json
server:
port: 8080
bind_address: "0.0.0.0"
secret_key: "your-secret-key-here"
ui:
static_use_hash: true
engines:
- name: google
engine: google
shortcut: g
disabled: false
- name: duckduckgo
engine: duckduckgo
shortcut: ddg
disabled: false
- name: bing
engine: bing
shortcut: bi
disabled: false
```
## Deployment
### Build and Start
```bash
# Build images
docker-compose build
# Start all services
docker-compose up -d
# View logs
docker-compose logs -f polymathy
```
### Verify Deployment
```bash
# Check services are running
docker-compose ps
# Test the API
curl "http://localhost:8080/v1/search?q=test"
# Check SearxNG
curl "http://localhost:8888/search?q=test&format=json"
```
## Production Considerations
### Reverse Proxy
Add nginx for SSL and rate limiting:
```yaml
services:
nginx:
image: nginx:alpine
ports:
- "443:443"
- "80:80"
volumes:
- ./nginx.conf:/etc/nginx/nginx.conf
- ./certs:/etc/nginx/certs
depends_on:
- polymathy
```
Example `nginx.conf`:
```nginx
events {
worker_connections 1024;
}
http {
upstream polymathy {
server polymathy:8080;
}
limit_req_zone $binary_remote_addr zone=api:10m rate=10r/s;
server {
listen 443 ssl;
server_name your-domain.com;
ssl_certificate /etc/nginx/certs/fullchain.pem;
ssl_certificate_key /etc/nginx/certs/privkey.pem;
location /v1/ {
limit_req zone=api burst=20 nodelay;
proxy_pass http://polymathy;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
}
}
}
```
### Health Checks
Add health checks to your compose file:
```yaml
services:
polymathy:
# ... other config
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:8080/openapi.json"]
interval: 30s
timeout: 10s
retries: 3
```
### Resource Limits
Set resource constraints:
```yaml
services:
polymathy:
# ... other config
deploy:
resources:
limits:
cpus: '2'
memory: 2G
reservations:
cpus: '0.5'
memory: 512M
```
## Scaling
### Horizontal Scaling
Scale Polymathy instances:
```bash
docker-compose up -d --scale polymathy=3
```
Update nginx to load balance:
```nginx
upstream polymathy {
least_conn;
server polymathy_1:8080;
server polymathy_2:8080;
server polymathy_3:8080;
}
```
## Monitoring
Add Prometheus metrics:
```yaml
services:
prometheus:
image: prom/prometheus
volumes:
- ./prometheus.yml:/etc/prometheus/prometheus.yml
ports:
- "9090:9090"
grafana:
image: grafana/grafana
ports:
- "3000:3000"
depends_on:
- prometheus
```