Spaces:
Sleeping
Sleeping
Update Dockerfile
Browse files- Dockerfile +37 -2
Dockerfile
CHANGED
|
@@ -1,15 +1,50 @@
|
|
| 1 |
-
FROM
|
| 2 |
|
|
|
|
| 3 |
RUN apt-get update && apt-get install -y \
|
| 4 |
wget \
|
| 5 |
curl \
|
| 6 |
ca-certificates \
|
|
|
|
|
|
|
|
|
|
| 7 |
&& rm -rf /var/lib/apt/lists/*
|
| 8 |
|
|
|
|
| 9 |
WORKDIR /app
|
| 10 |
|
|
|
|
| 11 |
RUN curl -L -o llamafile \
|
| 12 |
https://github.com/Mozilla-Ocho/llamafile/releases/download/0.9.2/llamafile-0.9.2 \
|
| 13 |
&& chmod +x llamafile
|
| 14 |
|
| 15 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
FROM ubuntu:22.04
|
| 2 |
|
| 3 |
+
# 1. 安装系统依赖 + Python
|
| 4 |
RUN apt-get update && apt-get install -y \
|
| 5 |
wget \
|
| 6 |
curl \
|
| 7 |
ca-certificates \
|
| 8 |
+
python3 \
|
| 9 |
+
python3-pip \
|
| 10 |
+
python3-venv \
|
| 11 |
&& rm -rf /var/lib/apt/lists/*
|
| 12 |
|
| 13 |
+
# 2. 设置工作目录
|
| 14 |
WORKDIR /app
|
| 15 |
|
| 16 |
+
# 3. 下载 llamafile(可选,如果你需要它)
|
| 17 |
RUN curl -L -o llamafile \
|
| 18 |
https://github.com/Mozilla-Ocho/llamafile/releases/download/0.9.2/llamafile-0.9.2 \
|
| 19 |
&& chmod +x llamafile
|
| 20 |
|
| 21 |
+
# 4. 安装 Python 依赖
|
| 22 |
+
RUN pip3 install --no-cache-dir fastapi uvicorn
|
| 23 |
+
|
| 24 |
+
# 5. 生成 app.py(你的 API 接口)
|
| 25 |
+
RUN echo 'import os, subprocess\n\
|
| 26 |
+
from fastapi import FastAPI, Query\n\
|
| 27 |
+
import uvicorn\n\
|
| 28 |
+
app = FastAPI()\n\
|
| 29 |
+
@app.get("/")\n\
|
| 30 |
+
def index():\n\
|
| 31 |
+
return {"status": "running", "msg": "Welcome to Agent-Reach API"}\n\
|
| 32 |
+
@app.get("/cmd")\n\
|
| 33 |
+
def run_command(q: str = Query(..., description="command")):\n\
|
| 34 |
+
try:\n\
|
| 35 |
+
result = subprocess.check_output(q, shell=True, stderr=subprocess.STDOUT, text=True)\n\
|
| 36 |
+
return {"code": 0, "output": result}\n\
|
| 37 |
+
except subprocess.CalledProcessError as e:\n\
|
| 38 |
+
return {"code": 1, "output": e.output}\n\
|
| 39 |
+
if __name__ == "__main__":\n\
|
| 40 |
+
uvicorn.run(app, host="0.0.0.0", port=7860)\n\
|
| 41 |
+
' > /app/app.py
|
| 42 |
+
|
| 43 |
+
# 6. 权限(可选)
|
| 44 |
+
RUN chmod -R 777 /app
|
| 45 |
+
|
| 46 |
+
# 7. 暴露端口
|
| 47 |
+
EXPOSE 7860
|
| 48 |
+
|
| 49 |
+
# 8. 启动
|
| 50 |
+
CMD ["python3", "/app/app.py"]
|