2026-01-18 15:58:05 +08:00
|
|
|
|
version: '3.8'
|
|
|
|
|
|
|
|
|
|
|
|
services:
|
2026-01-21 23:21:36 +01:00
|
|
|
|
# PostgreSQL 数据库(使用最新版 17)
|
|
|
|
|
|
postgres:
|
2026-03-23 09:20:38 +08:00
|
|
|
|
image: m.daocloud.io/docker.io/pgvector/pgvector:pg17
|
2026-01-21 23:21:36 +01:00
|
|
|
|
container_name: life-echo-postgres
|
2026-02-14 13:36:17 +01:00
|
|
|
|
ports:
|
|
|
|
|
|
- "127.0.0.1:5432:5432" # 仅绑定 localhost,通过 SSH 隧道访问
|
2026-01-21 23:21:36 +01:00
|
|
|
|
environment:
|
|
|
|
|
|
POSTGRES_USER: ${POSTGRES_USER:-postgres}
|
|
|
|
|
|
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-postgres}
|
|
|
|
|
|
POSTGRES_DB: ${POSTGRES_DB:-life_echo}
|
|
|
|
|
|
volumes:
|
|
|
|
|
|
- postgres_data:/var/lib/postgresql/data
|
|
|
|
|
|
restart: always
|
|
|
|
|
|
healthcheck:
|
|
|
|
|
|
test: ["CMD-SHELL", "pg_isready -U postgres"]
|
|
|
|
|
|
interval: 10s
|
|
|
|
|
|
timeout: 5s
|
|
|
|
|
|
retries: 5
|
|
|
|
|
|
networks:
|
|
|
|
|
|
- life-echo-network
|
|
|
|
|
|
logging:
|
|
|
|
|
|
driver: "json-file"
|
|
|
|
|
|
options:
|
|
|
|
|
|
max-size: "10m"
|
|
|
|
|
|
max-file: "3"
|
|
|
|
|
|
|
2026-01-21 23:06:47 +01:00
|
|
|
|
# Redis 服务(用于会话存储和 Celery 消息队列)
|
|
|
|
|
|
redis:
|
2026-03-22 20:27:16 +08:00
|
|
|
|
image: m.daocloud.io/docker.io/library/redis:7-alpine
|
2026-01-21 23:06:47 +01:00
|
|
|
|
container_name: life-echo-redis
|
2026-01-27 23:18:53 +01:00
|
|
|
|
# ports:
|
|
|
|
|
|
# - "6379:6379" # 不暴露到宿主机,仅在 Docker 网络内部访问
|
2026-01-21 23:06:47 +01:00
|
|
|
|
volumes:
|
|
|
|
|
|
- redis_data:/data
|
|
|
|
|
|
command: redis-server --appendonly yes --maxmemory 256mb --maxmemory-policy allkeys-lru
|
|
|
|
|
|
restart: always
|
|
|
|
|
|
healthcheck:
|
|
|
|
|
|
test: ["CMD", "redis-cli", "ping"]
|
|
|
|
|
|
interval: 10s
|
|
|
|
|
|
timeout: 5s
|
|
|
|
|
|
retries: 5
|
|
|
|
|
|
networks:
|
|
|
|
|
|
- life-echo-network
|
|
|
|
|
|
logging:
|
|
|
|
|
|
driver: "json-file"
|
|
|
|
|
|
options:
|
|
|
|
|
|
max-size: "10m"
|
|
|
|
|
|
max-file: "3"
|
|
|
|
|
|
|
|
|
|
|
|
# FastAPI 应用
|
2026-03-23 13:21:07 +08:00
|
|
|
|
# 运行时统一读取 .env;部署时在远端将 .env.staging 或 .env.production 复制为 .env。
|
2026-01-18 15:58:05 +08:00
|
|
|
|
api:
|
|
|
|
|
|
build:
|
|
|
|
|
|
context: .
|
|
|
|
|
|
dockerfile: Dockerfile
|
|
|
|
|
|
image: life-echo-api:latest
|
|
|
|
|
|
container_name: life-echo-api-prod
|
2026-03-25 10:26:21 +08:00
|
|
|
|
# 独立 Caddy(宿主机或其它 compose)经 HTTPS 反代;仅绑定本机回环,避免与机上其它项目端口直接对公网。
|
|
|
|
|
|
# 若与 Cosmetic 等共用主机且 8000 已被占用,在 .env 中设置 LIFE_ECHO_API_HOST_PORT=其它端口并在 Caddyfile 中一致。
|
|
|
|
|
|
ports:
|
|
|
|
|
|
- "127.0.0.1:${LIFE_ECHO_API_HOST_PORT:-8000}:8000"
|
2026-01-18 15:58:05 +08:00
|
|
|
|
env_file:
|
2026-03-23 13:21:07 +08:00
|
|
|
|
- .env
|
2026-01-21 23:06:47 +01:00
|
|
|
|
environment:
|
2026-02-10 15:08:00 +08:00
|
|
|
|
- ASR_MODEL_CACHE_DIR=/app/models/whisper
|
2026-02-13 21:30:18 +01:00
|
|
|
|
volumes:
|
|
|
|
|
|
- /root/apiclient_key.pem:/app/certs/apiclient_key.pem:ro
|
2026-01-18 15:58:05 +08:00
|
|
|
|
restart: always
|
2026-01-21 23:06:47 +01:00
|
|
|
|
depends_on:
|
2026-01-21 23:21:36 +01:00
|
|
|
|
postgres:
|
|
|
|
|
|
condition: service_healthy
|
2026-01-21 23:06:47 +01:00
|
|
|
|
redis:
|
|
|
|
|
|
condition: service_healthy
|
2026-01-18 15:58:05 +08:00
|
|
|
|
healthcheck:
|
2026-01-18 17:09:10 +08:00
|
|
|
|
test: ["CMD", "python", "-c", "import http.client; conn = http.client.HTTPConnection('localhost', 8000); conn.request('GET', '/health'); r = conn.getresponse(); exit(0 if r.status == 200 else 1)"]
|
2026-01-18 15:58:05 +08:00
|
|
|
|
interval: 30s
|
|
|
|
|
|
timeout: 10s
|
|
|
|
|
|
retries: 3
|
2026-01-21 23:21:36 +01:00
|
|
|
|
start_period: 15s
|
2026-01-18 15:58:05 +08:00
|
|
|
|
networks:
|
|
|
|
|
|
- life-echo-network
|
2026-01-18 17:09:10 +08:00
|
|
|
|
logging:
|
|
|
|
|
|
driver: "json-file"
|
|
|
|
|
|
options:
|
|
|
|
|
|
max-size: "10m"
|
|
|
|
|
|
max-file: "3"
|
2026-01-21 23:06:47 +01:00
|
|
|
|
|
2026-02-11 18:34:22 +01:00
|
|
|
|
# Celery Worker(后台任务处理,禁用镜像内置的 8000 端口健康检查,改用 celery inspect ping)
|
2026-01-21 23:06:47 +01:00
|
|
|
|
celery-worker:
|
|
|
|
|
|
build:
|
|
|
|
|
|
context: .
|
|
|
|
|
|
dockerfile: Dockerfile
|
|
|
|
|
|
image: life-echo-api:latest
|
|
|
|
|
|
container_name: life-echo-celery-worker
|
2026-03-18 17:18:23 +08:00
|
|
|
|
command: uv run celery -A app.tasks.celery_app worker --loglevel=info --concurrency=4
|
2026-01-21 23:06:47 +01:00
|
|
|
|
env_file:
|
2026-03-23 13:21:07 +08:00
|
|
|
|
- .env
|
2026-01-21 23:06:47 +01:00
|
|
|
|
restart: always
|
|
|
|
|
|
depends_on:
|
2026-01-21 23:21:36 +01:00
|
|
|
|
postgres:
|
|
|
|
|
|
condition: service_healthy
|
2026-01-21 23:06:47 +01:00
|
|
|
|
redis:
|
|
|
|
|
|
condition: service_healthy
|
|
|
|
|
|
api:
|
|
|
|
|
|
condition: service_healthy
|
2026-02-11 18:34:22 +01:00
|
|
|
|
healthcheck:
|
2026-03-23 10:25:51 +08:00
|
|
|
|
test: ["CMD-SHELL", "uv run celery -A app.tasks.celery_app inspect ping --timeout 10 2>/dev/null | grep -q pong || exit 1"]
|
2026-02-11 18:34:22 +01:00
|
|
|
|
interval: 30s
|
|
|
|
|
|
timeout: 15s
|
|
|
|
|
|
retries: 3
|
|
|
|
|
|
start_period: 30s
|
2026-01-21 23:06:47 +01:00
|
|
|
|
networks:
|
|
|
|
|
|
- life-echo-network
|
|
|
|
|
|
logging:
|
|
|
|
|
|
driver: "json-file"
|
|
|
|
|
|
options:
|
|
|
|
|
|
max-size: "10m"
|
|
|
|
|
|
max-file: "3"
|
|
|
|
|
|
|
|
|
|
|
|
# Celery Beat(定时任务调度,可选)
|
|
|
|
|
|
# celery-beat:
|
|
|
|
|
|
# build:
|
|
|
|
|
|
# context: .
|
|
|
|
|
|
# dockerfile: Dockerfile
|
|
|
|
|
|
# image: life-echo-api:latest
|
|
|
|
|
|
# container_name: life-echo-celery-beat
|
2026-03-18 17:18:23 +08:00
|
|
|
|
# command: celery -A app.tasks.celery_app beat --loglevel=info
|
2026-01-21 23:06:47 +01:00
|
|
|
|
# env_file:
|
2026-03-23 13:21:07 +08:00
|
|
|
|
# - .env
|
2026-01-21 23:06:47 +01:00
|
|
|
|
# environment:
|
2026-01-21 23:21:36 +01:00
|
|
|
|
# - DATABASE_URL=postgresql://postgres:postgres@postgres:5432/life_echo
|
2026-01-21 23:06:47 +01:00
|
|
|
|
# - REDIS_URL=redis://redis:6379/0
|
|
|
|
|
|
# restart: always
|
|
|
|
|
|
# depends_on:
|
2026-01-21 23:21:36 +01:00
|
|
|
|
# postgres:
|
|
|
|
|
|
# condition: service_healthy
|
2026-01-21 23:06:47 +01:00
|
|
|
|
# redis:
|
|
|
|
|
|
# condition: service_healthy
|
|
|
|
|
|
# networks:
|
|
|
|
|
|
# - life-echo-network
|
|
|
|
|
|
|
|
|
|
|
|
# Flower(Celery 监控面板,可选)
|
|
|
|
|
|
# flower:
|
|
|
|
|
|
# build:
|
|
|
|
|
|
# context: .
|
|
|
|
|
|
# dockerfile: Dockerfile
|
|
|
|
|
|
# image: life-echo-api:latest
|
|
|
|
|
|
# container_name: life-echo-flower
|
2026-03-18 17:18:23 +08:00
|
|
|
|
# command: celery -A app.tasks.celery_app flower --port=5555
|
2026-01-21 23:06:47 +01:00
|
|
|
|
# ports:
|
|
|
|
|
|
# - "5555:5555"
|
|
|
|
|
|
# env_file:
|
2026-03-23 13:21:07 +08:00
|
|
|
|
# - .env
|
2026-01-21 23:06:47 +01:00
|
|
|
|
# environment:
|
|
|
|
|
|
# - REDIS_URL=redis://redis:6379/0
|
|
|
|
|
|
# restart: always
|
|
|
|
|
|
# depends_on:
|
|
|
|
|
|
# redis:
|
|
|
|
|
|
# condition: service_healthy
|
|
|
|
|
|
# networks:
|
|
|
|
|
|
# - life-echo-network
|
2026-01-18 15:58:05 +08:00
|
|
|
|
|
|
|
|
|
|
networks:
|
|
|
|
|
|
life-echo-network:
|
2026-01-28 12:59:03 +08:00
|
|
|
|
external: true
|
2026-01-28 16:05:05 +08:00
|
|
|
|
name: api_life-echo-network
|
2026-01-21 23:06:47 +01:00
|
|
|
|
|
|
|
|
|
|
volumes:
|
2026-01-21 23:21:36 +01:00
|
|
|
|
postgres_data:
|
|
|
|
|
|
driver: local
|
2026-01-21 23:06:47 +01:00
|
|
|
|
redis_data:
|
|
|
|
|
|
driver: local
|