From d7832e5345cb4e7a68c1e85ab2d9b514baf90ae0 Mon Sep 17 00:00:00 2001 From: admin Date: Wed, 5 Nov 2025 01:44:13 +0000 Subject: [PATCH] =?UTF-8?q?=E5=88=9D=E5=A7=8B=E5=8C=96=E5=BA=94=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Dockerfile | 17 +++++++++++++++++ app.py | 38 ++++++++++++++++++++++++++++++++++++++ requirements.txt | 2 ++ 3 files changed, 57 insertions(+) create mode 100644 Dockerfile create mode 100644 app.py create mode 100644 requirements.txt diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..7a9dd2b --- /dev/null +++ b/Dockerfile @@ -0,0 +1,17 @@ +FROM registry.dev.maimaiag.com/library/python:3.13-slim + +WORKDIR /app + +# 复制依赖文件并安装 +COPY requirements.txt . +RUN pip install --no-cache-dir -r requirements.txt + +# 复制应用代码 +COPY src/ ./src/ +COPY run.py . + +# 暴露端口 +EXPOSE 8000 + +# 启动命令 +CMD ["python", "run.py"] \ No newline at end of file diff --git a/app.py b/app.py new file mode 100644 index 0000000..c2c224a --- /dev/null +++ b/app.py @@ -0,0 +1,38 @@ +from fastapi import FastAPI + +app = FastAPI(title="测试API", description="一个简单的FastAPI测试接口") + +@app.get("/") +async def root(): + return {"message": "Hello World", "status": "success"} + +@app.get("/health") +async def health_check(): + return {"status": "healthy", "service": "fastapi-test"} + +@app.get("/items/{item_id}") +async def read_item(item_id: int, q: str = None): + return { + "item_id": item_id, + "q": q, + "message": f"获取项目 {item_id}" + } + +@app.post("/items/") +async def create_item(name: str, description: str = None): + return { + "name": name, + "description": description, + "status": "created" + } + +import uvicorn + +if __name__ == "__main__": + uvicorn.run( + "app:app", + host="0.0.0.0", + port=8000, + reload=True, + log_level="info" + ) \ No newline at end of file diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..9d0a7e0 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,2 @@ +fastapi>=0.104.0 +uvicorn>=0.24.0 \ No newline at end of file