BingLogyBlog-Backend/Dockerfile.api
laobinghu 37742571ae feat: 完成项目初始化并重构部署流程
主要变更:
- 添加完整的项目结构和模块(admin、articles、comments、users、session、oauth2、email、moderation、analytics、jobs 等)
- 实现系统初始化 API(/init/status 和 /init/run)
- 重写部署流程:迁移到 package.json scripts,删除 Makefile
- 优化部署脚本:deploy.sh、healthcheck.sh、backup.sh、restore.sh、verify-env.sh
- 更新 README.md:简化文档,整合部署指南
- 优化 AGENTS.md:精简到约 150 行,包含完整的代码规范和命令速查
- 配置 Docker Compose 自动化部署(prisma migrate deploy + seed)
- 生成 OAuth2 RSA 密钥对支持
- 添加环境变量验证和数据库备份恢复功能
2026-03-28 16:53:25 +08:00

56 lines
1.2 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.

# Build stage
FROM oven/bun:1.1 AS builder
WORKDIR /app
# 复制依赖文件
COPY apps/api/package.json .
COPY pnpm-workspace.yaml .
COPY package.json .
# 安装 pnpm如果未预装
RUN npm install -g pnpm
# 安装依赖
RUN pnpm install --frozen-lockfile
# 复制源码
COPY apps/api/src ./src
COPY apps/api/prisma ./prisma
COPY apps/api/.env.example .env.example
# 生成 Prisma Client
RUN pnpm prisma generate
# 构建
RUN pnpm build
# Production stage
FROM oven/bun:1.1-alpine AS runner
WORKDIR /app
# 安装依赖(仅生产)
COPY apps/api/package.json .
COPY pnpm-workspace.yaml .
COPY package.json .
RUN npm install -g pnpm
RUN pnpm install --prod --frozen-lockfile
# 复制构建结果
COPY --from=builder /app/dist ./dist
COPY --from=builder /app/node_modules/.prisma ./node_modules/.prisma
COPY --from=builder /app/prisma ./prisma
COPY --from=builder /app/.env.example .env.example
# 暴露端口
EXPOSE 3001
# 健康检查(使用 Bun 运行 node 兼容代码)
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
CMD bun -e "require('http').get('http://localhost:3001/health', (r) => {if(r.statusCode!==200)throw new Error(r.statusCode)})"
# 启动命令(使用 Bun
CMD ["bun", "dist/main"]