javaeeduke commited on
Commit
4e8da65
·
verified ·
1 Parent(s): 7769664

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +30 -9
Dockerfile CHANGED
@@ -1,18 +1,39 @@
1
  FROM docker.io/library/python:3.10
2
 
3
- # 1. 安装基础依赖
4
- RUN pip install --no-cache-dir pipx && pipx ensurepath
5
 
6
- # 2. 克隆源码并进行源码安装
 
 
 
7
  RUN git clone https://github.com/Panniantong/agent-reach.git /opt/agent-reach
8
  RUN pip install -e /opt/agent-reach
9
 
10
- # 3. 授予 Hugging Face 默认用户(UID 1000)完全的读写权限,防止后续报错
11
- RUN chmod -R 777 /opt/agent-reach
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
12
 
13
- # 4. 声明 Hugging Face 必须的 7860 端口
14
  EXPOSE 7860
15
 
16
- # 5. 【核心避坑】使用 Python 自带的轻量服务器强行占领 7860 端口,实现完美保活
17
- # 启动我们的简易后端
18
- CMD ["python", "app.py"]
 
1
  FROM docker.io/library/python:3.10
2
 
3
+ # 1. 设置清晰的工作目录
4
+ WORKDIR /app
5
 
6
+ # 2. 安装基础依赖
7
+ RUN pip install --no-cache-dir pipx uvicorn fastapi && pipx ensurepath
8
+
9
+ # 3. 克隆源码并进行源码安装
10
  RUN git clone https://github.com/Panniantong/agent-reach.git /opt/agent-reach
11
  RUN pip install -e /opt/agent-reach
12
 
13
+ # 4. 【核心】直接在容器内生成 app.py 接口文件
14
+ RUN echo 'import os, subprocess\n\
15
+ from fastapi import FastAPI, Query\n\
16
+ import uvicorn\n\
17
+ app = FastAPI()\n\
18
+ @app.get("/")\n\
19
+ def index():\n\
20
+ return {"status": "running", "msg": "Welcome to Agent-Reach API"}\n\
21
+ @app.get("/cmd")\n\
22
+ def run_command(q: str = Query(..., description="command")):\n\
23
+ try:\n\
24
+ result = subprocess.check_output(q, shell=True, stderr=subprocess.STDOUT, text=True)\n\
25
+ return {"code": 0, "output": result}\n\
26
+ except subprocess.CalledProcessError as e:\n\
27
+ return {"code": 1, "output": e.output}\n\
28
+ if __name__ == "__main__":\n\
29
+ uvicorn.run(app, host="0.0.0.0", port=7860)\n\
30
+ ' > /app/app.py
31
+
32
+ # 5. 授予 Hugging Face 默认用户完全的读写权限
33
+ RUN chmod -R 777 /app /opt/agent-reach
34
 
35
+ # 6. 声明端口
36
  EXPOSE 7860
37
 
38
+ # 7. 绝对路径启动,彻底杜绝 No such file 错误
39
+ CMD ["python", "/app/app.py"]