From 8cf7f956d6968ee719dd2a116f3976fcf77c7d21 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=B1=E6=BD=AE?= Date: Wed, 22 Oct 2025 12:53:46 +0800 Subject: [PATCH] add dockerfile --- Dockerfile | 18 +++++++---------- Dockerfile.modelscope | 45 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+), 11 deletions(-) create mode 100644 Dockerfile.modelscope diff --git a/Dockerfile b/Dockerfile index 896515a..c1bbd82 100644 --- a/Dockerfile +++ b/Dockerfile @@ -9,23 +9,14 @@ ENV PYTHONPATH=/app ENV PYTHONUNBUFFERED=1 # 安装系统依赖 -RUN sed -i 's|http://deb.debian.org|http://mirrors.aliyun.com|g' /etc/apt/sources.list.d/debian.sources && \ - apt-get update && apt-get install -y \ +RUN apt-get update && apt-get install -y \ curl \ wget \ - git \ - nodejs \ - npm \ - ripgrep \ && rm -rf /var/lib/apt/lists/* -RUN mkdir -p /app/models -RUN pip install modelscope -i https://mirrors.aliyun.com/pypi/simple/ -RUN modelscope download --model sentence-transformers/paraphrase-multilingual-MiniLM-L12-v2 README.md --local_dir /app/models/paraphrase-multilingual-MiniLM-L12-v2 - # 复制requirements文件并安装Python依赖 COPY requirements.txt . -RUN pip install --no-cache-dir -i https://mirrors.aliyun.com/pypi/simple/ -r requirements.txt +RUN pip install --no-cache-dir -r requirements.txt # 复制应用代码 COPY . . @@ -33,7 +24,12 @@ COPY . . # 创建必要的目录 RUN mkdir -p /app/projects RUN mkdir -p /app/public +RUN mkdir -p /app/models RUN mkdir -p /app/queue_data + +# 下载sentence-transformers模型到models目录 +RUN python -c "from sentence_transformers import SentenceTransformer; model = SentenceTransformer('sentence-transformers/paraphrase-multilingual-MiniLM-L12-v2'); model.save('/app/models/paraphrase-multilingual-MiniLM-L12-v2')" + # 暴露端口 EXPOSE 8001 diff --git a/Dockerfile.modelscope b/Dockerfile.modelscope new file mode 100644 index 0000000..4b09843 --- /dev/null +++ b/Dockerfile.modelscope @@ -0,0 +1,45 @@ +# 使用Python 3.12官方镜像作为基础镜像 +FROM python:3.12-slim + +# 设置工作目录 +WORKDIR /app + +# 设置环境变量 +ENV PYTHONPATH=/app +ENV PYTHONUNBUFFERED=1 + +# 安装系统依赖 +RUN sed -i 's|http://deb.debian.org|http://mirrors.aliyun.com|g' /etc/apt/sources.list.d/debian.sources && \ + apt-get update && apt-get install -y \ + curl \ + wget \ + && rm -rf /var/lib/apt/lists/* + +# 复制requirements文件并安装Python依赖 +COPY requirements.txt . +RUN pip install --no-cache-dir -i https://mirrors.aliyun.com/pypi/simple/ -r requirements.txt + +# 复制应用代码 +COPY . . + +# 创建必要的目录 +RUN mkdir -p /app/projects +RUN mkdir -p /app/public +RUN mkdir -p /app/models +RUN mkdir -p /app/queue_data + +# 安装modelscope +RUN pip install --no-cache-dir -i https://mirrors.aliyun.com/pypi/simple/ modelscope + +# 从modelscope下载sentence-transformers模型到models目录 +RUN python -c "from modelscope import snapshot_download; model_dir = snapshot_download('sentence-transformers/paraphrase-multilingual-MiniLM-L12-v2'); import shutil; shutil.move(model_dir, '/app/models/paraphrase-multilingual-MiniLM-L12-v2')" + +# 暴露端口 +EXPOSE 8001 + +# 健康检查 +HEALTHCHECK --interval=30s --timeout=30s --start-period=5s --retries=3 \ + CMD curl -f http://localhost:8001/api/health || exit 1 + +# 启动命令 - 同时运行FastAPI应用和队列消费者 +CMD ["./start_all.sh"]