Spaces:
Sleeping
Sleeping
Docker Stages Implemented
Browse files- .dockerignore +58 -0
- DOCKER.md +70 -0
- Dockerfile +41 -0
- docker-compose.yaml +60 -0
- observability/prometheus/prometheus.yml +1 -6
.dockerignore
CHANGED
|
@@ -0,0 +1,58 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Git
|
| 2 |
+
.git
|
| 3 |
+
.gitignore
|
| 4 |
+
.gitattributes
|
| 5 |
+
|
| 6 |
+
# Python
|
| 7 |
+
__pycache__
|
| 8 |
+
*.py[cod]
|
| 9 |
+
*$py.class
|
| 10 |
+
*.so
|
| 11 |
+
.Python
|
| 12 |
+
env/
|
| 13 |
+
venv/
|
| 14 |
+
ENV/
|
| 15 |
+
*.egg-info/
|
| 16 |
+
|
| 17 |
+
# IDE
|
| 18 |
+
.vscode/
|
| 19 |
+
.idea/
|
| 20 |
+
*.swp
|
| 21 |
+
*.swo
|
| 22 |
+
*~
|
| 23 |
+
|
| 24 |
+
# Data and artifacts (mounted as volumes)
|
| 25 |
+
artifacts/
|
| 26 |
+
monitoring/
|
| 27 |
+
mlruns/
|
| 28 |
+
data/
|
| 29 |
+
|
| 30 |
+
# Airflow
|
| 31 |
+
airflow/logs/
|
| 32 |
+
airflow/airflow.db
|
| 33 |
+
|
| 34 |
+
# Documentation
|
| 35 |
+
README.md
|
| 36 |
+
docs/
|
| 37 |
+
*.md
|
| 38 |
+
|
| 39 |
+
# Docker
|
| 40 |
+
Dockerfile
|
| 41 |
+
docker-compose.yaml
|
| 42 |
+
.dockerignore
|
| 43 |
+
|
| 44 |
+
# CI/CD
|
| 45 |
+
.github/
|
| 46 |
+
|
| 47 |
+
# Tests
|
| 48 |
+
tests/
|
| 49 |
+
pytest.ini
|
| 50 |
+
.pytest_cache/
|
| 51 |
+
|
| 52 |
+
# Notebooks
|
| 53 |
+
notebooks/
|
| 54 |
+
*.ipynb
|
| 55 |
+
|
| 56 |
+
# OS
|
| 57 |
+
.DS_Store
|
| 58 |
+
Thumbs.db
|
DOCKER.md
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Docker Setup
|
| 2 |
+
|
| 3 |
+
This project includes Docker configuration for easy deployment and monitoring.
|
| 4 |
+
|
| 5 |
+
## Services
|
| 6 |
+
|
| 7 |
+
- **FastAPI App** (port 8000): Main ML API
|
| 8 |
+
- **Prometheus** (port 9090): Metrics collection
|
| 9 |
+
- **Grafana** (port 3000): Visualization dashboards
|
| 10 |
+
|
| 11 |
+
## Quick Start
|
| 12 |
+
|
| 13 |
+
### 1. Build and Start
|
| 14 |
+
|
| 15 |
+
```bash
|
| 16 |
+
docker-compose up -d
|
| 17 |
+
```
|
| 18 |
+
|
| 19 |
+
### 2. Access Services
|
| 20 |
+
|
| 21 |
+
- API: http://localhost:8000
|
| 22 |
+
- API Docs: http://localhost:8000/docs
|
| 23 |
+
- Prometheus: http://localhost:9090
|
| 24 |
+
- Grafana: http://localhost:3000 (admin/admin)
|
| 25 |
+
|
| 26 |
+
### 3. Stop Services
|
| 27 |
+
|
| 28 |
+
```bash
|
| 29 |
+
docker-compose down
|
| 30 |
+
```
|
| 31 |
+
|
| 32 |
+
## Useful Commands
|
| 33 |
+
|
| 34 |
+
```bash
|
| 35 |
+
# View logs
|
| 36 |
+
docker-compose logs -f
|
| 37 |
+
|
| 38 |
+
# View app logs only
|
| 39 |
+
docker-compose logs -f app
|
| 40 |
+
|
| 41 |
+
# Rebuild after code changes
|
| 42 |
+
docker-compose up -d --build
|
| 43 |
+
|
| 44 |
+
# Stop and remove volumes
|
| 45 |
+
docker-compose down -v
|
| 46 |
+
```
|
| 47 |
+
|
| 48 |
+
## Environment Variables
|
| 49 |
+
|
| 50 |
+
Create `.env` file with:
|
| 51 |
+
```
|
| 52 |
+
MLFLOW_TRACKING_URI=your_dagshub_uri
|
| 53 |
+
DAGSHUB_TOKEN=your_token
|
| 54 |
+
```
|
| 55 |
+
|
| 56 |
+
## Grafana Setup
|
| 57 |
+
|
| 58 |
+
1. Login to Grafana (admin/admin)
|
| 59 |
+
2. Datasources are auto-configured
|
| 60 |
+
3. Dashboards are auto-loaded
|
| 61 |
+
|
| 62 |
+
## Health Checks
|
| 63 |
+
|
| 64 |
+
```bash
|
| 65 |
+
# Check app health
|
| 66 |
+
curl http://localhost:8000/health
|
| 67 |
+
|
| 68 |
+
# Check Prometheus targets
|
| 69 |
+
curl http://localhost:9090/api/v1/targets
|
| 70 |
+
```
|
Dockerfile
CHANGED
|
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Multi-stage build for minimal image size
|
| 2 |
+
FROM python:3.11-slim as builder
|
| 3 |
+
|
| 4 |
+
WORKDIR /app
|
| 5 |
+
|
| 6 |
+
# Install system dependencies
|
| 7 |
+
RUN apt-get update && apt-get install -y --no-install-recommends \
|
| 8 |
+
gcc g++ \
|
| 9 |
+
&& rm -rf /var/lib/apt/lists/*
|
| 10 |
+
|
| 11 |
+
# Copy and install Python dependencies
|
| 12 |
+
COPY requirements.txt .
|
| 13 |
+
RUN pip install --no-cache-dir --user -r requirements.txt
|
| 14 |
+
|
| 15 |
+
# Runtime stage
|
| 16 |
+
FROM python:3.11-slim
|
| 17 |
+
|
| 18 |
+
WORKDIR /app
|
| 19 |
+
|
| 20 |
+
# Copy installed packages from builder
|
| 21 |
+
COPY --from=builder /root/.local /root/.local
|
| 22 |
+
|
| 23 |
+
# Copy application code
|
| 24 |
+
COPY src/ ./src/
|
| 25 |
+
COPY app/ ./app/
|
| 26 |
+
COPY config/ ./config/
|
| 27 |
+
COPY templates/ ./templates/
|
| 28 |
+
COPY .env .env
|
| 29 |
+
|
| 30 |
+
# Add .local/bin to PATH
|
| 31 |
+
ENV PATH=/root/.local/bin:$PATH
|
| 32 |
+
|
| 33 |
+
# Expose FastAPI port
|
| 34 |
+
EXPOSE 8000
|
| 35 |
+
|
| 36 |
+
# Health check
|
| 37 |
+
HEALTHCHECK --interval=30s --timeout=10s --start-period=40s --retries=3 \
|
| 38 |
+
CMD python -c "import urllib.request; urllib.request.urlopen('http://localhost:8000/health')"
|
| 39 |
+
|
| 40 |
+
# Run FastAPI
|
| 41 |
+
CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000"]
|
docker-compose.yaml
CHANGED
|
@@ -0,0 +1,60 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version: '3.8'
|
| 2 |
+
|
| 3 |
+
services:
|
| 4 |
+
# FastAPI Application
|
| 5 |
+
app:
|
| 6 |
+
build: .
|
| 7 |
+
container_name: automl-app
|
| 8 |
+
ports:
|
| 9 |
+
- "8000:8000"
|
| 10 |
+
volumes:
|
| 11 |
+
- ./artifacts:/app/artifacts
|
| 12 |
+
- ./monitoring:/app/monitoring
|
| 13 |
+
- ./mlruns:/app/mlruns
|
| 14 |
+
environment:
|
| 15 |
+
- MLFLOW_TRACKING_URI=${MLFLOW_TRACKING_URI}
|
| 16 |
+
- DAGSHUB_TOKEN=${DAGSHUB_TOKEN}
|
| 17 |
+
restart: unless-stopped
|
| 18 |
+
healthcheck:
|
| 19 |
+
test: ["CMD", "curl", "-f", "http://localhost:8000/health"]
|
| 20 |
+
interval: 30s
|
| 21 |
+
timeout: 10s
|
| 22 |
+
retries: 3
|
| 23 |
+
|
| 24 |
+
# Prometheus for metrics
|
| 25 |
+
prometheus:
|
| 26 |
+
image: prom/prometheus:latest
|
| 27 |
+
container_name: automl-prometheus
|
| 28 |
+
ports:
|
| 29 |
+
- "9090:9090"
|
| 30 |
+
volumes:
|
| 31 |
+
- ./observability/prometheus/prometheus.yml:/etc/prometheus/prometheus.yml
|
| 32 |
+
- ./observability/prometheus/alerts.yml:/etc/prometheus/alerts.yml
|
| 33 |
+
- prometheus-data:/prometheus
|
| 34 |
+
command:
|
| 35 |
+
- '--config.file=/etc/prometheus/prometheus.yml'
|
| 36 |
+
- '--storage.tsdb.path=/prometheus'
|
| 37 |
+
restart: unless-stopped
|
| 38 |
+
depends_on:
|
| 39 |
+
- app
|
| 40 |
+
|
| 41 |
+
# Grafana for visualization
|
| 42 |
+
grafana:
|
| 43 |
+
image: grafana/grafana:latest
|
| 44 |
+
container_name: automl-grafana
|
| 45 |
+
ports:
|
| 46 |
+
- "3000:3000"
|
| 47 |
+
volumes:
|
| 48 |
+
- ./observability/grafana/provisioning:/etc/grafana/provisioning
|
| 49 |
+
- ./observability/grafana/dashboards:/var/lib/grafana/dashboards
|
| 50 |
+
- grafana-data:/var/lib/grafana
|
| 51 |
+
environment:
|
| 52 |
+
- GF_SECURITY_ADMIN_PASSWORD=admin
|
| 53 |
+
- GF_USERS_ALLOW_SIGN_UP=false
|
| 54 |
+
restart: unless-stopped
|
| 55 |
+
depends_on:
|
| 56 |
+
- prometheus
|
| 57 |
+
|
| 58 |
+
volumes:
|
| 59 |
+
prometheus-data:
|
| 60 |
+
grafana-data:
|
observability/prometheus/prometheus.yml
CHANGED
|
@@ -16,7 +16,7 @@ rule_files:
|
|
| 16 |
scrape_configs:
|
| 17 |
- job_name: 'prometheus'
|
| 18 |
static_configs:
|
| 19 |
-
- targets: ['
|
| 20 |
|
| 21 |
- job_name: 'fastapi-app'
|
| 22 |
metrics_path: '/metrics'
|
|
@@ -25,8 +25,3 @@ scrape_configs:
|
|
| 25 |
labels:
|
| 26 |
service: 'automl-api'
|
| 27 |
|
| 28 |
-
- job_name: 'node-exporter'
|
| 29 |
-
static_configs:
|
| 30 |
-
- targets: ['node-exporter:9100']
|
| 31 |
-
labels:
|
| 32 |
-
service: 'system-metrics'
|
|
|
|
| 16 |
scrape_configs:
|
| 17 |
- job_name: 'prometheus'
|
| 18 |
static_configs:
|
| 19 |
+
- targets: ['prometheus:9090']
|
| 20 |
|
| 21 |
- job_name: 'fastapi-app'
|
| 22 |
metrics_path: '/metrics'
|
|
|
|
| 25 |
labels:
|
| 26 |
service: 'automl-api'
|
| 27 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|