From a8a7b62f76aa3452b0ca836cf0c1bfab29e2dcab Mon Sep 17 00:00:00 2001 From: passthem Date: Tue, 18 Nov 2025 02:22:35 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=20playwright=20=E5=9C=A8?= =?UTF-8?q?=E4=B8=8D=E5=90=8C=E6=BA=90=E7=9A=84=E7=89=88=E6=9C=AC=E4=B8=8D?= =?UTF-8?q?=E5=90=8C=E5=AF=BC=E8=87=B4=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .drone.yml | 8 ++++++++ Dockerfile | 7 ++----- scripts/test_playwright.py | 15 +++++++++++++++ 3 files changed, 25 insertions(+), 5 deletions(-) create mode 100644 scripts/test_playwright.py diff --git a/.drone.yml b/.drone.yml index 7593379..06ac577 100644 --- a/.drone.yml +++ b/.drone.yml @@ -38,6 +38,14 @@ steps: path: /var/run/docker.sock commands: - docker run --rm gitea.service.jazzwhom.top/mttu-developers/konabot:nightly-${DRONE_COMMIT_SHA} python scripts/test_plugin_load.py + - name: 在容器中测试 Playwright 工作正常 + image: docker:dind + privileged: true + volumes: + - name: docker-socket + path: /var/run/docker.sock + commands: + - docker run --rm gitea.service.jazzwhom.top/mttu-developers/konabot:nightly-${DRONE_COMMIT_SHA} python scripts/test_playwright.py - name: 发送构建结果到 ntfy image: parrazam/drone-ntfy when: diff --git a/Dockerfile b/Dockerfile index 9ed4c19..7e0944e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -18,11 +18,6 @@ RUN apt-get update && \ fonts-noto-color-emoji \ && rm -rf /var/lib/apt/lists/* -RUN pip install --no-cache-dir playwright \ - && python -m playwright install chromium \ - && pip uninstall -y playwright - - FROM base AS builder @@ -46,6 +41,8 @@ COPY --from=builder ${VIRTUAL_ENV} ${VIRTUAL_ENV} WORKDIR /app +RUN python -m playwright install chromium + COPY bot.py pyproject.toml .env.prod .env.test ./ COPY assets ./assets COPY scripts ./scripts diff --git a/scripts/test_playwright.py b/scripts/test_playwright.py new file mode 100644 index 0000000..bc447ab --- /dev/null +++ b/scripts/test_playwright.py @@ -0,0 +1,15 @@ +import playwright.sync_api + + +def main(): + with playwright.sync_api.sync_playwright() as p: + browser = p.chromium.launch() + page = browser.new_page() + page.goto("https://www.baidu.com") + print("Playwright + Chromium 环境正常") + browser.close() + + +if __name__ == "__main__": + main() +