Your Name 86a7865808 feat: 添加 Docker 部署配置 + 安全加固 + 数据导出 API
- 新增 backend/Dockerfile + frontend/Dockerfile (多阶段构建)
- 新增 docker-compose.yml (postgres + redis + backend + frontend)
- 新增 .env.example 模板 (前后端)
- 新增 export API: 任务数据导出 + 审计日志导出 (CSV + 流式响应)
- 安全加固: CORS 从环境变量配置, 安全 headers 中间件
- 生产环境自动禁用 API 文档 (Swagger/Redoc)
- 添加 ENVIRONMENT, CORS_ORIGINS 配置项
- 前端启用 Next.js standalone 输出模式

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-09 17:43:28 +08:00

65 lines
1.6 KiB
Docker
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.

# ===========================
# 秒思智能审核平台 - Frontend Dockerfile
# 多阶段构建,基于 node:20-alpine
# ===========================
# ---------- Stage 1: 安装依赖 ----------
FROM node:20-alpine AS deps
WORKDIR /app
# 复制依赖描述文件
COPY package.json package-lock.json ./
# 安装生产依赖
RUN npm ci --ignore-scripts
# ---------- Stage 2: 构建应用 ----------
FROM node:20-alpine AS builder
WORKDIR /app
# 从 deps 阶段复制 node_modules
COPY --from=deps /app/node_modules ./node_modules
COPY . .
# 构建时环境变量NEXT_PUBLIC_ 前缀的变量在构建时注入)
ARG NEXT_PUBLIC_API_BASE_URL=http://localhost:8000
ARG NEXT_PUBLIC_USE_MOCK=false
ENV NEXT_PUBLIC_API_BASE_URL=$NEXT_PUBLIC_API_BASE_URL
ENV NEXT_PUBLIC_USE_MOCK=$NEXT_PUBLIC_USE_MOCK
# 启用 standalone 输出模式并构建
ENV NEXT_TELEMETRY_DISABLED=1
RUN npm run build
# ---------- Stage 3: 运行时镜像 ----------
FROM node:20-alpine AS runner
WORKDIR /app
ENV NODE_ENV=production
ENV NEXT_TELEMETRY_DISABLED=1
# 创建非 root 用户
RUN addgroup --system --gid 1001 nodejs \
&& adduser --system --uid 1001 nextjs
# 从 builder 阶段复制 standalone 产物
COPY --from=builder /app/public ./public
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
USER nextjs
EXPOSE 3000
ENV PORT=3000
ENV HOSTNAME="0.0.0.0"
HEALTHCHECK --interval=30s --timeout=5s --start-period=10s --retries=3 \
CMD wget --no-verbose --tries=1 --spider http://localhost:3000/ || exit 1
CMD ["node", "server.js"]