Completed: - Add 6 core database documents (docs/01-平台基础层/07-数据库/) Architecture overview, migration history, environment comparison, tech debt tracking, seed data management, PostgreSQL extensions - Restructure deployment docs: archive 20 legacy files to _archive-2025/ - Create unified daily operations manual (01-日常更新操作手册.md) - Add pending deployment change tracker (03-待部署变更清单.md) - Update database development standard to v3.0 (three iron rules) - Fix Prisma schema type drift: align @db.* annotations with actual DB IIT: UUID/Timestamptz(6), SSA: Timestamp(6)/VarChar(20/50/100) - Add migration: 20260227_align_schema_with_db_types (idempotent ALTER) - Add Cursor Rule for auto-reminding deployment change documentation - Update system status guide v6.4 with deployment and DB doc references - Add architecture consultation docs (Prisma guide, SAE deployment guide) Technical details: - Manual migration due to shadow DB limitation (TD-001 in tech debt) - Deployment docs reduced from 20+ scattered files to 3 core documents - Cursor Rule triggers on schema.prisma, package.json, Dockerfile changes Made-with: Cursor
83 lines
2.6 KiB
Docker
83 lines
2.6 KiB
Docker
# ==================== 阶段 1: 依赖安装阶段 ====================
|
||
FROM node:alpine AS builder
|
||
|
||
# 替换Alpine镜像源为阿里云镜像(解决网络问题)
|
||
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories
|
||
|
||
# 安装 Prisma 运行时依赖
|
||
RUN apk add --no-cache openssl
|
||
|
||
WORKDIR /app
|
||
|
||
# 1. 复制依赖文件
|
||
COPY package*.json ./
|
||
|
||
# 2. 复制 Prisma Schema(用于生成Prisma Client)
|
||
COPY prisma ./prisma/
|
||
|
||
# 3. 只安装生产依赖(大幅减少网络传输和安装时间)
|
||
RUN npm config set registry https://registry.npmmirror.com && \
|
||
npm config set fetch-retry-mintimeout 20000 && \
|
||
npm config set fetch-retry-maxtimeout 120000 && \
|
||
npm config set fetch-retries 5 && \
|
||
npm ci --production --prefer-offline --no-audit
|
||
|
||
# 4. 生成 Prisma Client(生产环境需要)
|
||
RUN npx prisma generate
|
||
|
||
# 5. 复制本地已编译好的 dist 文件夹(跳过TypeScript编译)
|
||
COPY dist ./dist
|
||
|
||
# 5a. tsc 不会复制 .json 文件,手动补充 src 中的 JSON 配置到 dist
|
||
COPY src/modules/ssa/config/*.json ./dist/modules/ssa/config/
|
||
COPY src/modules/asl/fulltext-screening/prompts/*.json ./dist/modules/asl/fulltext-screening/prompts/
|
||
|
||
# 6. 复制配置文件(agents.yaml等)
|
||
COPY config ./config
|
||
|
||
# ==================== 阶段 2: 运行阶段 ====================
|
||
FROM node:alpine
|
||
|
||
# 替换Alpine镜像源为阿里云镜像(解决网络问题)
|
||
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories
|
||
|
||
# 安装运行时依赖 + 时区数据
|
||
RUN apk add --no-cache \
|
||
openssl \
|
||
curl \
|
||
ca-certificates \
|
||
tzdata
|
||
|
||
# ⚠️ 统一时区:Asia/Shanghai
|
||
ENV TZ=Asia/Shanghai
|
||
|
||
# 创建非 root 用户(安全最佳实践)
|
||
RUN addgroup -g 1001 -S nodejs && \
|
||
adduser -S nodejs -u 1001
|
||
|
||
WORKDIR /app
|
||
|
||
# 从构建阶段复制产物
|
||
COPY --from=builder --chown=nodejs:nodejs /app/node_modules ./node_modules
|
||
COPY --from=builder --chown=nodejs:nodejs /app/dist ./dist
|
||
COPY --from=builder --chown=nodejs:nodejs /app/package*.json ./
|
||
COPY --from=builder --chown=nodejs:nodejs /app/prisma ./prisma
|
||
COPY --from=builder --chown=nodejs:nodejs /app/config ./config
|
||
|
||
# 创建上传目录(用于临时文件)
|
||
RUN mkdir -p /app/uploads && chown -R nodejs:nodejs /app/uploads
|
||
|
||
# 切换到非 root 用户
|
||
USER nodejs
|
||
|
||
# 健康检查
|
||
HEALTHCHECK --interval=30s --timeout=10s --start-period=60s --retries=3 \
|
||
CMD node -e "require('http').get('http://localhost:3001/health', (res) => { process.exit(res.statusCode === 200 ? 0 : 1); })"
|
||
|
||
# 暴露端口
|
||
EXPOSE 3001
|
||
|
||
# 🔥 启动命令(仅启动应用,不执行数据库迁移)
|
||
CMD ["node", "dist/index.js"]
|
||
|