File size: 2,070 Bytes
57727be
8a59281
 
cd640eb
 
b4ad2f5
cd640eb
 
 
 
 
8a59281
57727be
8a59281
 
57727be
8a59281
 
dbb3932
 
 
 
 
 
 
54e065a
62bdfa1
57727be
8a59281
57727be
62bdfa1
20ebd03
 
eadc41e
b78b330
93381bd
07bbcac
afab6af
54e065a
62bdfa1
57727be
62bdfa1
 
57727be
8521e87
ee9f0e1
c8c7936
57727be
 
 
 
62bdfa1
 
 
 
984724f
 
62bdfa1
 
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
51
52
53
54
55
56
57
58
59
# ========== 第一阶段:构建 ==========
FROM node:20-slim AS builder
WORKDIR /app
# 安装运行时依赖:cron, supervisor, python3, pip, requests
RUN apt-get update && apt-get install -y \
    git \
    cron \
    supervisor \
    python3 \
    python3-pip \
    && rm -rf /var/lib/apt/lists/*
RUN git clone https://github.com/tashfeenahmed/freellmapi.git .
RUN npm config set registry https://registry.npmmirror.com && npm install
RUN npm run build

# ========== 第二阶段:运行 ==========
FROM node:20-slim AS runner
WORKDIR /app
# 安装运行时依赖:cron, supervisor, python3, pip
RUN apt-get update && apt-get install -y \
    cron \
    supervisor \
    python3 \
    python3-pip \
    && rm -rf /var/lib/apt/lists/*

# 安装 huggingface-hub
RUN pip3 install huggingface-hub --break-system-packages || pip3 install huggingface-hub

COPY --from=builder /app ./
RUN mkdir -p /data /app/scripts /var/log/backup
RUN cp -r client/dist/* server/dist/public/ 2>/dev/null || cp -r client/dist/* server/public/ 2>/dev/null || true

EXPOSE 7860
ENV PORT=7860
ENV NODE_ENV=production
# 指向持久化目录(虽然免费无持久化,但统一用/data)
ENV DATABASE_URL="/app/server/data/freeapi.db"

# 复制备份和恢复脚本
COPY scripts/backup_to_dataset.py /app/scripts/backup_to_dataset.py
COPY scripts/restore_from_dataset.py /app/scripts/restore_from_dataset.py
RUN chmod +x /app/scripts/*.py

# 配置 cron 任务
RUN echo "*/10 * * * * root /usr/local/bin/python3 /app/scripts/backup_to_dataset.py >> /var/log/backup/cron.log 2>&1" > /etc/cron.d/backup-job
RUN echo "0 * * * * root /usr/bin/python3 /app/scripts/sync_bailian_models.py >> /var/log/backup/sync_models.log 2>&1" >> /etc/cron.d/backup-job

# 复制 supervisord 配置
COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf

# 复制启动脚本
COPY start.sh /start.sh
RUN chmod +x /start.sh

COPY scripts/sync_bailian_models.py /app/scripts/sync_bailian_models.py
RUN chmod +x /app/scripts/sync_bailian_models.py
# 使用启动脚本作为入口点
CMD ["/start.sh"]