This commit is contained in:
ljy 2025-05-06 20:27:07 +08:00
commit d87452b934
4 changed files with 66 additions and 0 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
*.pyc

27
Dockerfile Normal file
View File

@ -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"]

31
README.md Normal file
View File

@ -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
```

7
requirements.txt Normal file
View File

@ -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