gongxiangp2/yedir/Dockerfile
chenpei d0dc94e36d feat: 将弹幕功能替换为AI聊天助手
新功能:
- 创建AI聊天助手组件(AIChatWidget)
- 支持文字+图片多模态对话
- 集成Gemini AI API
- 支持图片编辑和内容生成
- 实时对话历史管理
- 优雅的UI设计,支持黑夜模式

技术实现:
- 后端API代理Gemini API(/api/ai-chat)
- 支持最多5张图片上传
- 流式响应处理
- 对话历史管理
- Base64图片处理

配置:
- 在.env中添加Gemini API配置
- GEMINI_API_KEY
- GEMINI_API_BASE_URL
- GEMINI_MODEL

替换原弹幕功能,提供更强大的AI助手体验!
2025-10-27 17:45:37 +08:00

127 lines
4.4 KiB
Docker
Executable File
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

FROM node:18-alpine AS builder
# 设置工作目录
WORKDIR /app
# 设置npm镜像源和网络配置
RUN npm config set registry https://registry.npmmirror.com/ && \
npm config set fetch-retries 5 && \
npm config set fetch-retry-mintimeout 20000 && \
npm config set fetch-retry-maxtimeout 120000
# 复制package.json和package-lock.json
COPY package*.json ./
# 安装所有依赖(包括开发依赖)- 添加重试机制
RUN npm ci --no-audit --no-fund --prefer-offline || \
(sleep 10 && npm ci --no-audit --no-fund --prefer-offline) || \
(sleep 20 && npm ci --no-audit --no-fund --prefer-offline)
# 确保AWS SDK安装正确
RUN npm install @aws-sdk/client-s3 --save --no-audit --no-fund || \
(sleep 10 && npm install @aws-sdk/client-s3 --save --no-audit --no-fund)
RUN npm install aws-sdk --save --no-audit --no-fund || \
(sleep 10 && npm install aws-sdk --save --no-audit --no-fund)
# 确保express-session安装正确
RUN npm install express-session --save --no-audit --no-fund || \
(sleep 10 && npm install express-session --save --no-audit --no-fund)
# 复制源代码
COPY . .
# 如果有构建步骤,可以在这里执行
# RUN npm run build
FROM node:18-alpine
# 创建非root用户
RUN addgroup -S appgroup && adduser -S appuser -G appgroup
# 设置工作目录
WORKDIR /app
# 设置npm镜像源和网络配置
RUN npm config set registry https://registry.npmmirror.com/ && \
npm config set fetch-retries 5 && \
npm config set fetch-retry-mintimeout 20000 && \
npm config set fetch-retry-maxtimeout 120000
# 复制package.json和package-lock.json
COPY package*.json ./
# 仅安装生产依赖 - 添加重试机制
RUN npm ci --only=production --no-audit --no-fund --prefer-offline || \
(sleep 10 && npm ci --only=production --no-audit --no-fund --prefer-offline) || \
(sleep 20 && npm ci --only=production --no-audit --no-fund --prefer-offline)
# 确保AWS SDK安装正确
RUN npm install @aws-sdk/client-s3 --production --no-audit --no-fund || \
(sleep 10 && npm install @aws-sdk/client-s3 --production --no-audit --no-fund)
RUN npm install aws-sdk --production --no-audit --no-fund || \
(sleep 10 && npm install aws-sdk --production --no-audit --no-fund)
# 确保express-session安装正确
RUN npm install express-session --production --no-audit --no-fund || \
(sleep 10 && npm install express-session --production --no-audit --no-fund)
# 确保node-fetch和axios安装正确(AI分析器需要)
RUN npm install node-fetch axios --production --no-audit --no-fund || \
(sleep 10 && npm install node-fetch axios --production --no-audit --no-fund)
# 复制启动脚本
COPY start.sh ./
RUN chmod +x start.sh
# 确保public/js/libs目录存在
RUN mkdir -p ./public/js/libs
# 从构建阶段复制应用代码
COPY --from=builder /app/server ./server
COPY --from=builder /app/public ./public
COPY --from=builder /app/init-db.js ./
COPY --from=builder /app/start-combined-servers.js ./
# 确保server/routes/api目录及其下的文件被正确复制
RUN mkdir -p ./server/routes/api
COPY --from=builder /app/server/routes/api/ai-analyzer.js ./server/routes/api/
# 复制云存储相关的路由文件
COPY --from=builder /app/routes/cloud-storage.js ./routes/
COPY --from=builder /app/routes/s3-config.js ./routes/
RUN mkdir -p ./routes
COPY --from=builder /app/routes ./routes
# 复制所有必要的SDK和其他目录
COPY --from=builder /app/openapi-sdk-nodejs-20220615 ./openapi-sdk-nodejs-20220615
COPY --from=builder /app/volc-sdk-nodejs ./volc-sdk-nodejs
COPY --from=builder /app/volc-sdk-nodejs-main ./volc-sdk-nodejs-main
COPY --from=builder /app/config ./config
COPY --from=builder /app/views ./views
COPY --from=builder /app/scripts ./scripts
# 创建必要的目录并设置权限
RUN mkdir -p logs uploads public/uploads temp && \
chown -R appuser:appgroup logs uploads public/uploads temp
# 创建.env文件并设置可写权限
RUN touch .env && chmod 777 .env && chown appuser:appgroup .env
# 设置环境变量 - 使用环境变量而不是硬编码端口
ENV PORT=3231
ENV NODE_ENV=production
ENV HOST=0.0.0.0
ENV INIT_DB=false
# 切换到非root用户
USER appuser
# 暴露端口 - 使用环境变量定义的端口
EXPOSE 3231
# 健康检查 - 使用环境变量定义的端口
HEALTHCHECK --interval=30s --timeout=10s --start-period=30s --retries=3 \
CMD wget -O- http://localhost:3231/api/health || exit 1
# 启动命令
CMD ["./start.sh"]