docker更新
Some checks failed
CI / lint (push) Has been cancelled
CI / typecheck (push) Has been cancelled
CI / build (macos-latest) (push) Has been cancelled
CI / build (ubuntu-latest) (push) Has been cancelled
CI / build (windows-latest) (push) Has been cancelled
CI / generate (macos-latest) (push) Has been cancelled
CI / generate (ubuntu-latest) (push) Has been cancelled
CI / generate (windows-latest) (push) Has been cancelled
Publish Any Commit / publish (push) Has been cancelled
Some checks failed
CI / lint (push) Has been cancelled
CI / typecheck (push) Has been cancelled
CI / build (macos-latest) (push) Has been cancelled
CI / build (ubuntu-latest) (push) Has been cancelled
CI / build (windows-latest) (push) Has been cancelled
CI / generate (macos-latest) (push) Has been cancelled
CI / generate (ubuntu-latest) (push) Has been cancelled
CI / generate (windows-latest) (push) Has been cancelled
Publish Any Commit / publish (push) Has been cancelled
This commit is contained in:
79
Dockerfile
79
Dockerfile
@@ -1,43 +1,38 @@
|
||||
########## 阶段 1:build ##########
|
||||
FROM node:20-alpine AS base
|
||||
# ------------- 依赖缓存阶段 -------------
|
||||
FROM node:22.16-alpine AS base
|
||||
|
||||
# 1. 如项目有原生包(better-sqlite3、sharp等)启用下面两行
|
||||
# RUN apk add --no-cache build-base python3 sqlite-dev
|
||||
|
||||
# 安装pnpm
|
||||
RUN npm install -g pnpm
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
# 2. 用 pnpm 锁文件
|
||||
COPY package.json pnpm-lock.yaml ./
|
||||
RUN pnpm install --frozen-lockfile
|
||||
|
||||
# 3. 源码 + 打补丁
|
||||
COPY . .
|
||||
RUN chmod +x patch-ui-pro.zsh && ./patch-ui-pro.zsh
|
||||
|
||||
# 4. 构建产物
|
||||
RUN pnpm build
|
||||
|
||||
########## 阶段 2:生产运行时 ##########
|
||||
FROM node:20-alpine AS production
|
||||
|
||||
# 安装pnpm
|
||||
RUN npm install -g pnpm
|
||||
|
||||
# 输出里有 .output,Nuxt3 的默认路径
|
||||
WORKDIR /app
|
||||
|
||||
# 1. 如果项目由 better-sqlite3,运行时还需 sqlite-libs
|
||||
# RUN apk add --no-cache sqlite-libs
|
||||
|
||||
# 2. 只拷贝生产运行时
|
||||
COPY package.json pnpm-lock.yaml ./
|
||||
RUN pnpm install --frozen-lockfile --prod
|
||||
|
||||
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"]
|
||||
# 国内镜像
|
||||
RUN npm config set registry https://registry.npmmirror.com
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
# 1️⃣ 先把锁文件拷进来,让这一层可以 cache
|
||||
COPY package.json pnpm-lock.yaml ./
|
||||
|
||||
# 2️⃣ 再执行安装
|
||||
RUN corepack enable && pnpm install --frozen-lockfile
|
||||
|
||||
# 3️⃣ 再拷剩余源码
|
||||
COPY . .
|
||||
RUN chmod +x patch-ui-pro.zsh && ./patch-ui-pro.zsh
|
||||
|
||||
# ------------- 构建阶段 -------------
|
||||
FROM base AS builder
|
||||
RUN pnpm build
|
||||
|
||||
# ------------- 运行阶段 -------------
|
||||
FROM node:22.16-alpine AS production
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
# 拷贝 lock + package.json 用于安装 prod 依赖
|
||||
COPY --from=builder /app/package.json /app/pnpm-lock.yaml ./
|
||||
RUN corepack enable && pnpm install --frozen-lockfile --prod
|
||||
|
||||
# 拷贝构建产物
|
||||
COPY --from=builder /app/.output ./.output
|
||||
|
||||
EXPOSE 3000
|
||||
ENV NODE_ENV=production HOST=0.0.0.0 PORT=3000
|
||||
CMD ["node", ".output/server/index.mjs"]
|
||||
|
Reference in New Issue
Block a user