Files
jenkins-pipeline/Dockerfile/web/lessie_web_Dockerfile
2026-02-03 19:37:58 +08:00

41 lines
1.5 KiB
Plaintext
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.

# 第一阶段:构建阶段 - 使用指定node20.15.0版本安装pnpm
FROM node:20.15.0-alpine AS builder
# 设定工作目录(容器内的项目目录)
WORKDIR /app
# 配置pnpm源可选加速国内安装
ENV PNPM_REGISTRY=https://registry.npmmirror.com/
# 全局安装pnpmnode20+推荐corepack管理pnpm更适配
RUN corepack enable && corepack prepare pnpm@latest --activate
# 复制包管理文件先复制lock文件利用docker层缓存避免代码变动重复装包
COPY package.json pnpm-lock.yaml* ./
# 安装项目依赖(--frozen-lockfile 锁定依赖版本,保证构建一致性)
RUN pnpm install --frozen-lockfile
# 复制整个项目代码到容器
COPY . .
# 构建参数指定构建环境默认im可在build时覆盖为test/im/prod等
ARG BUILD_ENV=im
# 执行对应环境的构建命令拼接为pnpm build:xxx
RUN pnpm build:${BUILD_ENV}
RUN mv /app/dist/main/index.html /app/dist/
# 第二阶段:运行阶段 - 使用官方Nginx稳定版仅保留dist目录减小镜像体积
FROM nginx:stable-alpine
# 暴露Nginx默认端口前端项目常规端口
EXPOSE 80
# 可选替换Nginx默认配置解决前端路由刷新404、开启gzip压缩优化静态资源
# COPY ./default.conf /etc/nginx/conf.d/default.conf
# 从构建阶段builder复制构建后的dist目录到Nginx的静态资源根目录
COPY --from=builder /app/dist /usr/share/nginx/html
# Nginx镜像默认会启动nginx无需额外CMD/ENTRYPOINT