Spaces:
Sleeping
Sleeping
| # ========== 第一阶段:构建 ========== | |
| 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"] |