Files
frontend/Dockerfile

48 lines
1.2 KiB
Docker
Raw Permalink 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.

# ================================
# 第一步:构建阶段
# ================================
FROM cimg/node:22.15.1 AS builder
# 设置国内 npm 镜像加速
RUN npm config set registry https://registry.npmmirror.com/
# 切换为 root 用户安装 pnpm
USER root
# 如果你使用 pnpm则安装 pnpm
RUN corepack enable && corepack prepare pnpm@latest --activate
# 切回默认用户 circlecicimg 镜像默认非 root 用户)
USER circleci
# WORKDIR /app
# 先复制依赖清单,利用 Docker 缓存
COPY package.json ./
# 如果你没有 pnpm-lock.yaml使用 npm 的 package-lock.json
COPY package-lock.json ./
# COPY package-lock.json ./ # 如果你用的是 npm
# 安装依赖
RUN pnpm install
# 再复制源码
# COPY . .
# 进行构建(适用于 Astro、Next.js、Vite 等项目)
RUN pnpm build
# ================================
# 第二步:运行阶段(只保留 dist
# ================================
FROM cimg/node:22.15.1
# 设置国内 npm 镜像(可选)
RUN npm config set registry https://registry.npmmirror.com/
# WORKDIR /app
# 只复制构建产物和依赖
# COPY --from=builder /app .
# 启动 SSR 项目Astro SSR 情况)
# CMD ["node", "dist/server/entry.mjs"]