zjrwtx commited on
Commit
c42752c
·
1 Parent(s): 7a11f89

update readme

Browse files
.container/Dockerfile CHANGED
@@ -1,107 +1,57 @@
1
- # 使用ARG定义可配置的构建参数 | Using ARG to define configurable build parameters
2
- ARG PYTHON_VERSION=3.10
3
- ARG PIP_INDEX_URL=https://pypi.tuna.tsinghua.edu.cn/simple
4
- ARG PLAYWRIGHT_DOWNLOAD_HOST=https://npmmirror.com/mirrors/playwright
5
-
6
- # 第一阶段:构建依赖 | Stage 1: Build dependencies
7
- FROM python:${PYTHON_VERSION}-slim AS builder
8
-
9
- # 设置工作目录 | Set working directory
10
- WORKDIR /build
11
-
12
- # 设置pip镜像源以加速下载 | Set pip mirror to accelerate downloads
13
- ARG PIP_INDEX_URL
14
- RUN pip config set global.index-url ${PIP_INDEX_URL}
15
-
16
- # 安装构建依赖 | Install build dependencies
17
- RUN apt-get update && apt-get install -y --no-install-recommends \
18
- build-essential \
19
- && apt-get clean \
20
- && rm -rf /var/lib/apt/lists/*
21
-
22
- # 复制并安装requirements.txt | Copy and install requirements.txt
23
- COPY requirements.txt .
24
- RUN pip install --no-cache-dir --prefix=/install -r requirements.txt
25
-
26
- # 第二阶段:运行时环境 | Stage 2: Runtime environment
27
- FROM python:${PYTHON_VERSION}-slim
28
-
29
- # 添加构建信息标签 | Add build information labels
30
- ARG BUILD_DATE
31
- ARG VERSION
32
- LABEL org.opencontainers.image.created="${BUILD_DATE}" \
33
- org.opencontainers.image.version="${VERSION}" \
34
- org.opencontainers.image.title="OWL Project" \
35
- org.opencontainers.image.description="OWL Project Docker Image" \
36
- org.opencontainers.image.source="https://github.com/yourusername/owl"
37
-
38
- # 设置工作目录 | Set working directory
39
  WORKDIR /app
40
 
41
- # 设置pip镜像源以加速下载 | Set pip mirror to accelerate downloads
42
- ARG PIP_INDEX_URL
43
- RUN pip config set global.index-url ${PIP_INDEX_URL}
44
-
45
- # 从builder阶段复制已安装的Python包 | Copy installed Python packages from builder stage
46
- COPY --from=builder /install /usr/local
47
-
48
- # 优化apt安装,减少层数 | Optimize apt installation, reduce layers
49
  RUN apt-get update && apt-get install -y --no-install-recommends \
50
- curl \
51
- git \
52
- ffmpeg \
53
- libsm6 \
54
- libxext6 \
55
- # 添加xvfb和相关依赖 | Add xvfb and related dependencies
56
- xvfb \
57
- xauth \
58
- x11-utils \
59
  && apt-get clean \
60
  && rm -rf /var/lib/apt/lists/*
61
 
62
- # 安装 Playwright 依赖(使用国内镜像源) | Install Playwright dependencies (using Chinese mirror)
63
- ENV PLAYWRIGHT_BROWSERS_PATH=/root/.cache/ms-playwright
64
- ARG PLAYWRIGHT_DOWNLOAD_HOST
65
- ENV PLAYWRIGHT_DOWNLOAD_HOST=${PLAYWRIGHT_DOWNLOAD_HOST}
66
- RUN pip install --no-cache-dir playwright && \
67
- playwright install --with-deps chromium
 
 
 
 
68
 
69
- # 创建非root用户 | Create non-root user
70
- RUN groupadd -r owl && useradd -r -g owl -m owl
71
 
72
- # 复制项目文件 | Copy project files
73
  COPY owl/ ./owl/
74
  COPY licenses/ ./licenses/
75
  COPY assets/ ./assets/
76
  COPY README.md .
77
  COPY README_zh.md .
78
 
79
-
80
- # 创建启动脚本 | Create startup script
81
  RUN echo '#!/bin/bash\nxvfb-run --auto-servernum --server-args="-screen 0 1280x960x24" python "$@"' > /usr/local/bin/xvfb-python && \
82
  chmod +x /usr/local/bin/xvfb-python
83
 
84
- # 创建欢迎脚本 | Create welcome script
85
  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 && \
86
  chmod +x /usr/local/bin/owl-welcome
87
 
88
- # 设置工作目录 | Set working directory
89
  WORKDIR /app/owl
90
 
91
- # 设置适当的权限 | Set appropriate permissions
92
- RUN chown -R owl:owl /app
93
- RUN mkdir -p /root/.cache && chown -R owl:owl /root/.cache
94
- RUN chmod 644 /app/owl/.env
95
-
96
-
97
- USER owl
98
- # 切换到非root用户 | Switch to non-root user
99
- # 注意:如果需要访问/dev/shm,可能仍需要root用户 | Note: If you need to access /dev/shm, you may still need root user
100
- # USER owl
101
-
102
- # 添加健康检查 | Add health check
103
  HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
104
  CMD python -c "import sys; sys.exit(0 if __import__('os').path.exists('/app/owl') else 1)"
105
 
106
- # 容器启动命令 | Container startup command
107
  CMD ["/bin/bash", "-c", "owl-welcome && /bin/bash"]
 
1
+ FROM python:3.10-slim
2
+
3
+ # 设置环境变量
4
+ ENV PYTHONDONTWRITEBYTECODE=1 \
5
+ PYTHONUNBUFFERED=1 \
6
+ PIP_NO_CACHE_DIR=0 \
7
+ PIP_INDEX_URL=https://pypi.tuna.tsinghua.edu.cn/simple \
8
+ PLAYWRIGHT_DOWNLOAD_HOST=https://npmmirror.com/mirrors/playwright \
9
+ PLAYWRIGHT_BROWSERS_PATH=/root/.cache/ms-playwright \
10
+ DEBIAN_FRONTEND=noninteractive
11
+
12
+ # 设置工作目录
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
13
  WORKDIR /app
14
 
15
+ # 安装系统依赖(合并为一个RUN命令减少层数)
 
 
 
 
 
 
 
16
  RUN apt-get update && apt-get install -y --no-install-recommends \
17
+ curl git ffmpeg libsm6 libxext6 xvfb xauth x11-utils \
18
+ gcc python3-dev \
 
 
 
 
 
 
 
19
  && apt-get clean \
20
  && rm -rf /var/lib/apt/lists/*
21
 
22
+ COPY pyproject.toml .
23
+ # 创建README.md文件以避免构建错误
24
+ RUN echo "# OWL Project\n\n这是OWL项目的Docker环境。" > README.md
25
+ # 安装uv工具
26
+ RUN pip install uv
27
+
28
+ # 创建虚拟环境并安装依赖
29
+ RUN uv venv .venv --python=3.10 && \
30
+ . .venv/bin/activate && \
31
+ uv pip install -e .
32
 
 
 
33
 
34
+ # 复制项目文件
35
  COPY owl/ ./owl/
36
  COPY licenses/ ./licenses/
37
  COPY assets/ ./assets/
38
  COPY README.md .
39
  COPY README_zh.md .
40
 
41
+ # 创建启动脚本
 
42
  RUN echo '#!/bin/bash\nxvfb-run --auto-servernum --server-args="-screen 0 1280x960x24" python "$@"' > /usr/local/bin/xvfb-python && \
43
  chmod +x /usr/local/bin/xvfb-python
44
 
45
+ # 创建欢迎脚本
46
  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 && \
47
  chmod +x /usr/local/bin/owl-welcome
48
 
49
+ # 设置工作目录
50
  WORKDIR /app/owl
51
 
52
+ # 添加健康检查
 
 
 
 
 
 
 
 
 
 
 
53
  HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
54
  CMD python -c "import sys; sys.exit(0 if __import__('os').path.exists('/app/owl') else 1)"
55
 
56
+ # 容器启动命令
57
  CMD ["/bin/bash", "-c", "owl-welcome && /bin/bash"]
.container/docker-compose.yml CHANGED
@@ -3,47 +3,29 @@ services:
3
  build:
4
  context: ..
5
  dockerfile: .container/Dockerfile
6
- args:
7
- # 构建参数 | Build arguments
8
- BUILDKIT_INLINE_CACHE: 1
9
- # 使用BuildKit加速构建 | Use BuildKit to accelerate build
10
- cache_from:
11
- - python:3.10-slim
12
  volumes:
13
- # 挂载.env文件,方便配置API密钥 | Mount .env file for easy API key configuration
14
  - ../owl/.env:/app/owl/.env
15
- # 可选:挂载数据目录 | Optional: Mount data directory
16
  - ./data:/app/data
17
- # 挂载缓存目录,避免重复下载 | Mount cache directories to avoid repeated downloads
18
- - playwright-cache:/root/.cache/ms-playwright
19
- - pip-cache:/root/.pip/cache
20
  environment:
21
- # 可以在这里设置环境变量,覆盖.env文件中的设置 | Set environment variables here to override settings in .env file
22
  - OPENAI_API_KEY=${OPENAI_API_KEY}
23
- # 添加显示相关的环境变量 | Add display-related environment variables
24
  - DISPLAY=:99
25
- - PLAYWRIGHT_BROWSERS_PATH=/root/.cache/ms-playwright
26
- # 设置Python不生成.pyc文件,减少磁盘IO | Set Python to not generate .pyc files, reduce disk IO
27
  - PYTHONDONTWRITEBYTECODE=1
28
- # 设置Python不缓冲输出,方便查看日志 | Set Python to not buffer output for easier log viewing
29
  - PYTHONUNBUFFERED=1
30
- # 设置终端颜色 | Set terminal color
31
  - TERM=xterm-256color
32
- # 启用pip缓存 | Enable pip cache
33
- - PIP_CACHE_DIR=/root/.pip/cache
34
  ports:
35
- # 如果项目有Web界面,可以映射端口 | If the project has a web interface, map ports
36
  - "8000:8000"
37
- # 使用交互模式运行容器 | Run container in interactive mode
38
  stdin_open: true
39
  tty: true
40
- # 添加共享内存大小,提高浏览器性能 | Add shared memory size to improve browser performance
41
  shm_size: 2gb
42
- # 设置资源限制 | Set resource limits
43
  deploy:
44
  resources:
45
  limits:
46
- cpus: '2'
47
  memory: 4G
48
 
49
  # 定义持久化卷,用于缓存 | Define persistent volumes for caching
 
3
  build:
4
  context: ..
5
  dockerfile: .container/Dockerfile
 
 
 
 
 
 
6
  volumes:
7
+ # 挂载.env文件,方便配置API密钥
8
  - ../owl/.env:/app/owl/.env
9
+ # 挂载数据目录
10
  - ./data:/app/data
11
+ # 挂载缓存目录,避免重复下载
12
+ - ~/.cache/pip:/root/.pip/cache
13
+ - ~/.cache/playwright:/root/.cache/ms-playwright
14
  environment:
 
15
  - OPENAI_API_KEY=${OPENAI_API_KEY}
 
16
  - DISPLAY=:99
 
 
17
  - PYTHONDONTWRITEBYTECODE=1
 
18
  - PYTHONUNBUFFERED=1
 
19
  - TERM=xterm-256color
 
 
20
  ports:
 
21
  - "8000:8000"
 
22
  stdin_open: true
23
  tty: true
 
24
  shm_size: 2gb
25
+ # 简化资源限制
26
  deploy:
27
  resources:
28
  limits:
 
29
  memory: 4G
30
 
31
  # 定义持久化卷,用于缓存 | Define persistent volumes for caching
.container/run_in_docker.bat CHANGED
@@ -165,7 +165,10 @@ REM 在容器中运行指定的脚本,传递查询参数
165
  REM Run the specified script in container, passing query parameter
166
  echo 在Docker容器中使用!PYTHON_CMD!运行脚本...
167
  echo Running script in Docker container using !PYTHON_CMD!...
168
- %COMPOSE_CMD% exec -T !SERVICE_NAME! !PYTHON_CMD! !SCRIPT_NAME! "!QUERY!"
 
 
 
169
 
170
  if errorlevel 0 (
171
  echo 查询完成!
 
165
  REM Run the specified script in container, passing query parameter
166
  echo 在Docker容器中使用!PYTHON_CMD!运行脚本...
167
  echo Running script in Docker container using !PYTHON_CMD!...
168
+
169
+ REM 修改执行命令,按照README中的方式执行
170
+ REM Modify execution command according to README
171
+ %COMPOSE_CMD% exec -T !SERVICE_NAME! bash -c "cd .. && source .venv/bin/activate && cd owl && !PYTHON_CMD! !SCRIPT_NAME! \"!QUERY!\""
172
 
173
  if errorlevel 0 (
174
  echo 查询完成!
.container/run_in_docker.sh CHANGED
@@ -36,13 +36,13 @@ else
36
  fi
37
 
38
  # 检查脚本是否存在 | Check if the script exists
39
- if [ ! -f "owl/$SCRIPT_NAME" ]; then
40
- echo "错误 | Error: 脚本 | Script 'owl/$SCRIPT_NAME' 不存在 | does not exist"
41
  echo "可用的脚本有 | Available scripts:"
42
  if [[ "$OS_TYPE" == MINGW* ]] || [[ "$OS_TYPE" == CYGWIN* ]] || [[ "$OS_TYPE" == MSYS* ]]; then
43
- find owl -name "*.py" | grep -v "__" | sed 's/\\/\//g'
44
  else
45
- ls -1 owl/*.py | grep -v "__"
46
  fi
47
  exit 1
48
  fi
@@ -51,8 +51,8 @@ echo "使用脚本 | Using script: $SCRIPT_NAME"
51
  echo "查询内容 | Query content: $QUERY"
52
 
53
  # 从docker-compose.yml获取服务名称(如果文件存在) | Get service name from docker-compose.yml (if file exists)
54
- if [ -f ".container/docker-compose.yml" ]; then
55
- DETECTED_SERVICE=$(grep -E "^ [a-zA-Z0-9_-]*:" .container/docker-compose.yml | head -1 | sed 's/^ \(.*\):.*/\1/')
56
  if [ ! -z "$DETECTED_SERVICE" ]; then
57
  SERVICE_NAME="$DETECTED_SERVICE"
58
  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
119
  # 根据操作系统类型执行不同的命令 | Execute different commands based on operating system type
120
  if [[ "$OS_TYPE" == MINGW* ]] || [[ "$OS_TYPE" == CYGWIN* ]] || [[ "$OS_TYPE" == MSYS* ]]; then
121
  # Windows可能需要特殊处理引号 | Windows may need special handling for quotes
122
- winpty $COMPOSE_CMD exec -T $SERVICE_NAME $PYTHON_CMD $SCRIPT_NAME "$QUERY"
123
  RESULT=$?
124
  else
125
  # macOS 或 Linux | macOS or Linux
126
- $COMPOSE_CMD exec -T $SERVICE_NAME $PYTHON_CMD $SCRIPT_NAME "$QUERY"
127
  RESULT=$?
128
  fi
129
 
 
36
  fi
37
 
38
  # 检查脚本是否存在 | Check if the script exists
39
+ if [ ! -f "../owl/$SCRIPT_NAME" ]; then
40
+ echo "错误 | Error: 脚本 | Script '../owl/$SCRIPT_NAME' 不存在 | does not exist"
41
  echo "可用的脚本有 | Available scripts:"
42
  if [[ "$OS_TYPE" == MINGW* ]] || [[ "$OS_TYPE" == CYGWIN* ]] || [[ "$OS_TYPE" == MSYS* ]]; then
43
+ find ../owl -name "*.py" | grep -v "__" | sed 's/\\/\//g'
44
  else
45
+ ls -1 ../owl/*.py | grep -v "__"
46
  fi
47
  exit 1
48
  fi
 
51
  echo "查询内容 | Query content: $QUERY"
52
 
53
  # 从docker-compose.yml获取服务名称(如果文件存在) | Get service name from docker-compose.yml (if file exists)
54
+ if [ -f "docker-compose.yml" ]; then
55
+ DETECTED_SERVICE=$(grep -E "^ [a-zA-Z0-9_-]*:" docker-compose.yml | head -1 | sed 's/^ \(.*\):.*/\1/')
56
  if [ ! -z "$DETECTED_SERVICE" ]; then
57
  SERVICE_NAME="$DETECTED_SERVICE"
58
  echo "从docker-compose.yml检测到服务名称 | Detected service name from docker-compose.yml: $SERVICE_NAME"
 
119
  # 根据操作系统类型执行不同的命令 | Execute different commands based on operating system type
120
  if [[ "$OS_TYPE" == MINGW* ]] || [[ "$OS_TYPE" == CYGWIN* ]] || [[ "$OS_TYPE" == MSYS* ]]; then
121
  # Windows可能需要特殊处理引号 | Windows may need special handling for quotes
122
+ winpty $COMPOSE_CMD exec -T $SERVICE_NAME bash -c "cd .. && source .venv/bin/activate && cd owl && $PYTHON_CMD $SCRIPT_NAME \"$QUERY\""
123
  RESULT=$?
124
  else
125
  # macOS 或 Linux | macOS or Linux
126
+ $COMPOSE_CMD exec -T $SERVICE_NAME bash -c "cd .. && source .venv/bin/activate && cd owl && $PYTHON_CMD $SCRIPT_NAME \"$QUERY\""
127
  RESULT=$?
128
  fi
129
 
README.md CHANGED
@@ -261,9 +261,14 @@ cp owl/.env_template owl/.env
261
 
262
  # Option 1: Using docker-compose directly
263
  cd .container
 
264
  docker-compose up -d
 
265
  # Run OWL inside the container
266
- docker-compose exec owl bash -c "xvfb-python run.py"
 
 
 
267
 
268
  # Option 2: Build and run using the provided scripts
269
  cd .container
 
261
 
262
  # Option 1: Using docker-compose directly
263
  cd .container
264
+
265
  docker-compose up -d
266
+
267
  # Run OWL inside the container
268
+ docker-compose exec owl bash -c "cd .. && source .venv/bin/activate && cd owl"
269
+
270
+ #run example demo script
271
+ xvfb-python run.py
272
 
273
  # Option 2: Build and run using the provided scripts
274
  cd .container
README_zh.md CHANGED
@@ -257,9 +257,13 @@ cp owl/.env_template owl/.env
257
 
258
  # 选项1:直接使用docker-compose
259
  cd .container
 
260
  docker-compose up -d
 
261
  # 在容器中运行OWL
262
- docker-compose exec owl bash -c "xvfb-python run.py"
 
 
263
 
264
  # 选项2:使用提供的脚本构建和运行
265
  cd .container
 
257
 
258
  # 选项1:直接使用docker-compose
259
  cd .container
260
+
261
  docker-compose up -d
262
+
263
  # 在容器中运行OWL
264
+ docker-compose exec owl bash -c "cd .. && source .venv/bin/activate && cd owl"
265
+
266
+ xvfb-python run.py
267
 
268
  # 选项2:使用提供的脚本构建和运行
269
  cd .container