cicd-test/docker/Dockerfile-frontend

28 lines
643 B
Plaintext
Raw Normal View History

# 前端构建阶段
FROM registry.cn-beijing.aliyuncs.com/yinzy/node:20.11-alpine3.19 AS builder
WORKDIR /app
# 先复制依赖声明,利用缓存
COPY package*.json ./
# 使用国内镜像源并安装依赖
RUN npm config set registry https://registry.npmmirror.com \
&& npm ci --no-audit --no-fund
# 复制源码并构建
COPY vue-ui/ .
RUN npm run build
# 运行阶段,使用独立 nginx 镜像
FROM registry.cn-beijing.aliyuncs.com/yinzy/nginx:latest AS runtime
# 清理默认页面
WORKDIR /usr/share/nginx/html
RUN rm -rf ./*
# 拷贝构建产物
COPY --from=builder /app/dist .
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]