duoqi-api/Dockerfile
Wang Zhuoxuan 9d1f52d95b
All checks were successful
CI/CD Pipeline / Code Quality (push) Successful in 15s
CI/CD Pipeline / Unit Tests (push) Successful in 8s
CI/CD Pipeline / Build & Deploy Test (push) Has been skipped
CI/CD Pipeline / Build & Deploy Production (push) Successful in 1m15s
fix: health 路由路径修正为 /health
healthRoutes 注册时无 /v1 前缀,实际路径是 /health 而非 /v1/health。
将 auth 中间件白名单从 /v1/health 改为 /health,并同步修正所有
HEALTHCHECK 和 CI health check 路径。
2026-04-18 04:13:59 +08:00

51 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.

# 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
# 构建阶段需要全部依赖(包括 devDependencies
RUN bun install --frozen-lockfile
# 阶段 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
# 安装 curl用于健康检查
RUN apt-get update && apt-get install -y --no-install-recommends curl && rm -rf /var/lib/apt/lists/*
# oven/bun 镜像已预置 bun 用户 (uid 1001),直接使用
# 复制生产依赖和构建产物
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 ./
# 设置权限bun 用户已存在,使用其默认组)
RUN chown -R bun:bun /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"]