File size: 6,486 Bytes
ba0fd0f
6779f5f
ba0fd0f
 
6779f5f
 
 
 
 
 
 
ba0fd0f
 
6779f5f
 
 
 
ba0fd0f
 
 
6779f5f
 
ba0fd0f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6779f5f
ba0fd0f
 
 
 
 
 
 
 
 
 
 
 
6779f5f
ba0fd0f
 
 
 
 
6779f5f
ba0fd0f
 
 
6779f5f
ba0fd0f
6779f5f
ba0fd0f
 
 
 
 
 
 
6779f5f
ba0fd0f
 
6779f5f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ba0fd0f
 
 
6779f5f
 
 
 
 
 
 
 
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
# =============================================================================
# OmniDiag β€” Docker Compose (v2.0 β€” Full MLOps Stack)
# =============================================================================
# Services:
#   postgres    β€” PostgreSQL 15 database (primary datastore)
#   redis       β€” Redis 7 cache
#   backend     β€” FastAPI application (port 7860)
#   mlflow      β€” MLflow tracking server (port 5000)
#   prometheus  β€” Prometheus metrics scraper (port 9090)
#   grafana     β€” Grafana dashboard (port 3001)
#   retrain     β€” One-shot retrain container (runs on demand)
#
# Usage:
#   docker compose up -d postgres redis                     # infra only
#   docker compose up -d                                    # full stack
#   docker compose run --rm retrain --disease heart_disease # manual retrain
#   docker compose down -v                                  # wipe volumes
# =============================================================================

services:

  # ── PostgreSQL Database ──────────────────────────────────────────────────────
  postgres:
    image: postgres:15-alpine
    container_name: omnidiag-postgres
    restart: unless-stopped
    environment:
      POSTGRES_USER: omnidiag
      POSTGRES_PASSWORD: omnidiag_pass
      POSTGRES_DB: omnidiag_db
    ports:
      - "5432:5432"
    volumes:
      - postgres_data:/var/lib/postgresql/data
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U omnidiag"]
      interval: 10s
      timeout: 5s
      retries: 5
      start_period: 10s

  # ── Redis Cache ──────────────────────────────────────────────────────────────
  redis:
    image: redis:7-alpine
    container_name: omnidiag-redis
    restart: unless-stopped
    ports:
      - "6379:6379"
    healthcheck:
      test: ["CMD", "redis-cli", "ping"]
      interval: 10s
      timeout: 5s
      retries: 5

  # ── FastAPI Backend ──────────────────────────────────────────────────────────
  backend:
    build: .
    container_name: omnidiag-backend
    restart: unless-stopped
    ports:
      - "7860:7860"
    environment:
      - DATABASE_URL=postgresql+asyncpg://omnidiag:omnidiag_pass@postgres:5432/omnidiag_db
      - REDIS_URL=redis://redis:6379
      - MLFLOW_TRACKING_URI=http://mlflow:5000
      - CORS_ALLOWED_ORIGINS=http://localhost:5173,http://localhost:3000
      - JWT_SECRET_KEY=${JWT_SECRET_KEY:-change-me-in-production}
    depends_on:
      postgres:
        condition: service_healthy
      redis:
        condition: service_healthy
    volumes:
      - .:/app
      - model_cache:/app/models
    command: uvicorn backend.main:app --host 0.0.0.0 --port 7860

  # ── MLflow Tracking Server ───────────────────────────────────────────────────
  mlflow:
    image: python:3.11-slim
    container_name: omnidiag-mlflow
    restart: unless-stopped
    ports:
      - "5000:5000"
    volumes:
      - mlflow_data:/mlruns
    command: >
      sh -c "pip install mlflow psycopg2-binary -q &&
             mlflow server
               --host 0.0.0.0
               --port 5000
               --backend-store-uri sqlite:///mlruns/mlruns.db
               --default-artifact-root /mlruns/artifacts"
    healthcheck:
      test: ["CMD", "curl", "-f", "http://localhost:5000/health"]
      interval: 30s
      timeout: 10s
      retries: 3
      start_period: 30s

  # ── Prometheus ───────────────────────────────────────────────────────────────
  prometheus:
    image: prom/prometheus:v2.51.0
    container_name: omnidiag-prometheus
    restart: unless-stopped
    ports:
      - "9090:9090"
    volumes:
      - ./deploy/prometheus.yml:/etc/prometheus/prometheus.yml:ro
      - prometheus_data:/prometheus
    command:
      - --config.file=/etc/prometheus/prometheus.yml
      - --storage.tsdb.path=/prometheus
      - --storage.tsdb.retention.time=30d
      - --web.enable-lifecycle
    depends_on:
      - backend

  # ── Grafana ──────────────────────────────────────────────────────────────────
  grafana:
    image: grafana/grafana:10.4.0
    container_name: omnidiag-grafana
    restart: unless-stopped
    ports:
      - "3001:3000"
    environment:
      - GF_SECURITY_ADMIN_USER=admin
      - GF_SECURITY_ADMIN_PASSWORD=${GRAFANA_PASSWORD:-omnidiag_grafana}
      - GF_USERS_ALLOW_SIGN_UP=false
      - GF_DASHBOARDS_DEFAULT_HOME_DASHBOARD_PATH=/etc/grafana/dashboards/omnidiag.json
    volumes:
      - grafana_data:/var/lib/grafana
      - ./deploy/grafana/datasources:/etc/grafana/provisioning/datasources:ro
      - ./deploy/grafana/dashboards:/etc/grafana/provisioning/dashboards:ro
      - ./deploy/grafana/dashboards:/etc/grafana/dashboards:ro
    depends_on:
      - prometheus

  # ── Auto-Retrain (on-demand / cron) ─────────────────────────────────────────
  retrain:
    build: .
    container_name: omnidiag-retrain
    profiles:
      - retrain
    environment:
      - DATABASE_URL=postgresql+asyncpg://omnidiag:omnidiag_pass@postgres:5432/omnidiag_db
      - MLFLOW_TRACKING_URI=http://mlflow:5000
    depends_on:
      postgres:
        condition: service_healthy
      mlflow:
        condition: service_healthy
    volumes:
      - .:/app
      - model_cache:/app/models
    entrypoint: ["python", "scripts/retrain.py"]
    command: ["--disease", "heart_disease"]

# ── Named Volumes ─────────────────────────────────────────────────────────────
volumes:
  postgres_data:
    driver: local
  mlflow_data:
    driver: local
  prometheus_data:
    driver: local
  grafana_data:
    driver: local
  model_cache:
    driver: local