diff --git a/.env b/.env index 4553b4a6..6ee8c965 100644 --- a/.env +++ b/.env @@ -153,4 +153,4 @@ PARSER_APPEND_URL=true # nonebot-plugin-htmlrender # https://github.com/kexue-z/nonebot-plugin-htmlrender -# HTMLRENDER_CI_MODE=false +HTMLRENDER_CONNECT="ws://playwright:53333/playwright" diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 70b08354..bec4d509 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -64,6 +64,9 @@ jobs: name: Docker runs-on: ubuntu-latest needs: test + services: + playwright: + image: jacoblincool/playwright:chromium-server-1.56.1 steps: - name: Checkout uses: actions/checkout@v6 @@ -135,7 +138,7 @@ jobs: # 启动容器 echo "正在启动容器..." - docker run --env HTMLRENDER_CI_MODE=true --name test-docker-container -d he0119/coolqbot:test > /dev/null + docker run --env HTMLRENDER_CONNECT=ws://playwright:53333/playwright --network=${{ job.services.playwright.network }} --name test-docker-container -d he0119/coolqbot:test > /dev/null TIMEOUT=60 ELAPSED=0 diff --git a/CHANGELOG.md b/CHANGELOG.md index 1661e7c0..be16a99c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -51,6 +51,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/lang/zh-CN/ - 使用依赖注入的 User 来判断权限 +### Changed + +- htmlrender 使用外部浏览器 + ## [0.26.2] - 2025-08-27 ### Fixed diff --git a/Dockerfile b/Dockerfile index b19013fa..ffb5bdde 100644 --- a/Dockerfile +++ b/Dockerfile @@ -36,11 +36,6 @@ COPY pyproject.toml uv.lock ./ RUN --mount=type=cache,target=/root/.cache/uv \ uv sync -# 安装浏览器 -RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \ - --mount=type=cache,target=/var/lib/apt,sharing=locked \ - uv run playwright install --with-deps chromium firefox - # Gunicorn 配置 COPY ./docker/gunicorn_conf.py /gunicorn_conf.py COPY ./docker/start.sh /start.sh diff --git a/docker-compose.yml b/docker-compose.yml index e970486b..8c89f93c 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -9,8 +9,22 @@ services: - "8080:8080" env_file: - ".env" + depends_on: + playwright: + condition: service_healthy rsshub: image: diygod/rsshub container_name: rsshub restart: always + + playwright: + image: jacoblincool/playwright:chromium-server-1.56.1 + container_name: playwright + restart: always + healthcheck: + test: ["CMD", "curl", "-f", "http://localhost:53333/playwright"] + interval: 1m30s + timeout: 30s + retries: 5 + start_period: 30s diff --git a/pyproject.toml b/pyproject.toml index 8b7a755a..88bdaaa6 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -45,6 +45,8 @@ dependencies = [ "nonebot-plugin-zssm==0.3.7", "nonebot-plugin-abs==1.1.0", "nonebot-plugin-parser[htmlkit]==2.4.1", + "nonebot-plugin-htmlrender>=0.7.0a3", + "playwright==1.56.0", ] [project.urls] diff --git a/uv.lock b/uv.lock index a87e444f..f935e6c3 100644 --- a/uv.lock +++ b/uv.lock @@ -574,6 +574,7 @@ dependencies = [ { name = "nonebot-plugin-apscheduler" }, { name = "nonebot-plugin-datastore" }, { name = "nonebot-plugin-deepseek" }, + { name = "nonebot-plugin-htmlrender" }, { name = "nonebot-plugin-localstore" }, { name = "nonebot-plugin-memes" }, { name = "nonebot-plugin-orm", extra = ["default"] }, @@ -589,6 +590,7 @@ dependencies = [ { name = "nonebot-plugin-zssm" }, { name = "nonebot-session-to-uninfo" }, { name = "nonebot2", extra = ["aiohttp", "fastapi", "httpx", "websockets"] }, + { name = "playwright" }, { name = "pydantic" }, { name = "uvicorn", extra = ["standard"] }, { name = "uvicorn-worker" }, @@ -632,6 +634,7 @@ requires-dist = [ { name = "nonebot-plugin-apscheduler", specifier = ">=0.5.0" }, { name = "nonebot-plugin-datastore", specifier = ">=1.3.1" }, { name = "nonebot-plugin-deepseek", specifier = "==0.2.0" }, + { name = "nonebot-plugin-htmlrender", specifier = ">=0.7.0a3" }, { name = "nonebot-plugin-localstore", specifier = ">=0.7.4" }, { name = "nonebot-plugin-memes", specifier = "==0.8.1" }, { name = "nonebot-plugin-orm", extras = ["default"], specifier = ">=0.8.3" }, @@ -647,6 +650,7 @@ requires-dist = [ { name = "nonebot-plugin-zssm", specifier = "==0.3.7" }, { name = "nonebot-session-to-uninfo", specifier = ">=0.0.2" }, { name = "nonebot2", extras = ["aiohttp", "fastapi", "httpx", "websockets"], specifier = ">=2.4.4" }, + { name = "playwright", specifier = "==1.56.0" }, { name = "pydantic", specifier = ">=2.12.5" }, { name = "uvicorn", extras = ["standard"], specifier = ">=0.41.0" }, { name = "uvicorn-worker", specifier = ">=0.4.0" },