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

44 lines
1.6 KiB
Plaintext
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.

# ===============================
# 1) 依赖安装 + 构建阶段
# ===============================
FROM node:20.15.0-alpine AS builder
# 设定工作目录,后续所有指令基于此,避免路径混乱
WORKDIR /app
# 配置npm国内源仅1次配置后续所有npm命令自动复用删除冗余的registry传参
ENV NPM_REGISTRY=https://registry.npmmirror.com/
RUN npm config set registry ${NPM_REGISTRY}
# 先拷贝package.json核心利用Docker层缓存代码不变则不重装依赖
COPY package.json ./
# 安装依赖无需重复写registry已全局配置加快构建
RUN npm install
# 拷贝全部项目代码(放在装依赖后,最大化缓存收益)
COPY . .
# 构建参数默认sitbuild时可通过--build-arg覆盖如prod/test
ARG BUILD_ENV=sit
# 注入环境变量,确保构建脚本能读取到(部分框架需要环境变量透传)
ENV BUILD_ENV=${BUILD_ENV}
# 执行环境构建命令兼容package.json的build:sit/build:test/build:prod
RUN npm run build:${BUILD_ENV}
# ===============================
# 2) 生产镜像阶段轻量Nginx仅保留构建产物
# ===============================
FROM nginx:stable-alpine AS runtime
# 暴露80端口Docker声明方便容器映射不影响实际运行
EXPOSE 80
# 复制自定义Nginx配置解决路由404+禁用所有缓存,核心修正)
COPY ./default.conf /etc/nginx/conf.d/default.conf
# 从构建阶段拷贝最终构建产物到Nginx静态资源根目录
COPY --from=builder /app/dist /usr/share/nginx/html
# Nginx官方镜像默认自动启动nginx无需额外CMD/ENTRYPOINT