调整环境变量配置,便于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,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")