Files
perler-lab/perler-lab-server/Dockerfile
T
Sisyphus (主代理) 02762400fb chore: 项目基线提交 - 拼豆图纸生成器 V1.0 核心代码
- 前端: React+Vite 首页/AI专区, 算法库(MARD色板/量化/背景去除), API对接
- 后端: Express+SQLite, 兑换码/订单/支付/chibi生成, 风控+云端同步
- CI/CD: GitHub Actions + Docker + nginx 配置
- 文档: PRD/DESIGN/LAUNCH/ROADMAP/E2E/竞品对照等 15 份
- 工程: 任务看板(taskboard) + 健康巡检(agent-health) + Git流程(gitflow)
2026-08-13 21:40:27 +08:00

68 lines
2.5 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.
# syntax=docker/dockerfile:1
# =============================================================================
# PERLER LAB — 后端 Dockerfile(多阶段构建)
# 构建阶段:node:20-slim + tsc 编译 + 原生模块编译
# 运行阶段:node:20-slim + tsx 运行时(与 package.json start 脚本一致)
# =============================================================================
#
# 为什么用 tsx 而非 node dist/server.js:
# server.ts 的 isMain 检查通过 process.argv[1].endsWith("server.ts") 判断
# 是否为主入口。编译后 dist/server.js 不满足此条件,因此必须使用 tsx 直接
# 运行 TypeScript 源码。这与 package.json 中的 start 脚本一致。
#
# 为什么用 slim 而非 alpine:
# better-sqlite3 原生模块在 alpine (musl libc) 上可能缺少预编译二进制。
# slim 基于 Debian (glibc),预编译二进制可用,无需编译工具链。
# =============================================================================
# ── 第一阶段:编译 ──
FROM node:20-slim AS build
WORKDIR /app
# 安装 better-sqlite3 原生模块编译所需工具(若 prebuilt 下发失败则回退源码编译)
RUN apt-get update \
&& apt-get install -y --no-install-recommends python3 make g++ \
&& rm -rf /var/lib/apt/lists/*
# 复制依赖清单并安装(有 package-lock.json,使用 npm ci 保证可复现)
COPY package.json package-lock.json ./
RUN npm ci --no-audit --no-fund
# 复制源码并编译
COPY tsconfig.json ./
COPY src ./src
RUN npm run build
# ── 第二阶段:运行 ──
FROM node:20-slim AS runtime
WORKDIR /app
# 复制 node_modules(含 devDeps,因运行时需 tsx)
COPY --from=build /app/node_modules ./node_modules
# 复制编译产物与源码(tsx 运行时需要源码)
COPY --from=build /app/dist ./dist
COPY --from=build /app/src ./src
COPY --from=build /app/package.json ./package.json
# 创建 SQLite 数据目录(对外挂载 volume)
RUN mkdir -p /app/data && \
useradd --create-home --uid 1000 perler && \
chown -R perler:perler /app
# 切换到非 root 用户
USER perler
ENV NODE_ENV=production \
PORT=8788
EXPOSE 8788
# 健康检查——通过 /health 端点检测
HEALTHCHECK --interval=30s --timeout=5s --retries=3 --start-period=15s \
CMD node -e "fetch('http://localhost:8788/health').then(r => { if (!r.ok) process.exit(1); }).catch(() => process.exit(1))"
# 与 package.json 的 start 脚本一致:tsx src/server.ts
CMD ["npm", "run", "start"]