commit d87452b9343ec7e14928aca928108a028be870aa Author: ljy <473960544@qq.com> Date: Tue May 6 20:27:07 2025 +0800 初版 diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..7e99e36 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +*.pyc \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..d60d264 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,27 @@ +# 使用官方Python轻量级镜像 +FROM python:3.10-slim + +# 设置工作目录 +WORKDIR /app + +# 配置国内镜像源(加速安装) +RUN pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple + +# 先复制依赖文件(利用Docker缓存优化) +COPY requirements.txt . + +# 安装依赖(禁用缓存减少体积) +RUN pip install --no-cache-dir -r requirements.txt + +# 复制整个项目代码 +COPY . . + +# 暴露Flask默认端口 +EXPOSE 5000 + +# 设置环境变量 +ENV FLASK_APP=app/main.py +ENV FLASK_ENV=production + +# 启动应用 +CMD ["flask", "run", "--host=0.0.0.0"] \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..f33e875 --- /dev/null +++ b/README.md @@ -0,0 +1,31 @@ +# 需求 + + + + +打开文档:http://127.0.0.1:5000/apidocs/ + + + +## 项目结构规范 + +``` +algorithm-service/ +├── app/ +│ ├── __init__.py # 可选 +│ ├── main.py # 主应用 +│ └── algorithms.py # 算法实现 +├── requirements.txt # Python依赖 +├── Dockerfile # Docker构建文件 +└── README.md # 说明文档 +``` + +## 镜像构建和运行 + +``` +# 构建镜像(注意最后的点表示当前目录) +docker build -t algorithm-service . + +# 后台运行(添加-d参数) +docker run -p 5121:5000 --name python-algo-service algorithm-service +``` \ No newline at end of file diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..d88c7b3 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,7 @@ +flask==3.0.3 +numpy==2.2.4 +flasgger==0.9.7.1 +werkzeug==3.0.3 +jinja2==3.1.4 +itsdangerous==2.2.0 +click==8.1.7 \ No newline at end of file