fix(docker): 修复容器中 Playwright 浏览器路径与权限不一致导致启动失败#373
Conversation
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! 此拉取请求旨在解决 Docker 容器中 Playwright 浏览器因路径不一致和权限不足而无法启动的问题。通过标准化 Playwright 浏览器的安装路径、确保在运行时环境中直接安装浏览器,并为非 root 用户 Highlights
Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: bca233e408
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| netcat-openbsd \ | ||
| telnet \ | ||
| && playwright install-deps chromium \ | ||
| && playwright install chromium \ |
There was a problem hiding this comment.
Eliminate duplicate Chromium download during docker build
Dockerfile now installs Chromium again in the runtime stage (playwright install chromium), while the builder stage still performs the same install (RUN playwright install chromium at line 25), so every image build downloads the browser twice. This significantly slows CI/build times and adds an unnecessary external network failure point without improving runtime correctness; keep only one install path (either reuse builder output or remove the builder install).
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Code Review
本次变更旨在修复 Docker 容器中因 Playwright 浏览器路径与权限不一致导致的启动失败问题。您通过以下方式解决了此问题:
- 为 Playwright 浏览器设置了一个固定的、非用户主目录的路径
/ms-playwright。 - 在最终镜像阶段直接安装浏览器及其依赖,而不是从构建器阶段复制。
- 为新的浏览器路径
/ms-playwright设置了正确的用户权限,确保appuser可以访问。
这些改动逻辑清晰,有效地解决了描述的问题。我有一个小建议,即在 Dockerfile 中使用 --with-deps 标志来简化浏览器安装命令,将依赖安装和浏览器下载合并为一步。总体而言,这是一次不错的修复。
| && playwright install-deps chromium \ | ||
| && playwright install chromium \ |
Motivation
BrowserType.launch: Executable doesn't exist at /root/.cache/ms-playwright/...,其根因是构建期/运行期浏览器缓存路径与运行用户不一致且运行镜像未确保浏览器二进制可用。appuser可访问,避免启动失败与版本漂移问题。Description
PLAYWRIGHT_BROWSERS_PATH改为固定全局路径/ms-playwright,避免依赖/root或其它用户主目录。playwright install chromium,确保浏览器二进制在运行层被安装并与 Playwright 版本匹配。/root/.cache/ms-playwright的操作,改为在运行镜像中本地安装浏览器并对/ms-playwright目录执行chown使appuser可读写。playwrightCLI 可用并维持原有运行时结构。Testing
rg -n "playwright|BrowserType.launch|chromium|ms-playwright|install"与查看Dockerfile/src/scraper.py),确认引用点与修复位置,检查通过。docker compose -f docker-compose.dev.yaml config以验证 compose 配置,但本环境没有 Docker CLI(command not found: docker),因此未能在本地构建或启动镜像。docker compose build --no-cache app和docker compose up -d并触发一次任务以完成端到端验证。Codex Task