diff --git a/.env.example b/.env.example index b780d15..b427aa4 100644 --- a/.env.example +++ b/.env.example @@ -1,6 +1,6 @@ # TJWater Server 环境变量配置模板 # 复制此文件为 .env 并填写实际值 - +NETWORK_NAME="szh" # ============================================ # 安全配置 (必填) # ============================================ @@ -16,20 +16,20 @@ ENCRYPTION_KEY= # ============================================ # 数据库配置 (PostgreSQL) # ============================================ -DB_NAME=tjwater -DB_HOST=localhost -DB_PORT=5432 -DB_USER=postgres -DB_PASSWORD=password +DB_NAME="tjwater" +DB_HOST="localhost" +DB_PORT="5432" +DB_USER="postgres" +DB_PASSWORD="password" # ============================================ # 数据库配置 (TimescaleDB) # ============================================ -TIMESCALEDB_DB_NAME=szh -TIMESCALEDB_DB_HOST=localhost -TIMESCALEDB_DB_PORT=5433 -TIMESCALEDB_DB_USER=tjwater -TIMESCALEDB_DB_PASSWORD=Tjwater@123456 +TIMESCALEDB_DB_NAME="szh" +TIMESCALEDB_DB_HOST="localhost" +TIMESCALEDB_DB_PORT="5433" +TIMESCALEDB_DB_USER="tjwater" +TIMESCALEDB_DB_PASSWORD="Tjwater@123456" # ============================================ # InfluxDB 配置 (时序数据) diff --git a/.env.local b/.env.local new file mode 100644 index 0000000..7e6e0ef --- /dev/null +++ b/.env.local @@ -0,0 +1,13 @@ +NETWORK_NAME="szh" + +DB_NAME="szh" +DB_HOST="192.168.1.114" +DB_PORT="5432" +DB_USER="tjwater" +DB_PASSWORD="Tjwater@123456" + +TIMESCALEDB_DB_NAME="szh" +TIMESCALEDB_DB_HOST="192.168.1.114" +TIMESCALEDB_DB_PORT="5433" +TIMESCALEDB_DB_USER="tjwater" +TIMESCALEDB_DB_PASSWORD="Tjwater@123456" \ No newline at end of file diff --git a/app/services/project_info.py b/app/services/project_info.py index 867a924..0a38481 100644 --- a/app/services/project_info.py +++ b/app/services/project_info.py @@ -1,22 +1,4 @@ import os -import yaml -# 获取当前项目根目录的路径 -_current_file = os.path.abspath(__file__) -project_root = os.path.dirname(os.path.dirname(os.path.dirname(_current_file))) - -# 尝试读取 .yml 或 .yaml 文件 -config_file = os.path.join(project_root, "configs", "project_info.yml") -if not os.path.exists(config_file): - config_file = os.path.join(project_root, "configs", "project_info.yaml") - -if not os.path.exists(config_file): - raise FileNotFoundError(f"未找到项目配置文件 (project_info.yaml 或 .yml): {os.path.dirname(config_file)}") - -with open(config_file, 'r', encoding='utf-8') as f: - _config = yaml.safe_load(f) - -if not _config or 'name' not in _config: - raise KeyError(f"项目配置文件中缺少 'name' 配置: {config_file}") - -name = _config['name'] +# 从环境变量 NETWORK_NAME 读取 +name = os.getenv("NETWORK_NAME") diff --git a/configs/project_info.yml b/configs/project_info.yml deleted file mode 100644 index 76f368b..0000000 --- a/configs/project_info.yml +++ /dev/null @@ -1 +0,0 @@ -name: szh diff --git a/infra/docker/Dockerfile b/infra/docker/Dockerfile index 3c0baa3..51571e0 100644 --- a/infra/docker/Dockerfile +++ b/infra/docker/Dockerfile @@ -1,13 +1,19 @@ -FROM python:3.12-slim +FROM continuumio/miniconda3:latest WORKDIR /app +# 安装 Python 3.12 和 pymetis (通过 conda-forge 避免编译问题) +RUN conda install -y -c conda-forge python=3.12 pymetis && \ + conda clean -afy + COPY requirements.txt . RUN pip install --no-cache-dir -r requirements.txt COPY app ./app -COPY resources ./resources +COPY .env . ENV PYTHONPATH=/app -CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000"] +EXPOSE 8000 + +CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000", "--workers", "4"] diff --git a/requirements.txt b/requirements.txt index 37a0686..234d2f0 100644 --- a/requirements.txt +++ b/requirements.txt @@ -95,7 +95,6 @@ prometheus_client==0.24.1 psycopg==3.2.5 psycopg-binary==3.2.5 psycopg-pool==3.3.0 -psycopg2==2.9.10 PuLP==3.1.1 py-key-value-aio==0.3.0 py-key-value-shared==0.3.0 @@ -157,8 +156,6 @@ starlette==0.50.0 threadpoolctl==3.6.0 tqdm==4.67.1 typer==0.21.1 -typing-inspection==0.4.0 -typing_extensions==4.12.2 tzdata==2025.2 urllib3==2.2.3 uvicorn==0.34.0