update docker (#328)

This commit is contained in:
Wendong-Fan
2025-03-17 22:49:12 +08:00
committed by GitHub
4 changed files with 28 additions and 26 deletions

View File

@@ -1,6 +1,6 @@
FROM python:3.10-slim
# 设置环境变量
# Set environment variables
ENV PYTHONDONTWRITEBYTECODE=1 \
PYTHONUNBUFFERED=1 \
PIP_NO_CACHE_DIR=0 \
@@ -10,51 +10,50 @@ ENV PYTHONDONTWRITEBYTECODE=1 \
DEBIAN_FRONTEND=noninteractive \
PATH="/app/.venv/bin:$PATH"
# 设置工作目录
# Set working directory
WORKDIR /app
# 安装系统依赖合并为一个RUN命令减少层数
# Install system dependencies (combine into one RUN command to reduce layers)
RUN apt-get update && apt-get install -y --no-install-recommends \
curl git ffmpeg libsm6 libxext6 xvfb xauth x11-utils \
build-essential python3-dev \
build-essential python3-dev vim\
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
# 安装uv工具
# Install uv tool
RUN pip install uv
# 复制构建项目文件
# Copy project build files
COPY pyproject.toml .
COPY README.md .
# 如果README.md不存在则创建
RUN if [ ! -f "README.md" ]; then echo -e "# OWL Project\n\n这是OWL项目的Docker环境。" > README.md; fi
# Create README.md if it doesn't exist
RUN if [ ! -f "README.md" ]; then echo -e "# OWL Project\n\nThis is the Docker environment for the OWL project." > README.md; fi
# 创建虚拟环境并安装依赖
# Create virtual environment and install dependencies
RUN uv venv .venv --python=3.10 && \
. .venv/bin/activate && \
uv pip install -e .
# 复制运行项目文件
# Copy project runtime files
COPY owl/ ./owl/
COPY licenses/ ./licenses/
COPY assets/ ./assets/
COPY README_zh.md .
# 创建启动脚本
# Create startup script
RUN echo '#!/bin/bash\nxvfb-run --auto-servernum --server-args="-screen 0 1280x960x24" python "$@"' > /usr/local/bin/xvfb-python && \
chmod +x /usr/local/bin/xvfb-python
# 创建欢迎脚本
RUN echo '#!/bin/bash\necho "欢迎使用OWL项目Docker环境"\necho "Welcome to OWL Project Docker environment!"\necho ""\necho "可用的脚本 | Available scripts:"\nls -1 *.py | grep -v "__" | sed "s/^/- /"\necho ""\necho "运行示例 | Run examples:"\necho " xvfb-python run.py # 运行默认脚本 | Run default script"\necho " xvfb-python run_deepseek_example.py # 运行DeepSeek示例 | Run DeepSeek example"\necho ""\necho "或者使用自定义查询 | Or use custom query:"\necho " xvfb-python run.py \"你的问题 | Your question\""\necho ""' > /usr/local/bin/owl-welcome && \
# Create welcome script
RUN echo '#!/bin/bash\necho "Welcome to the OWL Project Docker environment!"\necho "Welcome to OWL Project Docker environment!"\necho ""\necho "Available scripts:"\nls -1 *.py | grep -v "__" | sed "s/^/- /"\necho ""\necho "Run examples:"\necho " xvfb-python run.py # Run default script"\necho " xvfb-python run_deepseek_example.py # Run DeepSeek example"\necho ""\necho "Or use custom query:"\necho " xvfb-python run.py \"Your question\""\necho ""' > /usr/local/bin/owl-welcome && \
chmod +x /usr/local/bin/owl-welcome
# 设置工作目录
# Set working directory
WORKDIR /app/owl
# 添加健康检查
# Add health check
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
CMD python -c "import sys; sys.exit(0 if __import__('os').path.exists('/app/owl') else 1)"
# 容器启动命令
# Container startup command
CMD ["/bin/bash", "-c", "owl-welcome && /bin/bash"]

View File

@@ -10,13 +10,13 @@ services:
# dockerfile: .container/Dockerfile
volumes:
# 挂载.env文件方便配置API密钥
# Mount .env file for easy API key configuration
- ../owl/.env:/app/owl/.env
# 挂载example文件夹以支持docker容器内运行代码案例
# Mount examples folder to support running code examples inside the Docker container
- ../examples:/app/examples
# 挂载数据目录
# Mount data directory
- ./data:/app/owl/data
# 挂载缓存目录,避免重复下载
# Mount cache directories to avoid repeated downloads
- ~/.cache/pip:/root/.pip/cache
- ~/.cache/playwright:/root/.cache/ms-playwright
environment:
@@ -25,18 +25,21 @@ services:
- PYTHONDONTWRITEBYTECODE=1
- PYTHONUNBUFFERED=1
- TERM=xterm-256color
- GRADIO_SERVER_NAME=0.0.0.0
- GRADIO_SERVER_PORT=7860
- PYTHONPATH=.
ports:
- "7860:7860"
stdin_open: true
tty: true
shm_size: 2gb
# 简化资源限制
# Simplify resource limits
deploy:
resources:
limits:
memory: 4G
# 定义持久化卷,用于缓存 | Define persistent volumes for caching
# Define persistent volumes for caching
volumes:
playwright-cache:
pip-cache:
pip-cache:

View File

@@ -1287,7 +1287,7 @@ def main():
app = create_ui()
app.queue()
app.launch(share=False, server_name="127.0.0.1", server_port=7860)
app.launch(share=False)
except Exception as e:
logging.error(f"Error occurred while starting the application: {str(e)}")
print(f"Error occurred while starting the application: {str(e)}")

View File

@@ -1257,7 +1257,7 @@ def main():
app = create_ui()
app.queue()
app.launch(share=False, server_name="127.0.0.1", server_port=7860)
app.launch(share=False)
except Exception as e:
logging.error(f"启动应用程序时发生错误: {str(e)}")
print(f"启动应用程序时发生错误: {str(e)}")