From d9ef3fc3e311342a26b8daf09b5825892374324d Mon Sep 17 00:00:00 2001 From: Wenjie Zhang Date: Wed, 7 May 2025 00:38:42 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20dockerfile=20=E4=B8=AD?= =?UTF-8?q?=E5=AF=B9=E4=BA=8E=20uv=20=E7=9A=84=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docker/api.Dockerfile | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/docker/api.Dockerfile b/docker/api.Dockerfile index 571a5f81..fcc3ca69 100644 --- a/docker/api.Dockerfile +++ b/docker/api.Dockerfile @@ -1,9 +1,16 @@ # 使用基础镜像 FROM python:3.12 +COPY --from=ghcr.io/astral-sh/uv:0.7.2 /uv /uvx /bin/ # 设置工作目录 WORKDIR /app +# 设置时区为 UTC+8 +ENV TZ=Asia/Shanghai +ENV UV_LINK_MODE=copy + +RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone + # 安装系统依赖 RUN apt-get update && apt-get install -y \ python3-dev \ @@ -11,16 +18,19 @@ RUN apt-get update && apt-get install -y \ libsm6 \ libxext6 -# 复制 requirements.txt 文件(这一步如果文件没变,Docker 会使用缓存) -# COPY../requirements.txt /app/requirements.txt -COPY ../pyproject.toml /app/pyproject.toml -COPY ../.python-version /app/.python-version - -# 安装依赖(Docker 会缓存这一步,除非 requirements.txt 发生变化) -RUN pip install uv -RUN uv sync +# 安装依赖项 +RUN --mount=type=cache,target=/root/.cache/uv \ + --mount=type=bind,source=uv.lock,target=uv.lock \ + --mount=type=bind,source=pyproject.toml,target=pyproject.toml \ + uv sync --frozen --no-install-project # 复制代码到容器中 COPY ../src /app/src COPY ../server /app/server +COPY ../pyproject.toml /app/pyproject.toml +COPY ../.python-version /app/.python-version +COPY ../uv.lock /app/uv.lock +# 同步项目 +RUN --mount=type=cache,target=/root/.cache/uv \ + uv sync --frozen \ No newline at end of file