Files
estel_docs/Dockerfile
2025-07-29 00:04:29 +08:00

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

########## stage 1deps + build ##########
FROM node:20-alpine AS base
# 0. 先放系统包
RUN apk add --no-cache \
build-base \
python3 \
sqlite-dev # better-sqlite3 头文件、库
# 1. 装好 pnpm
RUN corepack enable && corepack prepare pnpm@latest --activate
WORKDIR /app
# 2. 复制锁文件,使用 layer cache
COPY package.json pnpm-lock.yaml ./
RUN --mount=type=cache,id=pnpm,target=/root/.local/share/pnpm/store \
pnpm install --frozen-lockfile --shamefully-hoist
# 3. 复制剩余源码并打补丁
COPY . .
RUN chmod +x patch-ui-pro.zsh && ./patch-ui-pro.zsh
# 4. build
RUN pnpm build
########## stage 2运行时 ##########
FROM node:20-alpine AS production
# 不需要任何 dev 编译依赖
RUN apk add --no-cache sqlite-libs # better-sqlite3 运行时库
RUN corepack enable && corepack prepare pnpm@latest --activate
WORKDIR /app
# 只装 prod 依赖
COPY package.json pnpm-lock.yaml ./
RUN --mount=type=cache,id=pnpm,target=/root/.local/share/pnpm/store \
pnpm install --prod --frozen-lockfile --shamefully-hoist
# 拷构建产物
COPY --from=base /app/.output /app/.output
EXPOSE 3000
ENV NODE_ENV=production HOST=0.0.0.0 PORT=3000
CMD ["node", ".output/server/index.mjs"]