From bd7bff1bb4df34c79900dc696864763939a23423 Mon Sep 17 00:00:00 2001 From: uy/sun Date: Wed, 25 Dec 2024 20:48:33 +0800 Subject: [PATCH 01/10] =?UTF-8?q?build:=20=E5=B0=86=20noneflow=20=E5=92=8C?= =?UTF-8?q?=20nonetest=20=E7=9A=84=20Dockerfile=20=E7=BB=9F=E4=B8=80?= =?UTF-8?q?=E5=AD=98=E6=94=BE=E5=9C=A8=20docker=20=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E5=A4=B9=E4=B8=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/main.yml | 3 ++- Dockerfile => docker/noneflow.dockerfile | 0 .../docker_test/Dockerfile => docker/nonetest.dockerfile | 0 3 files changed, 2 insertions(+), 1 deletion(-) rename Dockerfile => docker/noneflow.dockerfile (100%) rename src/providers/docker_test/Dockerfile => docker/nonetest.dockerfile (100%) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 7dbf91c3..5cfae90e 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -67,6 +67,7 @@ jobs: 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 }} @@ -105,7 +106,7 @@ jobs: 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/docker/noneflow.dockerfile similarity index 100% rename from Dockerfile rename to docker/noneflow.dockerfile diff --git a/src/providers/docker_test/Dockerfile b/docker/nonetest.dockerfile similarity index 100% rename from src/providers/docker_test/Dockerfile rename to docker/nonetest.dockerfile From df029d6ba3492838c5992161812ec2ab36928a73 Mon Sep 17 00:00:00 2001 From: uy/sun Date: Wed, 25 Dec 2024 20:57:52 +0800 Subject: [PATCH 02/10] =?UTF-8?q?build:=20=E4=B8=8D=E5=BA=94=E8=AF=A5?= =?UTF-8?q?=E4=BF=9D=E5=AD=98=20cache?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docker/noneflow.dockerfile | 6 +++++- docker/nonetest.dockerfile | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/docker/noneflow.dockerfile b/docker/noneflow.dockerfile index ae029cc0..daa160a1 100644 --- a/docker/noneflow.dockerfile +++ b/docker/noneflow.dockerfile @@ -11,9 +11,13 @@ RUN apt-get update \ && apt-get purge -y --auto-remove \ && rm -rf /var/lib/apt/lists/* +# 设置 uv +ENV UV_NO_CACHE=1 +ENV UV_COMPILE_BYTECODE=1 + # Python 依赖 COPY pyproject.toml uv.lock /app/ -RUN uv sync --project /app/ --no-dev --frozen --compile-bytecode +RUN uv sync --project /app/ --no-dev --frozen COPY bot.py .env /app/ COPY src /app/src/ diff --git a/docker/nonetest.dockerfile b/docker/nonetest.dockerfile index ca7e99f1..937e1c0a 100644 --- a/docker/nonetest.dockerfile +++ b/docker/nonetest.dockerfile @@ -17,9 +17,13 @@ RUN apt-get update \ ENV PATH="${PATH}:/root/.local/bin" RUN uv tool install poetry +# 设置 uv +ENV UV_NO_CACHE=1 +ENV UV_COMPILE_BYTECODE=1 + # Python 依赖 COPY pyproject.toml uv.lock /app/ -RUN uv sync --project /app/ --no-dev --frozen --compile-bytecode +RUN uv sync --project /app/ --no-dev --frozen COPY src /app/src/ From 08cf6dad6e23642f67a91022d02a998ffb7cdb6b Mon Sep 17 00:00:00 2001 From: uy/sun Date: Wed, 25 Dec 2024 23:10:55 +0800 Subject: [PATCH 03/10] =?UTF-8?q?build:=20=E9=80=9A=E8=BF=87=E7=8E=AF?= =?UTF-8?q?=E5=A2=83=E5=8F=98=E9=87=8F=E8=AE=BE=E7=BD=AE=20frozen?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docker/noneflow.dockerfile | 3 ++- docker/nonetest.dockerfile | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/docker/noneflow.dockerfile b/docker/noneflow.dockerfile index daa160a1..29a80976 100644 --- a/docker/noneflow.dockerfile +++ b/docker/noneflow.dockerfile @@ -14,10 +14,11 @@ RUN apt-get update \ # 设置 uv ENV UV_NO_CACHE=1 ENV UV_COMPILE_BYTECODE=1 +ENV UV_FROZEN=1 # Python 依赖 COPY pyproject.toml uv.lock /app/ -RUN uv sync --project /app/ --no-dev --frozen +RUN uv sync --project /app/ --no-dev COPY bot.py .env /app/ COPY src /app/src/ diff --git a/docker/nonetest.dockerfile b/docker/nonetest.dockerfile index 937e1c0a..725841c7 100644 --- a/docker/nonetest.dockerfile +++ b/docker/nonetest.dockerfile @@ -20,10 +20,11 @@ RUN uv tool install poetry # 设置 uv ENV UV_NO_CACHE=1 ENV UV_COMPILE_BYTECODE=1 +ENV UV_FROZEN=1 # Python 依赖 COPY pyproject.toml uv.lock /app/ -RUN uv sync --project /app/ --no-dev --frozen +RUN uv sync --project /app/ --no-dev COPY src /app/src/ From 213bea8a6bdb5996427df298c3d5347ef7f1eaa9 Mon Sep 17 00:00:00 2001 From: uy/sun Date: Thu, 26 Dec 2024 09:42:59 +0800 Subject: [PATCH 04/10] =?UTF-8?q?build:=20=E5=8F=82=E8=80=83=20uv=20?= =?UTF-8?q?=E7=9A=84=E7=A4=BA=E4=BE=8B=E9=87=8D=E5=86=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docker/noneflow.dockerfile | 32 +++++++++++++++++++------------- docker/nonetest.dockerfile | 32 ++++++++++++++++++-------------- 2 files changed, 37 insertions(+), 27 deletions(-) diff --git a/docker/noneflow.dockerfile b/docker/noneflow.dockerfile index 29a80976..d61eae52 100644 --- a/docker/noneflow.dockerfile +++ b/docker/noneflow.dockerfile @@ -1,26 +1,32 @@ -FROM python:3.13.1-slim -COPY --from=ghcr.io/astral-sh/uv:0.5.11 /uv /bin/uv +FROM ghcr.io/astral-sh/uv:python3.13-bookworm-slim # 设置时区 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/* - -# 设置 uv -ENV UV_NO_CACHE=1 +# 启用字节码编译,加速 NoneFlow 启动 ENV UV_COMPILE_BYTECODE=1 -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 uv sync --project /app/ --no-dev +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/ +# 重置入口点,避免调用 uv +ENTRYPOINT [] + CMD ["uv", "run", "--project", "/app/", "--no-dev", "/app/bot.py"] diff --git a/docker/nonetest.dockerfile b/docker/nonetest.dockerfile index 725841c7..a967c17f 100644 --- a/docker/nonetest.dockerfile +++ b/docker/nonetest.dockerfile @@ -1,31 +1,35 @@ -FROM python:3.13.1 -COPY --from=ghcr.io/astral-sh/uv:0.5.11 /uv /bin/uv +FROM ghcr.io/astral-sh/uv:python3.13-bookworm-slim WORKDIR /app # 设置时区 ENV TZ=Asia/Shanghai +# 启用字节码编译,加速 NoneFlow 启动 +ENV UV_COMPILE_BYTECODE=1 + +# 从缓存中复制而不是链接,因为缓存是挂载的 +ENV UV_LINK_MODE=copy + # 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/* +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 uv tool install poetry - -# 设置 uv -ENV UV_NO_CACHE=1 -ENV UV_COMPILE_BYTECODE=1 -ENV UV_FROZEN=1 +RUN --mount=type=cache,target=/root/.cache/uv \ + uv tool install poetry # Python 依赖 COPY pyproject.toml uv.lock /app/ -RUN uv sync --project /app/ --no-dev +RUN --mount=type=cache,target=/root/.cache/uv \ + uv sync --project /app/ --no-dev +# NoneFlow 本体 COPY src /app/src/ +# 重置入口点,避免调用 uv +ENTRYPOINT [] + CMD ["uv", "run", "--project", "/app/", "--no-dev", "-m", "src.providers.docker_test"] From a7ec0d3138463a36cd38b0c26745e22e54c3bdae Mon Sep 17 00:00:00 2001 From: uy/sun Date: Thu, 26 Dec 2024 09:46:07 +0800 Subject: [PATCH 05/10] =?UTF-8?q?build:=20=E8=A1=A5=E4=B8=8A=E6=BC=8F?= =?UTF-8?q?=E6=8E=89=E7=9A=84=20UV=5FFROZEN?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docker/noneflow.dockerfile | 3 +++ docker/nonetest.dockerfile | 3 +++ 2 files changed, 6 insertions(+) diff --git a/docker/noneflow.dockerfile b/docker/noneflow.dockerfile index d61eae52..1628efd2 100644 --- a/docker/noneflow.dockerfile +++ b/docker/noneflow.dockerfile @@ -6,6 +6,9 @@ ENV TZ=Asia/Shanghai # 启用字节码编译,加速 NoneFlow 启动 ENV UV_COMPILE_BYTECODE=1 +# 在不更新 uv.lock 文件的情况下运行 +ENV UV_FROZEN=1 + # 从缓存中复制而不是链接,因为缓存是挂载的 ENV UV_LINK_MODE=copy diff --git a/docker/nonetest.dockerfile b/docker/nonetest.dockerfile index a967c17f..2df050d9 100644 --- a/docker/nonetest.dockerfile +++ b/docker/nonetest.dockerfile @@ -8,6 +8,9 @@ ENV TZ=Asia/Shanghai # 启用字节码编译,加速 NoneFlow 启动 ENV UV_COMPILE_BYTECODE=1 +# 在不更新 uv.lock 文件的情况下运行 +ENV UV_FROZEN=1 + # 从缓存中复制而不是链接,因为缓存是挂载的 ENV UV_LINK_MODE=copy From 7d2e3c6743c840d0fcd33b1989a6e5452b31960c Mon Sep 17 00:00:00 2001 From: uy/sun Date: Thu, 26 Dec 2024 09:58:22 +0800 Subject: [PATCH 06/10] =?UTF-8?q?build:=20=E7=94=A8=E5=9B=9E=E4=B9=8B?= =?UTF-8?q?=E5=89=8D=E7=9A=84=E5=86=99=E6=B3=95=E6=96=B9=E4=BE=BF=E5=88=86?= =?UTF-8?q?=E5=88=AB=E6=8E=A7=E5=88=B6=20uv=20=E5=92=8C=20python=20?= =?UTF-8?q?=E7=89=88=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docker/noneflow.dockerfile | 4 +++- docker/nonetest.dockerfile | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/docker/noneflow.dockerfile b/docker/noneflow.dockerfile index 1628efd2..ba594ca7 100644 --- a/docker/noneflow.dockerfile +++ b/docker/noneflow.dockerfile @@ -1,4 +1,6 @@ -FROM ghcr.io/astral-sh/uv:python3.13-bookworm-slim +# 这样能分别控制 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 diff --git a/docker/nonetest.dockerfile b/docker/nonetest.dockerfile index 2df050d9..180c44bc 100644 --- a/docker/nonetest.dockerfile +++ b/docker/nonetest.dockerfile @@ -1,4 +1,6 @@ -FROM ghcr.io/astral-sh/uv:python3.13-bookworm-slim +# 这样能分别控制 uv 和 Python 版本 +FROM python:3.13.1-slim +COPY --from=ghcr.io/astral-sh/uv:0.5.11 /uv /bin/uv WORKDIR /app From 156c78430b1a2af1d2c4134999b2c46c6ed01353 Mon Sep 17 00:00:00 2001 From: uy/sun Date: Thu, 26 Dec 2024 10:00:13 +0800 Subject: [PATCH 07/10] =?UTF-8?q?build:=20=E4=B8=BA=E4=B9=8B=E5=90=8E=20nb?= =?UTF-8?q?=20noneflow=20=E5=91=BD=E4=BB=A4=E5=81=9A=E5=87=86=E5=A4=87?= =?UTF-8?q?=EF=BC=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docker/nonetest.dockerfile | 3 +++ 1 file changed, 3 insertions(+) diff --git a/docker/nonetest.dockerfile b/docker/nonetest.dockerfile index 180c44bc..d63497f9 100644 --- a/docker/nonetest.dockerfile +++ b/docker/nonetest.dockerfile @@ -31,6 +31,9 @@ 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/ From a83f7e082fb6428d89746e7fe8b3134aefd2101e Mon Sep 17 00:00:00 2001 From: uy/sun Date: Sat, 28 Dec 2024 22:31:36 +0800 Subject: [PATCH 08/10] =?UTF-8?q?build:=20=E4=B8=8D=E9=9C=80=E8=A6=81?= =?UTF-8?q?=E9=87=8D=E7=BD=AE=E5=85=A5=E5=8F=A3=E7=82=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docker/noneflow.dockerfile | 3 --- docker/nonetest.dockerfile | 3 --- 2 files changed, 6 deletions(-) diff --git a/docker/noneflow.dockerfile b/docker/noneflow.dockerfile index ba594ca7..aa06697f 100644 --- a/docker/noneflow.dockerfile +++ b/docker/noneflow.dockerfile @@ -31,7 +31,4 @@ ENV PATH="/app/.venv/bin:$PATH" COPY bot.py .env /app/ COPY src /app/src/ -# 重置入口点,避免调用 uv -ENTRYPOINT [] - CMD ["uv", "run", "--project", "/app/", "--no-dev", "/app/bot.py"] diff --git a/docker/nonetest.dockerfile b/docker/nonetest.dockerfile index d63497f9..9db4b890 100644 --- a/docker/nonetest.dockerfile +++ b/docker/nonetest.dockerfile @@ -37,7 +37,4 @@ ENV PATH="/app/.venv/bin:$PATH" # NoneFlow 本体 COPY src /app/src/ -# 重置入口点,避免调用 uv -ENTRYPOINT [] - CMD ["uv", "run", "--project", "/app/", "--no-dev", "-m", "src.providers.docker_test"] From a993ae099b46cf5b40cf3ed43b627b0e9956fd60 Mon Sep 17 00:00:00 2001 From: uy/sun Date: Sat, 28 Dec 2024 22:43:35 +0800 Subject: [PATCH 09/10] =?UTF-8?q?ci:=20=E6=B7=BB=E5=8A=A0=20buildkit=20?= =?UTF-8?q?=E7=BC=93=E5=AD=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/main.yml | 42 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 5cfae90e..0d966fd9 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -63,6 +63,27 @@ 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('.github/workflows/test/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: @@ -102,6 +123,27 @@ 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('.github/workflows/test/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: From 5e5f52b806bb97fb61daa863916151b069b93391 Mon Sep 17 00:00:00 2001 From: uy/sun Date: Sat, 28 Dec 2024 22:47:45 +0800 Subject: [PATCH 10/10] =?UTF-8?q?ci:=20=E4=BF=AE=E5=A4=8D=20hash=20?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E4=B8=8D=E6=AD=A3=E7=A1=AE=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/main.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 0d966fd9..d893b32a 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -71,7 +71,7 @@ jobs: var-cache-apt var-lib-apt root-cache-uv - key: cache-${{ hashFiles('.github/workflows/test/Dockerfile') }} + key: cache-${{ hashFiles('docker/noneflow.dockerfile') }} - name: Inject cache into docker uses: reproducible-containers/buildkit-cache-dance@v3.1.2 @@ -131,7 +131,7 @@ jobs: var-cache-apt var-lib-apt root-cache-uv - key: cache-${{ hashFiles('.github/workflows/test/Dockerfile') }} + key: cache-${{ hashFiles('docker/nonetest.dockerfile') }} - name: Inject cache into docker uses: reproducible-containers/buildkit-cache-dance@v3.1.2