调整环境变量配置,便于docker打包

This commit is contained in:
2026-02-09 15:31:21 +08:00
parent a41be9c362
commit a0987105dc
6 changed files with 35 additions and 38 deletions

View File

@@ -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 配置 (时序数据)

13
.env.local Normal file
View File

@@ -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"

View File

@@ -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")

View File

@@ -1 +0,0 @@
name: szh

View File

@@ -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"]

View File

@@ -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