Files
jenkins-pipeline/Dockerfile/web/apex/aqex_web_Dockerfile

50 lines
1.3 KiB
Plaintext
Raw Normal View History

2025-12-17 17:32:04 +08:00
# ===============================
# 1) 依赖安装 + 构建阶段
# ===============================
2025-12-19 11:43:42 +08:00
FROM node:20.15.0-alpine AS build
2025-12-17 17:32:04 +08:00
WORKDIR /app
2025-12-19 11:43:42 +08:00
# 安装 pnpm 和 git前端使用 pnpm 管理依赖git生成版本信息
RUN npm install -g pnpm --registry=https://registry.npmmirror.com \
&& echo "https://mirrors.aliyun.com/alpine/v$(cat /etc/alpine-release | cut -d '.' -f 1-2)/main/" > /etc/apk/repositories \
&& echo "https://mirrors.aliyun.com/alpine/v$(cat /etc/alpine-release | cut -d '.' -f 1-2)/community/" >> /etc/apk/repositories \
&& apk add --no-cache git
2025-12-17 17:32:04 +08:00
# 只拷贝 package.json加快缓存命中
2025-12-19 11:43:42 +08:00
COPY package.json pnpm-lock.yaml* ./
2025-12-17 17:32:04 +08:00
# 预先安装依赖(利用缓存)
RUN pnpm install --registry=https://registry.npmmirror.com
# 拷贝全部代码
COPY . .
2025-12-19 11:43:42 +08:00
# package.json内定义了 build 脚本,执行构建
2025-12-17 17:32:04 +08:00
RUN pnpm build
RUN mv /app/dist/main/index.html /app/dist/index.html
# ===============================
# 2) 生产镜像阶段
# ===============================
2025-12-19 11:43:42 +08:00
FROM nginx:1.25-alpine AS runtime
ENV TZ=Asia/Shanghai
2025-12-17 17:32:04 +08:00
# 清理默认 nginx 静态内容
RUN rm -rf /usr/share/nginx/html/*
COPY nginx.conf /etc/nginx/nginx.conf
# 拷贝 build 结果
COPY --from=build /app/dist /usr/share/nginx/html/
# 权限
RUN chmod -R 755 /usr/share/nginx/html
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]