# Stage 1: Build FROM swr.cn-north-4.myhuaweicloud.com/ddn-k8s/docker.io/node:20-alpine AS builder WORKDIR /app # Configure npm to use Aliyun mirror for faster installation RUN npm config set registry https://registry.npmmirror.com # Copy package files COPY package.json yarn.lock* package-lock.json* ./ # Clean install dependencies # 1. Remove lock file to solve cross-platform rollup issues # 2. Install with legacy-peer-deps for React 19 compatibility RUN rm -rf package-lock.json node_modules && \ npm install --legacy-peer-deps # Copy source code COPY . . # Build the application RUN npm run build # Stage 2: Production with Nginx FROM swr.cn-north-4.myhuaweicloud.com/ddn-k8s/docker.io/nginx:alpine # Remove default nginx config RUN rm /etc/nginx/conf.d/default.conf # Copy custom nginx config COPY nginx.conf /etc/nginx/conf.d/default.conf # Copy built files from builder COPY --from=builder /app/dist /usr/share/nginx/html # Expose port EXPOSE 80 # Health check HEALTHCHECK --interval=30s --timeout=10s --retries=3 \ CMD wget --quiet --tries=1 --spider http://localhost/ || exit 1 # Start nginx CMD ["nginx", "-g", "daemon off;"]