Repository navigation
Fix #20: fail fast in the API entrypoint when production deps are missing - #33
Open
xiaoyao-666-coder wants to merge 2 commits into
Open
xiaoyao-666-coder wants to merge 2 commits into
xiaoyao-666-coder wants to merge 2 commits into
Conversation
… deps are missing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
问题
主 compose 缺必填外部依赖时,API 容器起来了但
/api/ready永远不 healthy,于是 UI(depends_on: service_healthy)和网关永远不启动,整站永久不 healthy,且没有任何明确报错。修复
只做 API 入口 fail-fast,不做 compose
${VAR:?}:backend/docker-entrypoint.sh:新增一个 production-only 的 Python 预检块,放在已有 CIDR 校验之前、ingestion/服务启动之前;缺失时一次性列出所有缺失变量(各附一句原因)+ 指引(补.env,参考.env.template,重跑docker compose up --build -d),exit 1。生产必填:OPENAI_API_KEY、OPENAI_MODEL、REDIS_URL、MILVUS_URI(仅 milvus 后端,缺省即 milvus)、MEDGUIDE_AUTH_DSN(除非显式选 SQLite 认证:MEDGUIDE_AUTH_BACKEND=sqlite+MEDGUIDE_ALLOW_SQLITE_AUTH=true)。${VAR:?},三个理由:MILVUS_URI只在 milvus 后端必填、MEDGUIDE_AUTH_DSN有 SQLite escape hatch,compose 插值没有条件语法,会误拦合法部署;CI 的docker compose config --quiet在无任何环境变量下跑,${VAR:?}会让它直接失败;入口检查只在生产模式生效,local/offline/test 不受影响。README.md:部署章节加一句话,说明 API 容器启动前会校验上述必填依赖。OPENAI_BASE_URL(代码里缺省走 api.openai.com,要求它会破坏纯 OpenAI 部署)、MYSQL_DSN(缺了只禁用结构化查询,是设计好的降级)、MEDGUIDE_API_TOKENS(只在MEDGUIDE_REQUIRE_PROXY_TOKEN设置时才需要)。验证
MEDGUIDE_MODE=test python -m pytest -q backend/tests525 passed(基线 521 + 4 新,test_deployment_contracts.py,真实跑入口脚本、环境从零构造)。env -i干净环境):生产模式无任何变量 → exit 1,一次列出全部 5 个缺失变量;只设OPENAI_API_KEY/OPENAI_MODEL→ exit 1,只列剩下的 3 个;依赖齐全 → exit 0;test 模式无配置 → exit 0。docker-compose.yml、demo、local 三个 compose 文件 pyyaml 解析均合法;sh -n语法检查通过;CI 的docker compose config --quiet不受影响。已知遗留
docker compose up的真实端到端行为(包括“缺依赖时 API 容器立即退出、UI/网关不再永久 unhealthy”的完整链路),需在有 Docker 的环境按 issue 复现步骤确认。OPENAI_BASE_URL,但入口校验不要求它(纯 OpenAI 部署不需要);如认为文档应与校验严格一致,需另改 README 措辞。Closes #20