File size: 1,102 Bytes
b0a1454
743953f
 
 
 
b0a1454
 
 
 
 
 
 
 
 
 
 
743953f
 
 
 
b0a1454
 
743953f
 
 
 
2d45ea0
 
b0a1454
743953f
 
 
b0a1454
 
 
 
 
16fa939
 
b0a1454
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
FROM python:3.12-slim

# 设置工作目录
WORKDIR /app

# 设置环境变量
ENV PYTHONUNBUFFERED=1 \
    PYTHONDONTWRITEBYTECODE=1 \
    PORT=7860 \
    FLASK_ENV=production

# 安装系统依赖(如需要)
RUN apt-get update && apt-get install -y --no-install-recommends \
    curl \
    && rm -rf /var/lib/apt/lists/*

# 复制requirements文件
COPY requirements.txt .

# 安装Python依赖
RUN pip install --no-cache-dir --upgrade pip && \
    pip install --no-cache-dir -r requirements.txt

# 复制应用文件
COPY . .

# 创建日志目录并设置权限
RUN mkdir -p logs && chmod 777 logs

# 暴露7860端口(Hugging Face Spaces要求)
EXPOSE 7860

# 健康检查
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
    CMD curl -f http://localhost:7860/api/health || exit 1

# 使用 Gunicorn 启动 Flask 应用(生产环境推荐)
# 使用配置文件以显示客户端真实 IP
CMD ["gunicorn", "-c", "gunicorn_config.py", "app:app"]

# 如果想使用 Flask 内置服务器(开发/测试用),使用下面这行:
# CMD ["python3.12", "app.py"]