迁移 PostgreSQL 并新增 Python API 服务

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
fish
2026-05-03 14:58:01 +08:00
parent 750584e619
commit 220f4acc45
10 changed files with 333 additions and 123 deletions

View File

@@ -1,12 +1,29 @@
services:
postgres:
image: postgres:18.3-alpine3.23
environment:
POSTGRES_USER: trade
POSTGRES_PASSWORD: trade
POSTGRES_DB: futures
volumes:
- pgdata:/var/lib/postgresql/data
healthcheck:
test: ["CMD-SHELL", "pg_isready -U trade -d futures"]
interval: 5s
timeout: 5s
retries: 5
tushare:
build: ./tushare
env_file: ./tushare/.env
environment:
- DB_PATH=/app/data/futures.db
volumes:
- ./data:/app/data
command: ["python", "-m", "src.main"]
- DATABASE_URL=postgresql://trade:trade@postgres:5432/futures
depends_on:
postgres:
condition: service_healthy
ports:
- "8000:8000"
command: ["uvicorn", "src.api:app", "--host", "0.0.0.0", "--port", "8000"]
web:
build:
@@ -15,14 +32,15 @@ services:
env_file: ./web/backend/.env
environment:
- LISTEN_ADDR=:8080
- FUTURES_DB_PATH=/app/data/futures.db
- DATABASE_URL=postgres://trade:trade@postgres:5432/futures?sslmode=disable
- AUTH_DB_PATH=/app/auth/auth.db
volumes:
# futures.db 由 tushare 写入,web 端通过 DSN mode=ro&query_only 只读访问;
# 不在容器层加 :ro,因为 WAL 模式下读访问也需要写 -shm 同步文件
- ./data:/app/data
# auth.db 由 web 自己写,落在 ./data/auth.db (已被 .gitignore)
- ./data:/app/auth
depends_on:
- postgres
ports:
- "8080:8080"
volumes:
- ./data:/app/auth
restart: unless-stopped
volumes:
pgdata: