From e7026941bcb2ebfc07d8cc3e888d6018fac24a4e Mon Sep 17 00:00:00 2001 From: linyqh Date: Sun, 10 Nov 2024 21:25:44 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=20docker=20=E6=9E=84?= =?UTF-8?q?=E5=BB=BA=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Dockerfile | 74 +++++++++++++++++++++++++++++--------------- config.example.toml | 2 +- docker-compose.yml | 38 ++++++++--------------- docker-entrypoint.sh | 8 +++++ 4 files changed, 71 insertions(+), 51 deletions(-) create mode 100644 docker-entrypoint.sh 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 '/