Skip to content

Commit

Permalink
build: 参考 uv 的示例重写
Browse files Browse the repository at this point in the history
  • Loading branch information
he0119 committed Dec 26, 2024
1 parent 08cf6da commit 213bea8
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 27 deletions.
32 changes: 19 additions & 13 deletions docker/noneflow.dockerfile
Original file line number Diff line number Diff line change
@@ -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"]
32 changes: 18 additions & 14 deletions docker/nonetest.dockerfile
Original file line number Diff line number Diff line change
@@ -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"]

0 comments on commit 213bea8

Please sign in to comment.