-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathdocker-compose.yml
More file actions
173 lines (164 loc) · 5.17 KB
/
docker-compose.yml
File metadata and controls
173 lines (164 loc) · 5.17 KB
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
services:
# ============================================================================
# PostgreSQL with TimescaleDB Extension
# ============================================================================
timescaledb:
image: timescale/timescaledb:latest-pg16
container_name: fame-timescaledb
environment:
POSTGRES_DB: ${DB_NAME:-iiot_dqa}
POSTGRES_USER: ${DB_USER:-iiot_user}
POSTGRES_PASSWORD: ${DB_PASS:-iiot_password}
POSTGRES_INITDB_ARGS: "-c shared_preload_libraries=timescaledb"
ports:
- "${DB_PORT:-5432}:5432"
volumes:
# Database persistence
- timescaledb_data:/var/lib/postgresql/data
# Initialization scripts (executed in alphabetical order)
- ./database/init:/docker-entrypoint-initdb.d:ro
networks:
- fame-network
healthcheck:
test: ["CMD-SHELL", "pg_isready -U ${DB_USER:-iiot_user} -d ${DB_NAME:-iiot_dqa}"]
interval: 10s
timeout: 5s
retries: 5
start_period: 30s
restart: unless-stopped
# Performance tuning for TimescaleDB
command:
- "postgres"
- "-c"
- "max_connections=200"
- "-c"
- "shared_buffers=512MB"
- "-c"
- "effective_cache_size=2GB"
- "-c"
- "work_mem=16MB"
- "-c"
- "maintenance_work_mem=128MB"
- "-c"
- "checkpoint_completion_target=0.9"
- "-c"
- "wal_buffers=16MB"
- "-c"
- "random_page_cost=1.1"
- "-c"
- "effective_io_concurrency=200"
- "-c"
- "max_worker_processes=4"
- "-c"
- "max_parallel_workers_per_gather=2"
- "-c"
- "max_parallel_workers=4"
# ============================================================================
# Data Quality Worker Service
# ============================================================================
worker:
build:
context: .
dockerfile: worker/Dockerfile
container_name: fame-dqa-worker
environment:
# Database connection
DB_HOST: timescaledb
DB_PORT: 5432
DB_NAME: ${DB_NAME:-iiot_dqa}
DB_USER: ${DB_USER:-iiot_user}
DB_PASS: ${DB_PASS:-iiot_password}
# Worker configuration
AGGREGATION_INTERVAL_SECONDS: ${AGGREGATION_INTERVAL_SECONDS:-3600} # Default: 1 hour
ORIGINAL_FREQUENCY_SECONDS: ${ORIGINAL_FREQUENCY_SECONDS:-10} # Default: 10 seconds
ANOMALY_THRESHOLD_ZSCORE: ${ANOMALY_THRESHOLD_ZSCORE:-2.0} # Z-score threshold for anomaly detection
# Data ingestion settings
BATCH_SIZE: ${BATCH_SIZE:-1000} # Number of records to batch insert
WORKER_INTERVAL_SECONDS: ${WORKER_INTERVAL_SECONDS:-60} # How often worker runs aggregation
# Logging
LOG_LEVEL: ${LOG_LEVEL:-INFO}
PYTHONPATH: /app
depends_on:
timescaledb:
condition: service_healthy
networks:
- fame-network
volumes:
# Mount worker code for development (remove in production)
- ./worker:/app/worker:ro
- ./backend/config:/app/config:ro # Access to tags.csv if needed
restart: unless-stopped
healthcheck:
test: ["CMD-SHELL", "python -c 'import sys; sys.exit(0)'"]
interval: 30s
timeout: 10s
retries: 3
start_period: 60s
# ============================================================================
# FastAPI Backend Service
# ============================================================================
backend:
build:
context: .
dockerfile: backend/Dockerfile
container_name: fame-backend
ports:
- "8000:8000"
environment:
# Database connection (PostgreSQL instead of LeanXcale)
DB_HOST: timescaledb
DB_PORT: 5432
DB_NAME: ${DB_NAME:-iiot_dqa}
DB_USER: ${DB_USER:-iiot_user}
DB_PASS: ${DB_PASS:-iiot_password}
# Legacy env vars for backward compatibility (will be updated in code)
DB_IP: timescaledb
DB_PORT_LEGACY: 5432
# Application settings
OPENAI_API_KEY: ${OPENAI_API_KEY}
PYTHONPATH: /app
depends_on:
timescaledb:
condition: service_healthy
worker:
condition: service_started
networks:
- fame-network
volumes:
# Mount backend code for development hot-reload (remove in production)
- ./backend/api:/app/api:ro
- ./backend/core:/app/core:ro
- ./backend/models:/app/models:ro
- ./backend/schemas:/app/schemas:ro
- ./backend/main.py:/app/main.py:ro
- ./backend/config:/app/config:ro
restart: unless-stopped
healthcheck:
test: ["CMD-SHELL", "curl -f http://localhost:8000/health || exit 1"]
interval: 30s
timeout: 10s
retries: 3
start_period: 60s
# Frontend is run locally with npm for development
# Uncomment below for production deployment
# frontend:
# build:
# context: ./frontend
# dockerfile: Dockerfile
# container_name: fame-frontend
# ports:
# - "5173:5173"
# environment:
# - VITE_API_URL=http://localhost:8000
# depends_on:
# - backend
# networks:
# - fame-network
# restart: unless-stopped
volumes:
timescaledb_data:
driver: local
name: fame_timescaledb_data
networks:
fame-network:
driver: bridge