diff --git a/Dockerfile b/Dockerfile index 4beabe4..3498a5d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,39 +1,63 @@ -FROM python:3.10-slim-bullseye +# 构建阶段 +FROM python:3.10-slim-bullseye as builder -# Set the working directory in the container -WORKDIR /NarratoAI +# 设置工作目录 +WORKDIR /build -# 设置/NarratoAI目录权限为777 -RUN chmod 777 /NarratoAI - -ENV PYTHONPATH="/NarratoAI" - -# Install system dependencies +# 安装构建依赖 RUN apt-get update && apt-get install -y \ git \ git-lfs \ + && rm -rf /var/lib/apt/lists/* + +# 创建虚拟环境 +RUN python -m venv /opt/venv +ENV PATH="/opt/venv/bin:$PATH" + +# 首先安装 PyTorch(因为它是最大的依赖) +RUN pip install --no-cache-dir torch torchvision torchaudio + +# 然后安装其他依赖 +COPY requirements.txt . +RUN pip install --no-cache-dir -r requirements.txt + +# 运行阶段 +FROM python:3.10-slim-bullseye + +# 设置工作目录 +WORKDIR /NarratoAI + +# 从builder阶段复制虚拟环境 +COPY --from=builder /opt/venv /opt/venv +ENV PATH="/opt/venv/bin:$PATH" + +# 安装运行时依赖 +RUN apt-get update && apt-get install -y \ imagemagick \ ffmpeg \ wget \ - && rm -rf /var/lib/apt/lists/* + git-lfs \ + && rm -rf /var/lib/apt/lists/* \ + && sed -i '/