File size: 1,324 Bytes
26ea821
 
 
 
 
 
 
fd78901
26ea821
 
d94c7bc
26ea821
fd78901
26ea821
fd78901
26ea821
 
 
 
fd78901
26ea821
 
 
 
 
fd78901
26ea821
 
 
fd78901
 
26ea821
fd78901
26ea821
 
 
 
fd78901
 
 
26ea821
 
 
 
 
 
 
 
fd78901
b2aacd9
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
44
45
46
47
48
49
50
# 构建阶段
FROM python:3.11-slim AS builder

WORKDIR /build

# 安装 git 和构建依赖
RUN apt-get update && apt-get install -y --no-install-recommends \
    git gcc python3-dev libpq-dev && rm -rf /var/lib/apt/lists/*

# 克隆仓库
RUN git clone https://github.com/Starry-Sky-World/grok2api.git .

# 安装依赖(包含 PgSQL 驱动)
RUN pip install --no-cache-dir --prefix=/install psycopg2-binary && \
    pip install --no-cache-dir --only-binary=:all: --prefix=/install -r requirements.txt

# 运行阶段
FROM python:3.11-slim

# HF 环境变量
ENV PYTHONDONTWRITEBYTECODE=1 \
    PYTHONUNBUFFERED=1 \
    HOME=/home/user \
    PORT=7860

# 创建 HF 专用的非 root 用户
RUN useradd -m -u 1000 user
WORKDIR /app

# 安装运行时必要的 libpq
RUN apt-get update && apt-get install -y --no-install-recommends libpq5 && rm -rf /var/lib/apt/lists/*

# 复制文件
COPY --from=builder /install /usr/local
COPY --from=builder /build /app/
COPY docker-entrypoint.sh /app/docker-entrypoint.sh

# 权限处理
RUN chmod +x /app/docker-entrypoint.sh && \
    mkdir -p /app/data /app/logs && \
    chown -R user:user /app

USER user

EXPOSE 7860

ENTRYPOINT ["/app/docker-entrypoint.sh"]

# 启动命令,注意端口 7860
CMD ["python", "-m", "uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860"]