mirror of
https://github.com/camel-ai/owl.git
synced 2026-03-22 05:57:17 +08:00
update readme
This commit is contained in:
@@ -1,107 +1,57 @@
|
|||||||
# 使用ARG定义可配置的构建参数 | Using ARG to define configurable build parameters
|
FROM python:3.10-slim
|
||||||
ARG PYTHON_VERSION=3.10
|
|
||||||
ARG PIP_INDEX_URL=https://pypi.tuna.tsinghua.edu.cn/simple
|
|
||||||
ARG PLAYWRIGHT_DOWNLOAD_HOST=https://npmmirror.com/mirrors/playwright
|
|
||||||
|
|
||||||
# 第一阶段:构建依赖 | Stage 1: Build dependencies
|
# 设置环境变量
|
||||||
FROM python:${PYTHON_VERSION}-slim AS builder
|
ENV PYTHONDONTWRITEBYTECODE=1 \
|
||||||
|
PYTHONUNBUFFERED=1 \
|
||||||
|
PIP_NO_CACHE_DIR=0 \
|
||||||
|
PIP_INDEX_URL=https://pypi.tuna.tsinghua.edu.cn/simple \
|
||||||
|
PLAYWRIGHT_DOWNLOAD_HOST=https://npmmirror.com/mirrors/playwright \
|
||||||
|
PLAYWRIGHT_BROWSERS_PATH=/root/.cache/ms-playwright \
|
||||||
|
DEBIAN_FRONTEND=noninteractive
|
||||||
|
|
||||||
# 设置工作目录 | Set working directory
|
# 设置工作目录
|
||||||
WORKDIR /build
|
|
||||||
|
|
||||||
# 设置pip镜像源以加速下载 | Set pip mirror to accelerate downloads
|
|
||||||
ARG PIP_INDEX_URL
|
|
||||||
RUN pip config set global.index-url ${PIP_INDEX_URL}
|
|
||||||
|
|
||||||
# 安装构建依赖 | Install build dependencies
|
|
||||||
RUN apt-get update && apt-get install -y --no-install-recommends \
|
|
||||||
build-essential \
|
|
||||||
&& apt-get clean \
|
|
||||||
&& rm -rf /var/lib/apt/lists/*
|
|
||||||
|
|
||||||
# 复制并安装requirements.txt | Copy and install requirements.txt
|
|
||||||
COPY requirements.txt .
|
|
||||||
RUN pip install --no-cache-dir --prefix=/install -r requirements.txt
|
|
||||||
|
|
||||||
# 第二阶段:运行时环境 | Stage 2: Runtime environment
|
|
||||||
FROM python:${PYTHON_VERSION}-slim
|
|
||||||
|
|
||||||
# 添加构建信息标签 | Add build information labels
|
|
||||||
ARG BUILD_DATE
|
|
||||||
ARG VERSION
|
|
||||||
LABEL org.opencontainers.image.created="${BUILD_DATE}" \
|
|
||||||
org.opencontainers.image.version="${VERSION}" \
|
|
||||||
org.opencontainers.image.title="OWL Project" \
|
|
||||||
org.opencontainers.image.description="OWL Project Docker Image" \
|
|
||||||
org.opencontainers.image.source="https://github.com/yourusername/owl"
|
|
||||||
|
|
||||||
# 设置工作目录 | Set working directory
|
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
# 设置pip镜像源以加速下载 | Set pip mirror to accelerate downloads
|
# 安装系统依赖(合并为一个RUN命令减少层数)
|
||||||
ARG PIP_INDEX_URL
|
|
||||||
RUN pip config set global.index-url ${PIP_INDEX_URL}
|
|
||||||
|
|
||||||
# 从builder阶段复制已安装的Python包 | Copy installed Python packages from builder stage
|
|
||||||
COPY --from=builder /install /usr/local
|
|
||||||
|
|
||||||
# 优化apt安装,减少层数 | Optimize apt installation, reduce layers
|
|
||||||
RUN apt-get update && apt-get install -y --no-install-recommends \
|
RUN apt-get update && apt-get install -y --no-install-recommends \
|
||||||
curl \
|
curl git ffmpeg libsm6 libxext6 xvfb xauth x11-utils \
|
||||||
git \
|
gcc python3-dev \
|
||||||
ffmpeg \
|
|
||||||
libsm6 \
|
|
||||||
libxext6 \
|
|
||||||
# 添加xvfb和相关依赖 | Add xvfb and related dependencies
|
|
||||||
xvfb \
|
|
||||||
xauth \
|
|
||||||
x11-utils \
|
|
||||||
&& apt-get clean \
|
&& apt-get clean \
|
||||||
&& rm -rf /var/lib/apt/lists/*
|
&& rm -rf /var/lib/apt/lists/*
|
||||||
|
|
||||||
# 安装 Playwright 依赖(使用国内镜像源) | Install Playwright dependencies (using Chinese mirror)
|
COPY pyproject.toml .
|
||||||
ENV PLAYWRIGHT_BROWSERS_PATH=/root/.cache/ms-playwright
|
# 创建README.md文件以避免构建错误
|
||||||
ARG PLAYWRIGHT_DOWNLOAD_HOST
|
RUN echo "# OWL Project\n\n这是OWL项目的Docker环境。" > README.md
|
||||||
ENV PLAYWRIGHT_DOWNLOAD_HOST=${PLAYWRIGHT_DOWNLOAD_HOST}
|
# 安装uv工具
|
||||||
RUN pip install --no-cache-dir playwright && \
|
RUN pip install uv
|
||||||
playwright install --with-deps chromium
|
|
||||||
|
|
||||||
# 创建非root用户 | Create non-root user
|
# 创建虚拟环境并安装依赖
|
||||||
RUN groupadd -r owl && useradd -r -g owl -m owl
|
RUN uv venv .venv --python=3.10 && \
|
||||||
|
. .venv/bin/activate && \
|
||||||
|
uv pip install -e .
|
||||||
|
|
||||||
# 复制项目文件 | Copy project files
|
|
||||||
|
# 复制项目文件
|
||||||
COPY owl/ ./owl/
|
COPY owl/ ./owl/
|
||||||
COPY licenses/ ./licenses/
|
COPY licenses/ ./licenses/
|
||||||
COPY assets/ ./assets/
|
COPY assets/ ./assets/
|
||||||
COPY README.md .
|
COPY README.md .
|
||||||
COPY README_zh.md .
|
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 && \
|
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
|
chmod +x /usr/local/bin/xvfb-python
|
||||||
|
|
||||||
# 创建欢迎脚本 | Create welcome script
|
# 创建欢迎脚本
|
||||||
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 && \
|
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 && \
|
||||||
chmod +x /usr/local/bin/owl-welcome
|
chmod +x /usr/local/bin/owl-welcome
|
||||||
|
|
||||||
# 设置工作目录 | Set working directory
|
# 设置工作目录
|
||||||
WORKDIR /app/owl
|
WORKDIR /app/owl
|
||||||
|
|
||||||
# 设置适当的权限 | Set appropriate permissions
|
# 添加健康检查
|
||||||
RUN chown -R owl:owl /app
|
|
||||||
RUN mkdir -p /root/.cache && chown -R owl:owl /root/.cache
|
|
||||||
RUN chmod 644 /app/owl/.env
|
|
||||||
|
|
||||||
|
|
||||||
USER owl
|
|
||||||
# 切换到非root用户 | Switch to non-root user
|
|
||||||
# 注意:如果需要访问/dev/shm,可能仍需要root用户 | Note: If you need to access /dev/shm, you may still need root user
|
|
||||||
# USER owl
|
|
||||||
|
|
||||||
# 添加健康检查 | Add health check
|
|
||||||
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
|
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)"
|
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"]
|
CMD ["/bin/bash", "-c", "owl-welcome && /bin/bash"]
|
||||||
@@ -3,47 +3,29 @@ services:
|
|||||||
build:
|
build:
|
||||||
context: ..
|
context: ..
|
||||||
dockerfile: .container/Dockerfile
|
dockerfile: .container/Dockerfile
|
||||||
args:
|
|
||||||
# 构建参数 | Build arguments
|
|
||||||
BUILDKIT_INLINE_CACHE: 1
|
|
||||||
# 使用BuildKit加速构建 | Use BuildKit to accelerate build
|
|
||||||
cache_from:
|
|
||||||
- python:3.10-slim
|
|
||||||
volumes:
|
volumes:
|
||||||
# 挂载.env文件,方便配置API密钥 | Mount .env file for easy API key configuration
|
# 挂载.env文件,方便配置API密钥
|
||||||
- ../owl/.env:/app/owl/.env
|
- ../owl/.env:/app/owl/.env
|
||||||
# 可选:挂载数据目录 | Optional: Mount data directory
|
# 挂载数据目录
|
||||||
- ./data:/app/data
|
- ./data:/app/data
|
||||||
# 挂载缓存目录,避免重复下载 | Mount cache directories to avoid repeated downloads
|
# 挂载缓存目录,避免重复下载
|
||||||
- playwright-cache:/root/.cache/ms-playwright
|
- ~/.cache/pip:/root/.pip/cache
|
||||||
- pip-cache:/root/.pip/cache
|
- ~/.cache/playwright:/root/.cache/ms-playwright
|
||||||
environment:
|
environment:
|
||||||
# 可以在这里设置环境变量,覆盖.env文件中的设置 | Set environment variables here to override settings in .env file
|
|
||||||
- OPENAI_API_KEY=${OPENAI_API_KEY}
|
- OPENAI_API_KEY=${OPENAI_API_KEY}
|
||||||
# 添加显示相关的环境变量 | Add display-related environment variables
|
|
||||||
- DISPLAY=:99
|
- DISPLAY=:99
|
||||||
- PLAYWRIGHT_BROWSERS_PATH=/root/.cache/ms-playwright
|
|
||||||
# 设置Python不生成.pyc文件,减少磁盘IO | Set Python to not generate .pyc files, reduce disk IO
|
|
||||||
- PYTHONDONTWRITEBYTECODE=1
|
- PYTHONDONTWRITEBYTECODE=1
|
||||||
# 设置Python不缓冲输出,方便查看日志 | Set Python to not buffer output for easier log viewing
|
|
||||||
- PYTHONUNBUFFERED=1
|
- PYTHONUNBUFFERED=1
|
||||||
# 设置终端颜色 | Set terminal color
|
|
||||||
- TERM=xterm-256color
|
- TERM=xterm-256color
|
||||||
# 启用pip缓存 | Enable pip cache
|
|
||||||
- PIP_CACHE_DIR=/root/.pip/cache
|
|
||||||
ports:
|
ports:
|
||||||
# 如果项目有Web界面,可以映射端口 | If the project has a web interface, map ports
|
|
||||||
- "8000:8000"
|
- "8000:8000"
|
||||||
# 使用交互模式运行容器 | Run container in interactive mode
|
|
||||||
stdin_open: true
|
stdin_open: true
|
||||||
tty: true
|
tty: true
|
||||||
# 添加共享内存大小,提高浏览器性能 | Add shared memory size to improve browser performance
|
|
||||||
shm_size: 2gb
|
shm_size: 2gb
|
||||||
# 设置资源限制 | Set resource limits
|
# 简化资源限制
|
||||||
deploy:
|
deploy:
|
||||||
resources:
|
resources:
|
||||||
limits:
|
limits:
|
||||||
cpus: '2'
|
|
||||||
memory: 4G
|
memory: 4G
|
||||||
|
|
||||||
# 定义持久化卷,用于缓存 | Define persistent volumes for caching
|
# 定义持久化卷,用于缓存 | Define persistent volumes for caching
|
||||||
|
|||||||
@@ -165,7 +165,10 @@ REM 在容器中运行指定的脚本,传递查询参数
|
|||||||
REM Run the specified script in container, passing query parameter
|
REM Run the specified script in container, passing query parameter
|
||||||
echo 在Docker容器中使用!PYTHON_CMD!运行脚本...
|
echo 在Docker容器中使用!PYTHON_CMD!运行脚本...
|
||||||
echo Running script in Docker container using !PYTHON_CMD!...
|
echo Running script in Docker container using !PYTHON_CMD!...
|
||||||
%COMPOSE_CMD% exec -T !SERVICE_NAME! !PYTHON_CMD! !SCRIPT_NAME! "!QUERY!"
|
|
||||||
|
REM 修改执行命令,按照README中的方式执行
|
||||||
|
REM Modify execution command according to README
|
||||||
|
%COMPOSE_CMD% exec -T !SERVICE_NAME! bash -c "cd .. && source .venv/bin/activate && cd owl && !PYTHON_CMD! !SCRIPT_NAME! \"!QUERY!\""
|
||||||
|
|
||||||
if errorlevel 0 (
|
if errorlevel 0 (
|
||||||
echo 查询完成!
|
echo 查询完成!
|
||||||
|
|||||||
@@ -36,13 +36,13 @@ else
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
# 检查脚本是否存在 | Check if the script exists
|
# 检查脚本是否存在 | Check if the script exists
|
||||||
if [ ! -f "owl/$SCRIPT_NAME" ]; then
|
if [ ! -f "../owl/$SCRIPT_NAME" ]; then
|
||||||
echo "错误 | Error: 脚本 | Script 'owl/$SCRIPT_NAME' 不存在 | does not exist"
|
echo "错误 | Error: 脚本 | Script '../owl/$SCRIPT_NAME' 不存在 | does not exist"
|
||||||
echo "可用的脚本有 | Available scripts:"
|
echo "可用的脚本有 | Available scripts:"
|
||||||
if [[ "$OS_TYPE" == MINGW* ]] || [[ "$OS_TYPE" == CYGWIN* ]] || [[ "$OS_TYPE" == MSYS* ]]; then
|
if [[ "$OS_TYPE" == MINGW* ]] || [[ "$OS_TYPE" == CYGWIN* ]] || [[ "$OS_TYPE" == MSYS* ]]; then
|
||||||
find owl -name "*.py" | grep -v "__" | sed 's/\\/\//g'
|
find ../owl -name "*.py" | grep -v "__" | sed 's/\\/\//g'
|
||||||
else
|
else
|
||||||
ls -1 owl/*.py | grep -v "__"
|
ls -1 ../owl/*.py | grep -v "__"
|
||||||
fi
|
fi
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
@@ -51,8 +51,8 @@ echo "使用脚本 | Using script: $SCRIPT_NAME"
|
|||||||
echo "查询内容 | Query content: $QUERY"
|
echo "查询内容 | Query content: $QUERY"
|
||||||
|
|
||||||
# 从docker-compose.yml获取服务名称(如果文件存在) | Get service name from docker-compose.yml (if file exists)
|
# 从docker-compose.yml获取服务名称(如果文件存在) | Get service name from docker-compose.yml (if file exists)
|
||||||
if [ -f ".container/docker-compose.yml" ]; then
|
if [ -f "docker-compose.yml" ]; then
|
||||||
DETECTED_SERVICE=$(grep -E "^ [a-zA-Z0-9_-]*:" .container/docker-compose.yml | head -1 | sed 's/^ \(.*\):.*/\1/')
|
DETECTED_SERVICE=$(grep -E "^ [a-zA-Z0-9_-]*:" docker-compose.yml | head -1 | sed 's/^ \(.*\):.*/\1/')
|
||||||
if [ ! -z "$DETECTED_SERVICE" ]; then
|
if [ ! -z "$DETECTED_SERVICE" ]; then
|
||||||
SERVICE_NAME="$DETECTED_SERVICE"
|
SERVICE_NAME="$DETECTED_SERVICE"
|
||||||
echo "从docker-compose.yml检测到服务名称 | Detected service name from docker-compose.yml: $SERVICE_NAME"
|
echo "从docker-compose.yml检测到服务名称 | Detected service name from docker-compose.yml: $SERVICE_NAME"
|
||||||
@@ -119,11 +119,11 @@ echo "在Docker容器中使用 $PYTHON_CMD 运行脚本... | Running script in D
|
|||||||
# 根据操作系统类型执行不同的命令 | Execute different commands based on operating system type
|
# 根据操作系统类型执行不同的命令 | Execute different commands based on operating system type
|
||||||
if [[ "$OS_TYPE" == MINGW* ]] || [[ "$OS_TYPE" == CYGWIN* ]] || [[ "$OS_TYPE" == MSYS* ]]; then
|
if [[ "$OS_TYPE" == MINGW* ]] || [[ "$OS_TYPE" == CYGWIN* ]] || [[ "$OS_TYPE" == MSYS* ]]; then
|
||||||
# Windows可能需要特殊处理引号 | Windows may need special handling for quotes
|
# Windows可能需要特殊处理引号 | Windows may need special handling for quotes
|
||||||
winpty $COMPOSE_CMD exec -T $SERVICE_NAME $PYTHON_CMD $SCRIPT_NAME "$QUERY"
|
winpty $COMPOSE_CMD exec -T $SERVICE_NAME bash -c "cd .. && source .venv/bin/activate && cd owl && $PYTHON_CMD $SCRIPT_NAME \"$QUERY\""
|
||||||
RESULT=$?
|
RESULT=$?
|
||||||
else
|
else
|
||||||
# macOS 或 Linux | macOS or Linux
|
# macOS 或 Linux | macOS or Linux
|
||||||
$COMPOSE_CMD exec -T $SERVICE_NAME $PYTHON_CMD $SCRIPT_NAME "$QUERY"
|
$COMPOSE_CMD exec -T $SERVICE_NAME bash -c "cd .. && source .venv/bin/activate && cd owl && $PYTHON_CMD $SCRIPT_NAME \"$QUERY\""
|
||||||
RESULT=$?
|
RESULT=$?
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|||||||
@@ -261,9 +261,14 @@ cp owl/.env_template owl/.env
|
|||||||
|
|
||||||
# Option 1: Using docker-compose directly
|
# Option 1: Using docker-compose directly
|
||||||
cd .container
|
cd .container
|
||||||
|
|
||||||
docker-compose up -d
|
docker-compose up -d
|
||||||
|
|
||||||
# Run OWL inside the container
|
# Run OWL inside the container
|
||||||
docker-compose exec owl bash -c "xvfb-python run.py"
|
docker-compose exec owl bash -c "cd .. && source .venv/bin/activate && cd owl"
|
||||||
|
|
||||||
|
#run example demo script
|
||||||
|
xvfb-python run.py
|
||||||
|
|
||||||
# Option 2: Build and run using the provided scripts
|
# Option 2: Build and run using the provided scripts
|
||||||
cd .container
|
cd .container
|
||||||
|
|||||||
@@ -257,9 +257,13 @@ cp owl/.env_template owl/.env
|
|||||||
|
|
||||||
# 选项1:直接使用docker-compose
|
# 选项1:直接使用docker-compose
|
||||||
cd .container
|
cd .container
|
||||||
|
|
||||||
docker-compose up -d
|
docker-compose up -d
|
||||||
|
|
||||||
# 在容器中运行OWL
|
# 在容器中运行OWL
|
||||||
docker-compose exec owl bash -c "xvfb-python run.py"
|
docker-compose exec owl bash -c "cd .. && source .venv/bin/activate && cd owl"
|
||||||
|
|
||||||
|
xvfb-python run.py
|
||||||
|
|
||||||
# 选项2:使用提供的脚本构建和运行
|
# 选项2:使用提供的脚本构建和运行
|
||||||
cd .container
|
cd .container
|
||||||
|
|||||||
Reference in New Issue
Block a user