mirror of
https://github.com/linyqh/NarratoAI.git
synced 2025-12-12 19:52:48 +00:00
优化 docker 构建方法
This commit is contained in:
parent
84e48b5991
commit
e7026941bc
74
Dockerfile
74
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 \
|
RUN apt-get update && apt-get install -y \
|
||||||
git \
|
git \
|
||||||
git-lfs \
|
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 \
|
imagemagick \
|
||||||
ffmpeg \
|
ffmpeg \
|
||||||
wget \
|
wget \
|
||||||
&& rm -rf /var/lib/apt/lists/*
|
git-lfs \
|
||||||
|
&& rm -rf /var/lib/apt/lists/* \
|
||||||
|
&& sed -i '/<policy domain="path" rights="none" pattern="@\*"/d' /etc/ImageMagick-6/policy.xml
|
||||||
|
|
||||||
# Fix security policy for ImageMagick
|
# 设置环境变量
|
||||||
RUN sed -i '/<policy domain="path" rights="none" pattern="@\*"/d' /etc/ImageMagick-6/policy.xml
|
ENV PYTHONPATH="/NarratoAI" \
|
||||||
|
PYTHONUNBUFFERED=1 \
|
||||||
|
PYTHONDONTWRITEBYTECODE=1
|
||||||
|
|
||||||
# Copy only the requirements.txt first to leverage Docker cache
|
# 设置目录权限
|
||||||
COPY requirements.txt ./
|
RUN chmod 777 /NarratoAI
|
||||||
|
|
||||||
# Install Python dependencies
|
# 安装git lfs
|
||||||
RUN pip install --no-cache-dir -r requirements.txt
|
|
||||||
|
|
||||||
# Now copy the rest of the codebase into the image
|
|
||||||
COPY . .
|
|
||||||
|
|
||||||
# 安装 git lfs 并下载模型到指定目录
|
|
||||||
RUN git lfs install
|
RUN git lfs install
|
||||||
|
|
||||||
# Expose the port the app runs on
|
# 复制应用代码
|
||||||
EXPOSE 8501
|
COPY . .
|
||||||
|
|
||||||
# Command to run the application
|
# 暴露端口
|
||||||
CMD ["streamlit", "run", "webui.py","--browser.serverAddress=127.0.0.1","--server.enableCORS=True","--browser.gatherUsageStats=False"]
|
EXPOSE 8501 8080
|
||||||
|
|
||||||
|
# 使用脚本作为入口点
|
||||||
|
COPY docker-entrypoint.sh /usr/local/bin/
|
||||||
|
RUN chmod +x /usr/local/bin/docker-entrypoint.sh
|
||||||
|
ENTRYPOINT ["docker-entrypoint.sh"]
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
[app]
|
[app]
|
||||||
project_version="0.3.4"
|
project_version="0.3.5"
|
||||||
# 支持视频理解的大模型提供商
|
# 支持视频理解的大模型提供商
|
||||||
# gemini
|
# gemini
|
||||||
# NarratoAPI
|
# NarratoAPI
|
||||||
|
|||||||
@ -1,30 +1,18 @@
|
|||||||
x-common-volumes: &common-volumes
|
x-common: &common
|
||||||
- ./:/NarratoAI
|
build:
|
||||||
|
context: .
|
||||||
|
dockerfile: Dockerfile
|
||||||
|
image: linyq1/narratoai:latest
|
||||||
|
volumes:
|
||||||
|
- ./:/NarratoAI
|
||||||
|
environment:
|
||||||
|
- VPN_PROXY_URL=http://host.docker.internal:7890
|
||||||
|
restart: always
|
||||||
|
|
||||||
services:
|
services:
|
||||||
webui:
|
webui:
|
||||||
build:
|
<<: *common
|
||||||
context: .
|
container_name: webui
|
||||||
dockerfile: Dockerfile
|
|
||||||
image: linyq1/narratoai:latest
|
|
||||||
container_name: "webui"
|
|
||||||
ports:
|
ports:
|
||||||
- "8501:8501"
|
- "8501:8501"
|
||||||
command: [ "bash", "webui.sh" ]
|
command: ["webui"]
|
||||||
volumes: *common-volumes
|
|
||||||
environment:
|
|
||||||
- "VPN_PROXY_URL=http://host.docker.internal:7890"
|
|
||||||
restart: always
|
|
||||||
api:
|
|
||||||
build:
|
|
||||||
context: .
|
|
||||||
dockerfile: Dockerfile
|
|
||||||
image: linyq1/narratoai:latest
|
|
||||||
container_name: "api"
|
|
||||||
ports:
|
|
||||||
- "8502:8080"
|
|
||||||
command: [ "python3", "main.py" ]
|
|
||||||
volumes: *common-volumes
|
|
||||||
environment:
|
|
||||||
- "VPN_PROXY_URL=http://host.docker.internal:7890"
|
|
||||||
restart: always
|
|
||||||
|
|||||||
8
docker-entrypoint.sh
Normal file
8
docker-entrypoint.sh
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
set -e
|
||||||
|
|
||||||
|
if [ "$1" = "webui" ]; then
|
||||||
|
exec streamlit run webui.py --browser.serverAddress=127.0.0.1 --server.enableCORS=True --browser.gatherUsageStats=False
|
||||||
|
else
|
||||||
|
exec "$@"
|
||||||
|
fi
|
||||||
Loading…
x
Reference in New Issue
Block a user