duoqi-api/Dockerfile
Wang Zhuoxuan 2d8b07845f
Some checks failed
CI/CD Pipeline / Code Quality (push) Successful in 16s
CI/CD Pipeline / Unit Tests (push) Successful in 10s
CI/CD Pipeline / Build Test Image (push) Has been skipped
CI/CD Pipeline / Deploy to Test (push) Has been skipped
CI/CD Pipeline / Build Production Image (push) Failing after 9s
CI/CD Pipeline / Deploy to Production (push) Has been skipped
fix: 更新 Dockerfile Bun 版本 1.1 → 1.3 以匹配本地版本
本地使用 Bun 1.3.11 生成的 lockfile 与 Bun 1.1.45 不兼容
2026-04-17 16:11:03 +08:00

49 lines
1.0 KiB
Docker

# Duoqi API - Multi-stage Dockerfile
# 阶段 1: 构建依赖
FROM oven/bun:1.3 AS base
WORKDIR /app
# 复制依赖文件
COPY package.json bun.lock ./
# 阶段 2: 安装依赖
FROM base AS install
RUN bun install --frozen-lockfile --production
# 阶段 3: 构建应用
FROM base AS build
COPY --from=install /app/node_modules ./node_modules
COPY . .
# 类型检查和编译
RUN bun run typecheck
RUN bun run build
# 阶段 4: 生产镜像
FROM oven/bun:1.3 AS release
WORKDIR /app
# 创建非 root 用户
RUN addgroup --system --gid 1001 nodejs
RUN adduser --system --uid 1001 bun
# 复制生产依赖和构建产物
COPY --from=install /app/node_modules ./node_modules
COPY --from=build /app/dist ./dist
COPY --from=build /app/db ./db
COPY --from=build /app/package.json ./
# 设置权限
RUN chown -R bun:nodejs /app
USER bun
# 暴露端口
EXPOSE 3000
# 健康检查
HEALTHCHECK --interval=30s --timeout=10s --start-period=40s --retries=3 \
CMD curl -f http://localhost:3000/health || exit 1
# 启动应用
CMD ["node", "dist/index.js"]