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() +