fix(docker): 容器内 import 路径与 ttsuser home 修正(liveness 长期红的下一层) - #82
Merged
Merged
Conversation
Signed-off-by: ReSerendipity <zengyangc@outlook.com> #80 把 Compose file validity 修绿后,Docker Smoke 暴露下一层: `Wait for liveness (ping 200, max 180s)` 失败,容器日志末行是 ModuleNotFoundError: No module named 'integrated_app' 两个叠加缺陷: 1. useradd -d /app 让 ttsuser 的 HOME=/app,于是 Python 的 user-site 是 /app/.local/lib/python3.12/site-packages;而镜像把 `pip install --user` 的产物放在 /home/ttsuser/.local(第 70 行 COPY、第 85 行 PATH 都按这个假设写)。 装上了但永远不在 sys.path 上 —— CMD 的 python -c 因此找不到包。 改为 useradd -m -d /home/ttsuser。 2. 更关键:即使走 site-packages 导入,app_server._PROJECT_ROOT = dirname(dirname(<pkg>/app_server.py)) 会算成 site-packages 里的路径, 而那是**只读镜像层**(冒烟用 --read-only 启动)—— data/outputs/logs 这些 compose 挂的可写卷全部落空,config.yaml 的 /app 挂载也接不上。 Dockerfile 第 77-79 行注释本来就声明要 "editable-style imports",只是没人 把 /app/app 放进 PYTHONPATH。补 ENV PYTHONPATH=/app/app 后 _PROJECT_ROOT 恰为 /app,与冒烟用例的 -v $PWD/smoke/data:/app/data 对齐。 与 #81 的相互作用(先查过再改):CSRF 密钥写失败从静默降级改成拒绝启动后, 若仍从只读 site-packages 导入就会直接起不来;修好导入路径才是让两者共存的前提。 冒烟侧 -v smoke/data:/app/data 且 chmod -R 777 smoke,可写,不会误触发硬失败。 本地无 docker 守护进程,判据是 Docker Smoke 作业本身(该环境已稳定复现原错误)。
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.
承接 #80:那条把
Compose file validity修成首次绿之后,Docker Smoke暴露了下一层 ——Wait for liveness (ping 200, max 180s)失败,容器日志末行:两个叠加缺陷
useradd -d /app让HOME=/app,Python 的 user-site 因此是/app/.local/lib/python3.12/site-packages,而镜像把pip install --user的产物 COPY 到/home/ttsuser/.local(第 70 行),PATH也按后者写(第 85 行)。装上了但从不在sys.path上。→ 改为-m -d /home/ttsuser。_PROJECT_ROOT会落进只读镜像层:app_server.py:55是dirname(dirname(_BASE_DIR))。若从 site-packages 导入,工程根算成~/.local/lib/python3.12一类路径;而冒烟用--read-only启动,data/、outputs/、logs/这些本该是 compose 挂的可写卷全部落空,-v .../config.yaml:/app/config.yaml:ro也接不上。Dockerfile 第 77-79 行的注释其实已经声明了意图("editable-style imports"),只是没人把/app/app放进PYTHONPATH。→ 补ENV PYTHONPATH=/app/app,此时_PROJECT_ROOT == /app,与docker run -v $PWD/smoke/data:/app/data对齐。与 #81 的关系(先查证才动手)
#81 把「CSRF 密钥写不进盘」从静默降级(空密钥 = 防护关闭)改成拒绝启动。如果继续从只读 site-packages 导入,#81 一合容器就必然起不来——所以这条导入路径修的是前提,不是并列项。已核实冒烟侧不会误伤:
smoke/data有 bind mount 且chmod -R 777 smoke,TTS_AUTO_LOAD_MODEL=0。验证边界
本机没有 docker 守护进程(
docker version连不上 npipe、无 compose 插件),无法推送前复现。判据是本 PR 上Docker Smoke的Wait for liveness步骤——它此前从未绿过。若这步绿了,后面Probe readiness / auth / metrics / read-only rootfs四步是首次被执行,可能再暴露新东西(那属于下一条,不假装这次全清)。