refactor(env): 重构环境变量加载方式,修复前端无法动态获取环境变量的问题
- 移除 Dockerfile 中的额外依赖安装 - 更新环境变量加载路径,使用统一的 get_root_folder() 函数 - 调整数据库连接、MinIO 访问等配置方式 - 移除 pyproject.toml 和 requirements.txt 中的冗余依赖 - 优化前端 MinIO 访问方式,通过后端 API 获取 MinIO URL
This commit is contained in:
parent
0640f973aa
commit
16f3e227d5
|
@ -11,10 +11,6 @@ COPY rag ./rag
|
|||
COPY graphrag ./graphrag
|
||||
COPY agentic_reasoning ./agentic_reasoning
|
||||
|
||||
# 安装额外依赖
|
||||
RUN uv pip install --no-cache-dir mysql-connector-python==9.2.0 -i https://pypi.tuna.tsinghua.edu.cn/simple
|
||||
RUN uv pip install --no-cache-dir redis==6.2.0 -i https://pypi.tuna.tsinghua.edu.cn/simple
|
||||
|
||||
|
||||
# 复制前端源代码目录
|
||||
COPY web ./web
|
||||
|
|
|
@ -0,0 +1,10 @@
|
|||
import os
|
||||
|
||||
|
||||
@manager.route("/endpoint", methods=["GET"]) # noqa: F821
|
||||
# @login_required
|
||||
def minio():
|
||||
"""
|
||||
Constructs the MinIO endpoint URL based on environment variables.
|
||||
"""
|
||||
return os.getenv("MINIO_VISIT_HOST", "localhost") + ":" + os.getenv("MINIO_PORT", "9000") + "/"
|
|
@ -1,10 +1,13 @@
|
|||
import os
|
||||
from minio import Minio
|
||||
from dotenv import load_dotenv
|
||||
from pathlib import Path
|
||||
|
||||
from dotenv import load_dotenv
|
||||
from minio import Minio
|
||||
|
||||
from api.root_path import get_root_folder
|
||||
|
||||
# 加载环境变量
|
||||
env_path = Path(__file__).parent.parent.parent / "docker" / ".env"
|
||||
env_path = Path(get_root_folder()) / "docker" / ".env"
|
||||
load_dotenv(env_path)
|
||||
|
||||
|
||||
|
|
|
@ -2,24 +2,30 @@ import logging
|
|||
import os
|
||||
import signal
|
||||
import sys
|
||||
import threading
|
||||
import time
|
||||
import traceback
|
||||
from concurrent.futures import ThreadPoolExecutor
|
||||
import threading
|
||||
from pathlib import Path
|
||||
|
||||
from dotenv import load_dotenv
|
||||
from werkzeug.serving import run_simple
|
||||
from api import settings
|
||||
|
||||
from api import settings, utils
|
||||
from api.apps import app
|
||||
from api.db.db_models import init_database_tables as init_web_db
|
||||
from api.db.runtime_config import RuntimeConfig
|
||||
from api.db.services.document_service import DocumentService
|
||||
from api import utils
|
||||
from api.db.db_models import init_database_tables as init_web_db
|
||||
from api.db.init_data import init_web_data
|
||||
from api.versions import get_ragflow_version
|
||||
from api.root_path import get_root_folder
|
||||
from api.utils import show_configs
|
||||
from api.utils.log_utils import initRootLogger
|
||||
from api.versions import get_ragflow_version
|
||||
from rag.settings import print_rag_settings
|
||||
from rag.utils.redis_conn import RedisDistributedLock
|
||||
|
||||
from api.utils.log_utils import initRootLogger
|
||||
# 加载环境变量
|
||||
env_path = Path(get_root_folder()) / "docker" / ".env"
|
||||
load_dotenv(env_path)
|
||||
|
||||
initRootLogger("ragflow_server")
|
||||
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
import os
|
||||
|
||||
|
||||
def get_root_folder():
|
||||
return os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
|
@ -25,7 +25,7 @@ from graphrag import search as kg_search
|
|||
from api.utils import get_base_config, decrypt_database_config
|
||||
from api.constants import RAG_FLOW_SERVICE_NAME
|
||||
|
||||
LIGHTEN = int(os.environ.get('LIGHTEN', "0"))
|
||||
LIGHTEN = int(os.environ.get("LIGHTEN", "0"))
|
||||
|
||||
LLM = None
|
||||
LLM_FACTORY = None
|
||||
|
@ -41,7 +41,7 @@ HOST_IP = None
|
|||
HOST_PORT = None
|
||||
SECRET_KEY = None
|
||||
|
||||
DATABASE_TYPE = os.getenv("DB_TYPE", 'mysql')
|
||||
DATABASE_TYPE = os.getenv("DB_TYPE", "mysql")
|
||||
DATABASE = decrypt_database_config(name=DATABASE_TYPE)
|
||||
|
||||
# authentication
|
||||
|
@ -62,8 +62,8 @@ kg_retrievaler = None
|
|||
|
||||
def init_settings():
|
||||
global LLM, LLM_FACTORY, LLM_BASE_URL, LIGHTEN, DATABASE_TYPE, DATABASE
|
||||
LIGHTEN = int(os.environ.get('LIGHTEN', "0"))
|
||||
DATABASE_TYPE = os.getenv("DB_TYPE", 'mysql')
|
||||
LIGHTEN = int(os.environ.get("LIGHTEN", "0"))
|
||||
DATABASE_TYPE = os.getenv("DB_TYPE", "mysql")
|
||||
DATABASE = decrypt_database_config(name=DATABASE_TYPE)
|
||||
LLM = get_base_config("user_default_llm", {})
|
||||
LLM_DEFAULT_MODELS = LLM.get("default_models", {})
|
||||
|
@ -86,36 +86,32 @@ def init_settings():
|
|||
EMBEDDING_MDL = EMBEDDING_MDL + (f"@{LLM_FACTORY}" if "@" not in EMBEDDING_MDL and EMBEDDING_MDL != "" else "")
|
||||
RERANK_MDL = RERANK_MDL + (f"@{LLM_FACTORY}" if "@" not in RERANK_MDL and RERANK_MDL != "" else "")
|
||||
ASR_MDL = ASR_MDL + (f"@{LLM_FACTORY}" if "@" not in ASR_MDL and ASR_MDL != "" else "")
|
||||
IMAGE2TEXT_MDL = IMAGE2TEXT_MDL + (
|
||||
f"@{LLM_FACTORY}" if "@" not in IMAGE2TEXT_MDL and IMAGE2TEXT_MDL != "" else "")
|
||||
IMAGE2TEXT_MDL = IMAGE2TEXT_MDL + (f"@{LLM_FACTORY}" if "@" not in IMAGE2TEXT_MDL and IMAGE2TEXT_MDL != "" else "")
|
||||
|
||||
global API_KEY, PARSERS, HOST_IP, HOST_PORT, SECRET_KEY
|
||||
API_KEY = LLM.get("api_key", "")
|
||||
PARSERS = LLM.get(
|
||||
"parsers",
|
||||
"naive:General,qa:Q&A,resume:Resume,manual:Manual,table:Table,paper:Paper,book:Book,laws:Laws,presentation:Presentation,picture:Picture,one:One,audio:Audio,knowledge_graph:Knowledge Graph,email:Email,tag:Tag")
|
||||
"naive:General,qa:Q&A,resume:Resume,manual:Manual,table:Table,paper:Paper,book:Book,laws:Laws,presentation:Presentation,picture:Picture,one:One,audio:Audio,knowledge_graph:Knowledge Graph,email:Email,tag:Tag",
|
||||
)
|
||||
|
||||
HOST_IP = get_base_config(RAG_FLOW_SERVICE_NAME, {}).get("host", "127.0.0.1")
|
||||
HOST_PORT = get_base_config(RAG_FLOW_SERVICE_NAME, {}).get("http_port")
|
||||
|
||||
SECRET_KEY = get_base_config(
|
||||
RAG_FLOW_SERVICE_NAME,
|
||||
{}).get("secret_key", str(date.today()))
|
||||
SECRET_KEY = get_base_config(RAG_FLOW_SERVICE_NAME, {}).get("secret_key", str(date.today()))
|
||||
|
||||
global AUTHENTICATION_CONF, CLIENT_AUTHENTICATION, HTTP_APP_KEY, GITHUB_OAUTH, FEISHU_OAUTH
|
||||
# authentication
|
||||
AUTHENTICATION_CONF = get_base_config("authentication", {})
|
||||
|
||||
# client
|
||||
CLIENT_AUTHENTICATION = AUTHENTICATION_CONF.get(
|
||||
"client", {}).get(
|
||||
"switch", False)
|
||||
CLIENT_AUTHENTICATION = AUTHENTICATION_CONF.get("client", {}).get("switch", False)
|
||||
HTTP_APP_KEY = AUTHENTICATION_CONF.get("client", {}).get("http_app_key")
|
||||
GITHUB_OAUTH = get_base_config("oauth", {}).get("github")
|
||||
FEISHU_OAUTH = get_base_config("oauth", {}).get("feishu")
|
||||
|
||||
global DOC_ENGINE, docStoreConn, retrievaler, kg_retrievaler
|
||||
DOC_ENGINE = os.environ.get('DOC_ENGINE', "elasticsearch")
|
||||
DOC_ENGINE = os.environ.get("DOC_ENGINE", "elasticsearch")
|
||||
lower_case_doc_engine = DOC_ENGINE.lower()
|
||||
if lower_case_doc_engine == "elasticsearch":
|
||||
docStoreConn = rag.utils.es_conn.ESConnection()
|
||||
|
|
|
@ -1,13 +1,16 @@
|
|||
import mysql.connector
|
||||
import os
|
||||
import redis
|
||||
from minio import Minio
|
||||
from dotenv import load_dotenv
|
||||
from elasticsearch import Elasticsearch
|
||||
from pathlib import Path
|
||||
|
||||
import mysql.connector
|
||||
import redis
|
||||
from dotenv import load_dotenv
|
||||
from elasticsearch import Elasticsearch
|
||||
from minio import Minio
|
||||
|
||||
from .root_path import get_root_folder
|
||||
|
||||
# 加载环境变量
|
||||
env_path = Path(__file__).parent.parent.parent / "docker" / ".env"
|
||||
env_path = Path(get_root_folder()) / "docker" / ".env"
|
||||
load_dotenv(env_path)
|
||||
|
||||
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
import os
|
||||
|
||||
|
||||
def get_root_folder():
|
||||
return os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
|
@ -126,9 +126,7 @@ dependencies = [
|
|||
"trio>=0.29.0",
|
||||
"langfuse>=2.60.0",
|
||||
"debugpy>=1.8.13",
|
||||
"mcp>=1.6.0",
|
||||
"mysql-connector-python==9.2.0",
|
||||
"redis==6.2.0"
|
||||
"mcp>=1.6.0"
|
||||
]
|
||||
|
||||
[project.optional-dependencies]
|
||||
|
|
|
@ -111,6 +111,4 @@ mini-racer>=0.12.4,<0.13.0
|
|||
pyodbc>=5.2.0,<6.0.0
|
||||
flasgger>=0.9.7.1,<0.10.0
|
||||
xxhash>=3.5.0,<4.0.0
|
||||
trio>=0.29.0
|
||||
mysql-connector-python==9.2.0
|
||||
redis==6.2.0
|
||||
trio>=0.29.0
|
|
@ -1,6 +1,8 @@
|
|||
import { Popover } from 'antd';
|
||||
import classNames from 'classnames';
|
||||
|
||||
import api from '@/utils/api';
|
||||
import { useEffect, useState } from 'react';
|
||||
import styles from './index.less';
|
||||
|
||||
interface IImage {
|
||||
|
@ -9,14 +11,20 @@ interface IImage {
|
|||
}
|
||||
|
||||
const ChunkImage = ({ id, className, ...props }: IImage) => {
|
||||
const host = process.env.MINIO_VISIT_HOST || 'localhost';
|
||||
const port = process.env.MINIO_PORT || '9000';
|
||||
const imgSrc = `http://${host}:${port}/${id}`;
|
||||
// 检查环境变量是否被正确读取
|
||||
console.log('MinIO Config:', {
|
||||
host: process.env.MINIO_VISIT_HOST,
|
||||
port: process.env.MINIO_PORT,
|
||||
});
|
||||
// const host = process.env.MINIO_VISIT_HOST || 'localhost';
|
||||
// const port = process.env.MINIO_PORT || '9000';
|
||||
// const imgSrc = `http://${host}:${port}/${id}`;
|
||||
const [imgSrc, setImgSrc] = useState<string>('');
|
||||
|
||||
useEffect(() => {
|
||||
fetch(api.minio_endpoint)
|
||||
.then((res) => res.text())
|
||||
.catch(() => 'http://localhost:9000')
|
||||
.then((minioUrl) => {
|
||||
console.log('Minio URL:', minioUrl);
|
||||
setImgSrc(`${minioUrl}/${id}`);
|
||||
});
|
||||
}, [setImgSrc, id]);
|
||||
|
||||
return (
|
||||
<img
|
||||
|
|
|
@ -3,6 +3,9 @@ let api_host = `/v1`;
|
|||
export { api_host };
|
||||
|
||||
export default {
|
||||
// Minio
|
||||
minio_endpoint: `${api_host}/minio/endpoint`,
|
||||
|
||||
// user
|
||||
login: `${api_host}/user/login`,
|
||||
logout: `${api_host}/user/logout`,
|
||||
|
|
Loading…
Reference in New Issue