docker-compose.yml (9784B)
1 services: 2 # ============================================================ 3 # Tempo - Distributed Tracing Backend 4 # ============================================================ 5 # Receives traces via OTLP and is queried through Grafana (no separate UI). 6 # Its metrics-generator derives RED metrics and service graphs from spans 7 # and remote-writes them to Prometheus, powering Traces Drilldown. 8 tempo: 9 image: grafana/tempo:latest 10 container_name: tempo 11 command: ["-config.file=/etc/tempo.yaml"] 12 volumes: 13 - ./tempo.yaml:/etc/tempo.yaml:ro 14 - tempo_data:/var/tempo 15 ports: 16 - "3200:3200" # Tempo query API 17 - "4317:4317" # OTLP gRPC receiver 18 - "4318:4318" # OTLP HTTP receiver 19 networks: 20 - app-network 21 restart: unless-stopped 22 23 # ============================================================ 24 # Prometheus - Metrics Backend 25 # ============================================================ 26 # Prometheus 3.0 receives metrics via OTLP HTTP push (no scrape targets needed) 27 prometheus: 28 image: prom/prometheus:v3.0.0 29 container_name: prometheus 30 command: 31 - '--config.file=/etc/prometheus/prometheus.yml' 32 - '--web.enable-otlp-receiver' 33 - '--web.enable-remote-write-receiver' # accepts Tempo's span metrics 34 - '--enable-feature=exemplar-storage' # trace exemplars on metrics 35 volumes: 36 - ./prometheus.yml:/etc/prometheus/prometheus.yml:ro 37 - prometheus_data:/prometheus 38 ports: 39 - "9090:9090" 40 networks: 41 - app-network 42 restart: unless-stopped 43 44 # ============================================================ 45 # Loki - Log Aggregation Backend 46 # ============================================================ 47 # Receives logs via OTLP HTTP from OpenTelemetry SDK 48 loki: 49 image: grafana/loki:3.0.0 50 container_name: loki 51 ports: 52 - "3100:3100" 53 volumes: 54 - ./loki-config.yaml:/etc/loki/local-config.yaml:ro 55 - loki_data:/loki 56 command: -config.file=/etc/loki/local-config.yaml 57 networks: 58 - app-network 59 restart: unless-stopped 60 61 # ============================================================ 62 # Grafana - Dashboards & Visualization 63 # ============================================================ 64 # Queries both Prometheus (metrics) and Tempo (traces). 65 # Datasources are provisioned from ./grafana/provisioning so they survive 66 # container recreates instead of living in the container's ephemeral DB. 67 grafana: 68 image: grafana/grafana:latest 69 container_name: grafana 70 volumes: 71 - ./grafana/provisioning:/etc/grafana/provisioning:ro 72 - grafana_data:/var/lib/grafana 73 ports: 74 - "3000:3000" 75 depends_on: 76 - prometheus 77 - tempo 78 - loki 79 networks: 80 - app-network 81 restart: unless-stopped 82 83 # ============================================================ 84 # Database Service 85 # ============================================================ 86 # PostgreSQL with automatic schema initialization 87 postgres: 88 image: postgres:17-alpine 89 container_name: opentel-postgres 90 environment: 91 - POSTGRES_USER=opentel_user 92 - POSTGRES_PASSWORD=opentel_pass 93 - POSTGRES_DB=opentel_db 94 ports: 95 - "5433:5432" 96 volumes: 97 - postgres_data:/var/lib/postgresql/data 98 # Schema initialization scripts run automatically on first startup 99 - ./schemas/init:/docker-entrypoint-initdb.d 100 healthcheck: 101 test: ["CMD-SHELL", "pg_isready -U opentel_user -d opentel_db"] 102 interval: 10s 103 timeout: 5s 104 retries: 5 105 start_period: 30s 106 networks: 107 - app-network 108 restart: unless-stopped 109 110 # ============================================================ 111 # Products Service 112 # ============================================================ 113 # RESTful API for product catalog (runs migrations on startup) 114 products: 115 build: 116 context: . 117 dockerfile: products/Dockerfile 118 container_name: products-service 119 ports: 120 - "3001:3001" 121 environment: 122 - APP_DATABASE_URL=postgres://opentel_user:opentel_pass@postgres:5432/opentel_db 123 - OTEL_EXPORTER_OTLP_TRACES_ENDPOINT=http://tempo:4317 124 - OTEL_EXPORTER_OTLP_METRICS_ENDPOINT=http://prometheus:9090/api/v1/otlp/v1/metrics 125 - OTEL_EXPORTER_OTLP_LOGS_ENDPOINT=http://loki:3100/otlp/v1/logs 126 - OTEL_SERVICE_NAME=products 127 - RUST_LOG=info,open_telemetry=off,otel::tracing=trace 128 depends_on: 129 postgres: 130 condition: service_healthy 131 tempo: 132 condition: service_started 133 prometheus: 134 condition: service_started 135 networks: 136 - app-network 137 restart: unless-stopped 138 139 # ============================================================ 140 # Inventory Service 141 # ============================================================ 142 # RESTful API for inventory and pricing management (runs migrations on startup) 143 inventory: 144 build: 145 context: . 146 dockerfile: inventory/Dockerfile 147 container_name: inventory-service 148 ports: 149 - "3002:3002" 150 environment: 151 - APP_DATABASE_URL=postgres://opentel_user:opentel_pass@postgres:5432/opentel_db 152 - OTEL_EXPORTER_OTLP_TRACES_ENDPOINT=http://tempo:4317 153 - OTEL_EXPORTER_OTLP_METRICS_ENDPOINT=http://prometheus:9090/api/v1/otlp/v1/metrics 154 - OTEL_EXPORTER_OTLP_LOGS_ENDPOINT=http://loki:3100/otlp/v1/logs 155 - OTEL_SERVICE_NAME=inventory 156 - RUST_LOG=info,open_telemetry=off,otel::tracing=trace 157 depends_on: 158 postgres: 159 condition: service_healthy 160 tempo: 161 condition: service_started 162 prometheus: 163 condition: service_started 164 networks: 165 - app-network 166 restart: unless-stopped 167 168 # ============================================================ 169 # Orders Service 170 # ============================================================ 171 # RESTful API for order management, checkout, and shipment tracking (runs migrations on startup) 172 orders: 173 build: 174 context: . 175 dockerfile: orders/Dockerfile 176 container_name: orders-service 177 ports: 178 - "3003:3003" 179 environment: 180 - APP_DATABASE_URL=postgres://opentel_user:opentel_pass@postgres:5432/opentel_db 181 - OTEL_EXPORTER_OTLP_TRACES_ENDPOINT=http://tempo:4317 182 - OTEL_EXPORTER_OTLP_METRICS_ENDPOINT=http://prometheus:9090/api/v1/otlp/v1/metrics 183 - OTEL_EXPORTER_OTLP_LOGS_ENDPOINT=http://loki:3100/otlp/v1/logs 184 - OTEL_SERVICE_NAME=orders 185 - RUST_LOG=info,open_telemetry=off,otel::tracing=trace 186 depends_on: 187 postgres: 188 condition: service_healthy 189 tempo: 190 condition: service_started 191 prometheus: 192 condition: service_started 193 networks: 194 - app-network 195 restart: unless-stopped 196 197 # ============================================================ 198 # Data Ingestion Service 199 # ============================================================ 200 # Loads initial data after products service runs migrations 201 # Note: Waits 10s after products starts to ensure migrations complete 202 data-ingestion: 203 build: 204 context: ./schemas 205 dockerfile: data/Dockerfile 206 container_name: data-ingestion 207 environment: 208 - DB_HOST=postgres 209 - DB_PORT=5432 210 - DB_NAME=opentel_db 211 - DB_USER=opentel_user 212 - DB_PASSWORD=opentel_pass 213 - WAIT_TIME=10 214 depends_on: 215 postgres: 216 condition: service_healthy 217 products: 218 condition: service_started 219 networks: 220 - app-network 221 restart: "no" # Run once and exit 222 223 # ============================================================ 224 # OtelMart Service 225 # ============================================================ 226 # Main e-commerce application (Rust backend + Angular frontend) 227 otelmart: 228 build: 229 context: . 230 dockerfile: otelmart/Dockerfile 231 container_name: otelmart 232 ports: 233 - "4200:4200" 234 environment: 235 - APP_DATABASE__URL=postgres://opentel_user:opentel_pass@postgres:5432/opentel_db 236 - APP_SERVICES__PRODUCTS_HOST=products 237 - APP_SERVICES__PRODUCTS_PORT=3001 238 - APP_SERVICES__INVENTORY_HOST=inventory 239 - APP_SERVICES__INVENTORY_PORT=3002 240 - APP_SERVICES__ORDERS_HOST=orders 241 - APP_SERVICES__ORDERS_PORT=3003 242 - APP_SERVICES__INVENTORY_SERVICE_URL=http://inventory:3002 243 - APP_SERVICES__ORDERS_SERVICE_URL=http://orders:3003 244 - OTEL_EXPORTER_OTLP_TRACES_ENDPOINT=http://tempo:4317 245 - OTEL_EXPORTER_OTLP_METRICS_ENDPOINT=http://prometheus:9090/api/v1/otlp/v1/metrics 246 - OTEL_EXPORTER_OTLP_LOGS_ENDPOINT=http://loki:3100/otlp/v1/logs 247 - OTEL_SERVICE_NAME=otelmart 248 - RUST_LOG=info,open_telemetry=off,otel::tracing=trace 249 extra_hosts: 250 - "host.docker.internal:host-gateway" 251 depends_on: 252 postgres: 253 condition: service_healthy 254 tempo: 255 condition: service_started 256 prometheus: 257 condition: service_started 258 data-ingestion: 259 condition: service_completed_successfully 260 products: 261 condition: service_started 262 inventory: 263 condition: service_started 264 orders: 265 condition: service_started 266 networks: 267 - app-network 268 restart: unless-stopped 269 270 # ============================================================ 271 # Networks 272 # ============================================================ 273 networks: 274 app-network: 275 driver: bridge 276 277 # ============================================================ 278 # Volumes 279 # ============================================================ 280 volumes: 281 postgres_data: 282 name: opentel_postgres_data 283 tempo_data: 284 name: opentel_tempo_data 285 prometheus_data: 286 name: opentel_prometheus_data 287 loki_data: 288 name: opentel_loki_data 289 grafana_data: 290 name: opentel_grafana_data