diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 7dbf91c3..d893b32a 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -63,10 +63,32 @@ jobs: type=semver,pattern={{version}} type=ref,event=branch + - name: Cache buildkit + uses: actions/cache@v4 + id: cache + with: + path: | + var-cache-apt + var-lib-apt + root-cache-uv + key: cache-${{ hashFiles('docker/noneflow.dockerfile') }} + + - name: Inject cache into docker + uses: reproducible-containers/buildkit-cache-dance@v3.1.2 + with: + cache-map: | + { + "var-cache-apt": "/var/cache/apt", + "var-lib-apt": "/var/lib/apt", + "root-cache-uv": "/root/.cache/uv" + } + skip-extraction: ${{ steps.cache.outputs.cache-hit }} + - name: Build and Publish uses: docker/build-push-action@v6 with: context: . + file: ./docker/noneflow.dockerfile push: ${{ github.event_name != 'pull_request' }} tags: ${{ steps.metadata.outputs.tags }} labels: ${{ steps.metadata.outputs.labels }} @@ -101,11 +123,32 @@ jobs: type=semver,pattern={{version}} type=ref,event=branch + - name: Cache buildkit + uses: actions/cache@v4 + id: cache + with: + path: | + var-cache-apt + var-lib-apt + root-cache-uv + key: cache-${{ hashFiles('docker/nonetest.dockerfile') }} + + - name: Inject cache into docker + uses: reproducible-containers/buildkit-cache-dance@v3.1.2 + with: + cache-map: | + { + "var-cache-apt": "/var/cache/apt", + "var-lib-apt": "/var/lib/apt", + "root-cache-uv": "/root/.cache/uv" + } + skip-extraction: ${{ steps.cache.outputs.cache-hit }} + - name: Build and Publish uses: docker/build-push-action@v6 with: context: . - file: ./src/providers/docker_test/Dockerfile + file: ./docker/nonetest.dockerfile push: ${{ github.event_name != 'pull_request' }} tags: ${{ steps.metadata.outputs.tags }} labels: ${{ steps.metadata.outputs.labels }} diff --git a/Dockerfile b/Dockerfile deleted file mode 100644 index ae029cc0..00000000 --- a/Dockerfile +++ /dev/null @@ -1,21 +0,0 @@ -FROM python:3.13.1-slim -COPY --from=ghcr.io/astral-sh/uv:0.5.11 /uv /bin/uv - -# 设置时区 -ENV TZ=Asia/Shanghai - -# 安装依赖 -RUN apt-get update \ - && apt-get -y upgrade \ - && apt-get install -y --no-install-recommends git \ - && apt-get purge -y --auto-remove \ - && rm -rf /var/lib/apt/lists/* - -# Python 依赖 -COPY pyproject.toml uv.lock /app/ -RUN uv sync --project /app/ --no-dev --frozen --compile-bytecode - -COPY bot.py .env /app/ -COPY src /app/src/ - -CMD ["uv", "run", "--project", "/app/", "--no-dev", "/app/bot.py"] diff --git a/docker/noneflow.dockerfile b/docker/noneflow.dockerfile new file mode 100644 index 00000000..aa06697f --- /dev/null +++ b/docker/noneflow.dockerfile @@ -0,0 +1,34 @@ +# 这样能分别控制 uv 和 Python 版本 +FROM python:3.13.1-slim +COPY --from=ghcr.io/astral-sh/uv:0.5.11 /uv /bin/uv + +# 设置时区 +ENV TZ=Asia/Shanghai + +# 启用字节码编译,加速 NoneFlow 启动 +ENV UV_COMPILE_BYTECODE=1 + +# 在不更新 uv.lock 文件的情况下运行 +ENV UV_FROZEN=1 + +# 从缓存中复制而不是链接,因为缓存是挂载的 +ENV UV_LINK_MODE=copy + +# 安装依赖 +RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \ + --mount=type=cache,target=/var/lib/apt,sharing=locked \ + apt update && apt-get --no-install-recommends install -y git + +# Python 依赖 +COPY pyproject.toml uv.lock /app/ +RUN --mount=type=cache,target=/root/.cache/uv \ + uv sync --project /app/ --no-dev + +# 将可执行文件放在环境的路径前面 +ENV PATH="/app/.venv/bin:$PATH" + +# NoneFlow 本体 +COPY bot.py .env /app/ +COPY src /app/src/ + +CMD ["uv", "run", "--project", "/app/", "--no-dev", "/app/bot.py"] diff --git a/docker/nonetest.dockerfile b/docker/nonetest.dockerfile new file mode 100644 index 00000000..9db4b890 --- /dev/null +++ b/docker/nonetest.dockerfile @@ -0,0 +1,40 @@ +# 这样能分别控制 uv 和 Python 版本 +FROM python:3.13.1-slim +COPY --from=ghcr.io/astral-sh/uv:0.5.11 /uv /bin/uv + +WORKDIR /app + +# 设置时区 +ENV TZ=Asia/Shanghai + +# 启用字节码编译,加速 NoneFlow 启动 +ENV UV_COMPILE_BYTECODE=1 + +# 在不更新 uv.lock 文件的情况下运行 +ENV UV_FROZEN=1 + +# 从缓存中复制而不是链接,因为缓存是挂载的 +ENV UV_LINK_MODE=copy + +# OpenCV 所需的依赖 +RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \ + --mount=type=cache,target=/var/lib/apt,sharing=locked \ + apt update && apt-get install -y ffmpeg libsm6 libxext6 + +# 插件测试需要 Poetry +ENV PATH="${PATH}:/root/.local/bin" +RUN --mount=type=cache,target=/root/.cache/uv \ + uv tool install poetry + +# Python 依赖 +COPY pyproject.toml uv.lock /app/ +RUN --mount=type=cache,target=/root/.cache/uv \ + uv sync --project /app/ --no-dev + +# 将可执行文件放在环境的路径前面 +ENV PATH="/app/.venv/bin:$PATH" + +# NoneFlow 本体 +COPY src /app/src/ + +CMD ["uv", "run", "--project", "/app/", "--no-dev", "-m", "src.providers.docker_test"] diff --git a/src/providers/docker_test/Dockerfile b/src/providers/docker_test/Dockerfile deleted file mode 100644 index ca7e99f1..00000000 --- a/src/providers/docker_test/Dockerfile +++ /dev/null @@ -1,26 +0,0 @@ -FROM python:3.13.1 -COPY --from=ghcr.io/astral-sh/uv:0.5.11 /uv /bin/uv - -WORKDIR /app - -# 设置时区 -ENV TZ=Asia/Shanghai - -# OpenCV 所需的依赖 -RUN apt-get update \ - && apt-get -y upgrade \ - && apt-get install ffmpeg libsm6 libxext6 -y \ - && apt-get purge -y --auto-remove \ - && rm -rf /var/lib/apt/lists/* - -# 插件测试需要 Poetry -ENV PATH="${PATH}:/root/.local/bin" -RUN uv tool install poetry - -# Python 依赖 -COPY pyproject.toml uv.lock /app/ -RUN uv sync --project /app/ --no-dev --frozen --compile-bytecode - -COPY src /app/src/ - -CMD ["uv", "run", "--project", "/app/", "--no-dev", "-m", "src.providers.docker_test"]