2f0cc3899e
CI/CD Pipeline / Check if frontend-only change (pull_request) Successful in 21s
CI/CD Pipeline / Validate - Type Check (mypy) (pull_request) Successful in 1m12s
CI/CD Pipeline / Validate - Migration (alembic) (pull_request) Successful in 1m4s
CI/CD Pipeline / Frontend Lint (pull_request) Successful in 47s
CI/CD Pipeline / Build Staging API Image (pull_request) Has been skipped
CI/CD Pipeline / Build Staging Web Image (pull_request) Has been skipped
CI/CD Pipeline / Build Staging Worker Image (pull_request) Has been skipped
CI/CD Pipeline / PR Build Web Image (pull_request) Successful in 37s
PR Automation / Auto Merge on CI Green + Approved (pull_request) Successful in 1m15s
Preview Deploy / Deploy Preview Environment (pull_request) Failing after 54s
CI/CD Pipeline / Frontend Unit Tests (pull_request) Has been skipped
CI/CD Pipeline / Build Production API Image (pull_request) Has been skipped
CI/CD Pipeline / Build Production Web Image (pull_request) Has been skipped
CI/CD Pipeline / Build Production Worker Image (pull_request) Has been skipped
CI/CD Pipeline / Deploy Staging (Watchtower auto-deploy) (pull_request) Has been skipped
CI/CD Pipeline / Deploy Production (pull_request) Has been skipped
CI/CD Pipeline / Staging E2E Tests (pull_request) Has been skipped
CI/CD Pipeline / Staging API Integration Tests (pull_request) Has been skipped
CI/CD Pipeline / ACR Image Cleanup (pull_request) Has been skipped
CI/CD Pipeline / Production Browser E2E (pull_request) Has been skipped
PR Automation / Auto Approve on CI Green (pull_request) Successful in 3m48s
AI Code Review / AI Code Review (pull_request) Successful in 4m4s
CI/CD Pipeline / Integration Tests (pull_request) Successful in 3m2s
CI/CD Pipeline / PR Build API Image (pull_request) Successful in 6m17s
CI/CD Pipeline / PR Build Worker Image (pull_request) Successful in 12m19s
CI/CD Pipeline / Validate - Code Quality (pull_request) Failing after 1m22s
CI/CD Pipeline / Unit Tests (pull_request) Successful in 5m32s
Preview Cleanup / Cleanup Preview Environment (pull_request) Successful in 12s
核心改动: - SharedSettings 作为统一配置基类,所有通用配置只定义一次 - API Settings 继承 SharedSettings,只保留 API 特有字段(JWT/SMTP/CORS/渲染引擎等) - Worker Settings 继承 SharedSettings,只保留 Worker 特有字段(并发数等) - 统一数据库连接池默认值:max_overflow=10(API端合理值,两端一致) - 统一 OSS 直传配置:max_mb/expire_seconds 从 API 提到 SharedSettings - 新增 CosyVoice/豆包等 AI 配置的统一管理 - 保留 UPPER_CASE property 别名,100% 向后兼容 收益: - 消除 3 套配置系统的重复定义(DB/Redis/Celery/OSS 等 20+ 字段) - 彻底解决默认值不一致问题 - 新增通用配置只需改 SharedSettings 一处 - 全量 4305 单测通过
91 lines
4.1 KiB
Python
Executable File
91 lines
4.1 KiB
Python
Executable File
"""统一配置入口 — API 和 Worker 共享的基础配置。
|
||
|
||
所有服务通用配置定义在这里,两端各自的 Settings 类继承本类,
|
||
只追加服务特有字段。彻底消除重复定义和默认值不一致问题。
|
||
"""
|
||
|
||
import os
|
||
from typing import Optional
|
||
|
||
from pydantic_settings import BaseSettings, SettingsConfigDict
|
||
|
||
|
||
class SharedSettings(BaseSettings):
|
||
"""所有服务共享的基础配置。
|
||
|
||
API 和 Worker 都继承本类,确保:
|
||
1. 数据库/Redis/OSS/Celery 等核心配置默认值一致
|
||
2. 环境变量命名统一(小写风格,pydantic-settings 自动兼容大写)
|
||
3. 单例模式和 env 文件加载逻辑只实现一次
|
||
"""
|
||
|
||
# ── 环境 ──────────────────────────────────────────────────────────────
|
||
environment: str = "development"
|
||
debug: bool = True
|
||
auto_create_schema: bool = False
|
||
|
||
# ── 数据库 ────────────────────────────────────────────────────────────
|
||
database_url: str = "postgresql+psycopg://postgres:postgres@localhost:5432/xiaoxia_saas"
|
||
database_pool_size: int = 20
|
||
database_max_overflow: int = 10 # pool_size(20) + max_overflow(10) = 最大30连接
|
||
database_pool_timeout: int = 30
|
||
database_pool_recycle: int = 3600
|
||
|
||
# ── Redis ────────────────────────────────────────────────────────────
|
||
redis_url: str = "redis://localhost:6379/0"
|
||
|
||
# ── Celery ───────────────────────────────────────────────────────────
|
||
celery_broker_url: str = "redis://localhost:6379/0"
|
||
celery_result_backend: str = "redis://localhost:6379/1"
|
||
|
||
# ── OSS 阿里云 ──────────────────────────────────────────────────────
|
||
oss_endpoint: str = "oss-cn-hangzhou.aliyuncs.com"
|
||
oss_access_key_id: str = ""
|
||
oss_access_key_secret: str = ""
|
||
oss_bucket_name: str = "xiaoxia-autocut"
|
||
oss_direct_upload_max_mb: int = 2000
|
||
oss_direct_upload_expire_seconds: int = 900
|
||
|
||
# ── CosyVoice (阿里云百炼语音合成) ───────────────────────────────────
|
||
cosyvoice_api_key: str = ""
|
||
cosyvoice_base_url: str = "https://dashscope.aliyuncs.com/api/v1"
|
||
cosyvoice_model: str = "cosyvoice-v3-flash"
|
||
cosyvoice_voice: str = "longxiaochun_v3" # 默认音色(v3 系列系统音色带 _v3 后缀)
|
||
cosyvoice_sample_rate: int = 22050
|
||
cosyvoice_format: str = "mp3" # 输出格式:mp3/wav/pcm
|
||
# 音色克隆模型名(固定为 voice-enrollment)
|
||
cosyvoice_clone_model: str = "voice-enrollment"
|
||
|
||
# ── 豆包大模型(火山引擎方舟) ────────────────────────────────────────
|
||
doubao_api_key: str = ""
|
||
doubao_model: str = "doubao-seed-1-6-250615"
|
||
doubao_base_url: str = "https://ark.cn-beijing.volces.com/api/v3"
|
||
doubao_timeout: int = 30
|
||
doubao_max_retries: int = 2
|
||
|
||
model_config = SettingsConfigDict(
|
||
env_file=".env",
|
||
env_file_encoding="utf-8",
|
||
case_sensitive=False,
|
||
extra="ignore",
|
||
)
|
||
|
||
|
||
_settings: Optional[SharedSettings] = None
|
||
|
||
|
||
def get_shared_settings() -> SharedSettings:
|
||
"""获取共享配置单例。
|
||
|
||
优先读取 APP_ENV 指定的环境文件(.env.{env}),不存在则读 .env。
|
||
"""
|
||
global _settings
|
||
if _settings is None:
|
||
env = os.getenv("APP_ENV", "development")
|
||
env_file = f".env.{env}" if env != "development" else ".env"
|
||
if os.path.exists(env_file):
|
||
_settings = SharedSettings(_env_file=env_file)
|
||
else:
|
||
_settings = SharedSettings()
|
||
return _settings
|