diff --git a/Dockerfile b/Dockerfile index df28213e..72931572 100644 --- a/Dockerfile +++ b/Dockerfile @@ -20,6 +20,14 @@ RUN npm ci \ && npm ci --prefix frontend \ && cd backend && uv sync +# Pre-seed the tiktoken BPE encodings at build time. CAMEL/OASIS token counting +# imports tiktoken, which otherwise downloads o200k_base/cl100k_base from +# openaipublic.blob.core.windows.net on first use — a runtime cloud dependency +# that crashes the simulation subprocess in offline or DNS-restricted +# environments. Baking them in keeps simulation runtime fully offline. +ENV TIKTOKEN_CACHE_DIR=/app/tiktoken_cache +RUN cd backend && uv run python -c "import tiktoken; tiktoken.get_encoding('o200k_base'); tiktoken.get_encoding('cl100k_base')" + # 复制项目源码 COPY . . diff --git a/backend/app/config.py b/backend/app/config.py index de706ca4..cdd7fe40 100644 --- a/backend/app/config.py +++ b/backend/app/config.py @@ -8,13 +8,22 @@ # Load .env file from project root # Path: MiroFish/.env (relative to backend/app/config.py) +# +# override=False is deliberate: real OS environment variables must win over the +# .env file. The Docker deployment feeds configuration into the container through +# the environment — docker-compose injects the vars from `.env` via `env_file:` +# (and NEO4J_URI must point at the compose service, e.g. bolt://neo4j:7687, not +# the localhost value that is only correct for native dev). With override=True a +# stray/baked .env would silently clobber that injection, so the backend would +# dial localhost inside the container and never reach the neo4j service. For +# native dev nothing changes: those vars aren't in the OS env, so .env still loads. project_root_env = os.path.join(os.path.dirname(__file__), '../../.env') if os.path.exists(project_root_env): - load_dotenv(project_root_env, override=True) + load_dotenv(project_root_env, override=False) else: # If no .env in root, try to load environment variables (for production) - load_dotenv(override=True) + load_dotenv(override=False) class Config: