Repository navigation
Fix #29: restart policies and memory limits for the main compose - #39
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
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.
问题
主
docker-compose.yml三个服务都没有restart,也没有deploy.resources。API 是单容器部署,OOM/退出就直接 down;backend/Dockerfile用python:3.13-slim,镜像里没装 tini 之类,entrypoint 是sh backend/docker-entrypoint.sh,set -eu+exec链。注:issue 描述有两处与 main 不符(以代码为准)——demo 用的不是
deploy.restart_policy:deploy/instabox/compose.demo.yml的 API 实际写的是顶层restart: unless-stopped+mem_limit: 1g,UI 是restart: unless-stopped+mem_limit: 128m;local compose 也一样(另有 llm 服务mem_limit: 4g/cpus: 3.0)。仓库自己的惯例就是顶层键。主 compose 确实三个服务都没有 restart 和资源限制,这部分属实。修复
unless-stopped,三个服务都有。理由:与 demo/local 的既有惯例一致;它在 OOM(exit 137)、进程异常退出、宿主机重启、daemon 重启后都会恢复服务,而on-failure在宿主机重启后默认不会拉起容器。entrypoint 以exec "$@"结尾,uvicorn 就是 PID 1,信号能正常传递,restart 语义成立,不需要 tini。deploy.restart_policy/deploy.resources.limits(这是本次最关键的判断):这个栈是普通docker compose up部署,不是 swarm;deploy块在非 swarm 下会被静默忽略,写上去等于没写。真正生效的是顶层restart和mem_limit/cpus——demo/local 的写法已经证明了这一点。测试里也加了assert "deploy:" not in compose防止以后有人照抄 issue 的建议把死配置写回来。mem_limit: 1g——与 demo/local 里同一个镜像(同一个backend/Dockerfile、同一个 app)的 1g 完全一致;mem_limit: 128m——与 demo/local 里同一个 nginx 镜像的 128m 完全一致;mem_limit: 128m——caddy:2.10-alpine,与 UI nginx 同属轻量反向代理,仓库里没有 gateway 的先例,取与 UI 相同的 128m。cpus:demo/local 也没给 api/ui 设,保持最小改动;没加reservations:那也是 swarm 调度用的。验证
MEDGUIDE_MODE=test python -m pytest -q backend/tests523 passed(基线 521 + 2 新)。新增test_deployment_contracts.py的 2 个测试(_compose_service_blockhelper + 主 compose 断言 + demo/local 一致性断言),沿用该文件已有的字符串断言风格,没用 pyyaml——它不在backend/requirements.txt里,测试里 import 会在 CI 全新环境炸掉。.github/workflows/ci.yml的 compose job 是docker compose config --quiet(无环境变量);新增的键都是纯量值、无插值,不会破坏该校验。已知遗留
docker compose config/docker compose up的真实行为(包括 OOM 后是否自动拉起、mem_limit 是否生效)未跑过,需在有 Docker 的环境按 issue 复现步骤确认。Closes #29