add dockerfile
This commit is contained in:
parent
11206d8958
commit
8cf7f956d6
18
Dockerfile
18
Dockerfile
@ -9,23 +9,14 @@ ENV PYTHONPATH=/app
|
|||||||
ENV PYTHONUNBUFFERED=1
|
ENV PYTHONUNBUFFERED=1
|
||||||
|
|
||||||
# 安装系统依赖
|
# 安装系统依赖
|
||||||
RUN sed -i 's|http://deb.debian.org|http://mirrors.aliyun.com|g' /etc/apt/sources.list.d/debian.sources && \
|
RUN apt-get update && apt-get install -y \
|
||||||
apt-get update && apt-get install -y \
|
|
||||||
curl \
|
curl \
|
||||||
wget \
|
wget \
|
||||||
git \
|
|
||||||
nodejs \
|
|
||||||
npm \
|
|
||||||
ripgrep \
|
|
||||||
&& rm -rf /var/lib/apt/lists/*
|
&& 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依赖
|
# 复制requirements文件并安装Python依赖
|
||||||
COPY requirements.txt .
|
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 . .
|
COPY . .
|
||||||
@ -33,7 +24,12 @@ COPY . .
|
|||||||
# 创建必要的目录
|
# 创建必要的目录
|
||||||
RUN mkdir -p /app/projects
|
RUN mkdir -p /app/projects
|
||||||
RUN mkdir -p /app/public
|
RUN mkdir -p /app/public
|
||||||
|
RUN mkdir -p /app/models
|
||||||
RUN mkdir -p /app/queue_data
|
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
|
EXPOSE 8001
|
||||||
|
|
||||||
|
|||||||
45
Dockerfile.modelscope
Normal file
45
Dockerfile.modelscope
Normal file
@ -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"]
|
||||||
Loading…
Reference in New Issue
Block a user