Wendong-Fan commited on
Commit
e587de0
·
2 Parent(s): c321a6a ec40ee1

update docker (#328)

Browse files
.container/Dockerfile CHANGED
@@ -1,6 +1,6 @@
1
  FROM python:3.10-slim
2
 
3
- # 设置环境变量
4
  ENV PYTHONDONTWRITEBYTECODE=1 \
5
  PYTHONUNBUFFERED=1 \
6
  PIP_NO_CACHE_DIR=0 \
@@ -10,51 +10,50 @@ ENV PYTHONDONTWRITEBYTECODE=1 \
10
  DEBIAN_FRONTEND=noninteractive \
11
  PATH="/app/.venv/bin:$PATH"
12
 
13
- # 设置工作目录
14
  WORKDIR /app
15
 
16
- # 安装系统依赖(合并为一个RUN命令减少层数)
17
  RUN apt-get update && apt-get install -y --no-install-recommends \
18
  curl git ffmpeg libsm6 libxext6 xvfb xauth x11-utils \
19
- build-essential python3-dev \
20
  && apt-get clean \
21
  && rm -rf /var/lib/apt/lists/*
22
 
23
- # 安装uv工具
24
  RUN pip install uv
25
 
26
- # 复制构建项目文件
27
  COPY pyproject.toml .
28
  COPY README.md .
29
- # 如果README.md不存在则创建
30
- RUN if [ ! -f "README.md" ]; then echo -e "# OWL Project\n\n这是OWL项目的Docker环境。" > README.md; fi
31
 
32
- # 创建虚拟环境并安装依赖
33
  RUN uv venv .venv --python=3.10 && \
34
  . .venv/bin/activate && \
35
  uv pip install -e .
36
 
37
- # 复制运行项目文件
38
  COPY owl/ ./owl/
39
  COPY licenses/ ./licenses/
40
  COPY assets/ ./assets/
41
  COPY README_zh.md .
42
 
43
-
44
- # 创建启动脚本
45
  RUN echo '#!/bin/bash\nxvfb-run --auto-servernum --server-args="-screen 0 1280x960x24" python "$@"' > /usr/local/bin/xvfb-python && \
46
  chmod +x /usr/local/bin/xvfb-python
47
 
48
- # 创建欢迎脚本
49
- 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 && \
50
  chmod +x /usr/local/bin/owl-welcome
51
 
52
- # 设置工作目录
53
  WORKDIR /app/owl
54
 
55
- # 添加健康检查
56
  HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
57
  CMD python -c "import sys; sys.exit(0 if __import__('os').path.exists('/app/owl') else 1)"
58
 
59
- # 容器启动命令
60
  CMD ["/bin/bash", "-c", "owl-welcome && /bin/bash"]
 
1
  FROM python:3.10-slim
2
 
3
+ # Set environment variables
4
  ENV PYTHONDONTWRITEBYTECODE=1 \
5
  PYTHONUNBUFFERED=1 \
6
  PIP_NO_CACHE_DIR=0 \
 
10
  DEBIAN_FRONTEND=noninteractive \
11
  PATH="/app/.venv/bin:$PATH"
12
 
13
+ # Set working directory
14
  WORKDIR /app
15
 
16
+ # Install system dependencies (combine into one RUN command to reduce layers)
17
  RUN apt-get update && apt-get install -y --no-install-recommends \
18
  curl git ffmpeg libsm6 libxext6 xvfb xauth x11-utils \
19
+ build-essential python3-dev vim\
20
  && apt-get clean \
21
  && rm -rf /var/lib/apt/lists/*
22
 
23
+ # Install uv tool
24
  RUN pip install uv
25
 
26
+ # Copy project build files
27
  COPY pyproject.toml .
28
  COPY README.md .
29
+ # Create README.md if it doesn't exist
30
+ RUN if [ ! -f "README.md" ]; then echo -e "# OWL Project\n\nThis is the Docker environment for the OWL project." > README.md; fi
31
 
32
+ # Create virtual environment and install dependencies
33
  RUN uv venv .venv --python=3.10 && \
34
  . .venv/bin/activate && \
35
  uv pip install -e .
36
 
37
+ # Copy project runtime files
38
  COPY owl/ ./owl/
39
  COPY licenses/ ./licenses/
40
  COPY assets/ ./assets/
41
  COPY README_zh.md .
42
 
43
+ # Create startup script
 
44
  RUN echo '#!/bin/bash\nxvfb-run --auto-servernum --server-args="-screen 0 1280x960x24" python "$@"' > /usr/local/bin/xvfb-python && \
45
  chmod +x /usr/local/bin/xvfb-python
46
 
47
+ # Create welcome script
48
+ 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 && \
49
  chmod +x /usr/local/bin/owl-welcome
50
 
51
+ # Set working directory
52
  WORKDIR /app/owl
53
 
54
+ # Add health check
55
  HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
56
  CMD python -c "import sys; sys.exit(0 if __import__('os').path.exists('/app/owl') else 1)"
57
 
58
+ # Container startup command
59
  CMD ["/bin/bash", "-c", "owl-welcome && /bin/bash"]
.container/docker-compose.yml CHANGED
@@ -10,13 +10,13 @@ services:
10
  # dockerfile: .container/Dockerfile
11
 
12
  volumes:
13
- # 挂载.env文件,方便配置API密钥
14
  - ../owl/.env:/app/owl/.env
15
- # 挂载example文件夹,以支持docker容器内运行代码案例
16
  - ../examples:/app/examples
17
- # 挂载数据目录
18
  - ./data:/app/owl/data
19
- # 挂载缓存目录,避免重复下载
20
  - ~/.cache/pip:/root/.pip/cache
21
  - ~/.cache/playwright:/root/.cache/ms-playwright
22
  environment:
@@ -25,18 +25,21 @@ services:
25
  - PYTHONDONTWRITEBYTECODE=1
26
  - PYTHONUNBUFFERED=1
27
  - TERM=xterm-256color
 
 
 
28
  ports:
29
  - "7860:7860"
30
  stdin_open: true
31
  tty: true
32
  shm_size: 2gb
33
- # 简化资源限制
34
  deploy:
35
  resources:
36
  limits:
37
  memory: 4G
38
 
39
- # 定义持久化卷,用于缓存 | Define persistent volumes for caching
40
  volumes:
41
  playwright-cache:
42
- pip-cache:
 
10
  # dockerfile: .container/Dockerfile
11
 
12
  volumes:
13
+ # Mount .env file for easy API key configuration
14
  - ../owl/.env:/app/owl/.env
15
+ # Mount examples folder to support running code examples inside the Docker container
16
  - ../examples:/app/examples
17
+ # Mount data directory
18
  - ./data:/app/owl/data
19
+ # Mount cache directories to avoid repeated downloads
20
  - ~/.cache/pip:/root/.pip/cache
21
  - ~/.cache/playwright:/root/.cache/ms-playwright
22
  environment:
 
25
  - PYTHONDONTWRITEBYTECODE=1
26
  - PYTHONUNBUFFERED=1
27
  - TERM=xterm-256color
28
+ - GRADIO_SERVER_NAME=0.0.0.0
29
+ - GRADIO_SERVER_PORT=7860
30
+ - PYTHONPATH=.
31
  ports:
32
  - "7860:7860"
33
  stdin_open: true
34
  tty: true
35
  shm_size: 2gb
36
+ # Simplify resource limits
37
  deploy:
38
  resources:
39
  limits:
40
  memory: 4G
41
 
42
+ # Define persistent volumes for caching
43
  volumes:
44
  playwright-cache:
45
+ pip-cache:
owl/webapp.py CHANGED
@@ -1287,7 +1287,7 @@ def main():
1287
  app = create_ui()
1288
 
1289
  app.queue()
1290
- app.launch(share=False, server_name="127.0.0.1", server_port=7860)
1291
  except Exception as e:
1292
  logging.error(f"Error occurred while starting the application: {str(e)}")
1293
  print(f"Error occurred while starting the application: {str(e)}")
 
1287
  app = create_ui()
1288
 
1289
  app.queue()
1290
+ app.launch(share=False)
1291
  except Exception as e:
1292
  logging.error(f"Error occurred while starting the application: {str(e)}")
1293
  print(f"Error occurred while starting the application: {str(e)}")
owl/webapp_zh.py CHANGED
@@ -1257,7 +1257,7 @@ def main():
1257
  app = create_ui()
1258
 
1259
  app.queue()
1260
- app.launch(share=False, server_name="127.0.0.1", server_port=7860)
1261
  except Exception as e:
1262
  logging.error(f"启动应用程序时发生错误: {str(e)}")
1263
  print(f"启动应用程序时发生错误: {str(e)}")
 
1257
  app = create_ui()
1258
 
1259
  app.queue()
1260
+ app.launch(share=False)
1261
  except Exception as e:
1262
  logging.error(f"启动应用程序时发生错误: {str(e)}")
1263
  print(f"启动应用程序时发生错误: {str(e)}")