-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdocker-compose.yml
More file actions
126 lines (121 loc) · 3.98 KB
/
docker-compose.yml
File metadata and controls
126 lines (121 loc) · 3.98 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
services:
# PostgreSQL Database (NEW - Phase 1)
postgres:
image: postgres:15-alpine
container_name: vibration-postgres
restart: unless-stopped
environment:
POSTGRES_USER: ${POSTGRES_USER:-vibration}
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-vibration_pass}
POSTGRES_DB: ${POSTGRES_DB:-vibration_analysis}
volumes:
- postgres_data:/var/lib/postgresql/data
- ./scripts/init_postgres.sql:/docker-entrypoint-initdb.d/init.sql:ro
ports:
- "5432:5432"
healthcheck:
test: ["CMD-SHELL", "pg_isready -U vibration"]
interval: 10s
timeout: 5s
retries: 5
# Redis Cache (NEW - Phase 1)
redis:
image: redis:7.2-alpine
container_name: vibration-redis
restart: unless-stopped
command: redis-server --appendonly yes --requirepass ${REDIS_PASSWORD:-redis_pass}
volumes:
- redis_data:/data
ports:
- "6379:6379"
healthcheck:
test: ["CMD", "redis-cli", "--raw", "incr", "ping"]
interval: 10s
timeout: 5s
retries: 5
backend:
build:
context: ./backend
dockerfile: Dockerfile
container_name: vibration-backend
restart: unless-stopped
ports:
- "8081:8081"
volumes:
# Development: Mount backend source code for hot reload
- ./backend:/app/backend_src:ro
# Mount main.py separately for hot reload
- ./backend/main.py:/app/main.py:ro
# Mount realtime modules for hot reload
- ./backend/buffer_manager.py:/app/buffer_manager.py:ro
- ./backend/database_async.py:/app/database_async.py:ro
- ./backend/redis_client.py:/app/redis_client.py:ro
- ./backend/websocket_manager.py:/app/websocket_manager.py:ro
- ./backend/realtime_analyzer.py:/app/realtime_analyzer.py:ro
# Mount PHM analysis results
- ./phm_analysis_results:/app/phm_analysis_results:rw
# Mount database files (persistent storage) - Legacy SQLite
- ./backend/phm_data.db:/app/phm_data.db:rw
- ./backend/phm_temperature_data.db:/app/phm_temperature_data.db:rw
# Create volume for main database
- vibration_db:/app/vibration_analysis.db
environment:
- PYTHONPATH=/app
- PYTHONUNBUFFERED=1
# Legacy SQLite (existing)
- DATABASE_URL=sqlite:///./vibration_analysis.db
- PHM_DATABASE_PATH=/app/phm_data.db
- PHM_TEMPERATURE_DATABASE_PATH=/app/phm_temperature_data.db
# NEW - PostgreSQL & Redis (Phase 1)
- DATABASE_URL_POSTGRESQL=postgresql://vibration:vibration_pass@postgres:5432/vibration_analysis
- REDIS_URL=redis://:redis_pass@redis:6379/0
- ENABLE_REALTIME=true
- MAX_WEBSOCKET_CONNECTIONS=100
- SENSOR_BUFFER_SIZE=25600
- FEATURE_COMPUTATION_INTERVAL=1.0
# Existing
- API_HOST=0.0.0.0
- API_PORT=8081
command: uvicorn main:app --host 0.0.0.0 --port 8081 --reload
depends_on:
postgres:
condition: service_healthy
redis:
condition: service_healthy
healthcheck:
test: ["CMD", "python", "-c", "import urllib.request; urllib.request.urlopen('http://localhost:8081/')"]
interval: 30s
timeout: 10s
retries: 3
start_period: 40s
# 原始配置: 前端使用開發模式 (Vite dev server)
# 修改: 前端改為 nginx proxy service (生產模式)
frontend:
build:
context: ./frontend
dockerfile: Dockerfile
container_name: vibration-frontend
restart: unless-stopped
# 原始配置: "5173:5173" (Vite dev server)
# 修改: "80:80" → "18880:80" (使用冷門號碼避免與其他 container 衝突)
ports:
- "18880:80"
depends_on:
backend:
condition: service_healthy
healthcheck:
test: ["CMD", "wget", "--no-verbose", "--tries=1", "--spider", "http://localhost/"]
interval: 30s
timeout: 10s
retries: 3
start_period: 10s
volumes:
vibration_db:
driver: local
postgres_data:
driver: local
redis_data:
driver: local
networks:
default:
name: vibration-network