| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- # ============================================
- # Build stage with incremental cache support
- # Node.js前端构建
- # ============================================
- FROM node:18-alpine AS builder
- ARG BUILD_NUMBER=local
- ARG GIT_COMMIT=unknown
- WORKDIR /build
- # Copy package files
- COPY shop-recycle-web/package.json .
- COPY shop-recycle-web/package-lock.json ./
- # Install dependencies (cached layer - only changes if package.json changes)
- RUN npm ci --only=production && \
- npm ci
- # Copy source code
- COPY shop-recycle-web/src ./src
- COPY shop-recycle-web/vite.config.js ./
- COPY shop-recycle-web/index.html ./
- # Build application
- RUN npm run build
- # ============================================
- # Runtime stage - ultra-minimal image
- # 使用Nginx Alpine基础镜像提供静态资源服务
- # ============================================
- FROM nginx:1.25-alpine
- LABEL maintainer="shop-recycle"
- LABEL service="shop-recycle-web"
- LABEL build.number=${BUILD_NUMBER}
- LABEL git.commit=${GIT_COMMIT}
- ENV TZ=Asia/Shanghai
- # Remove default nginx config
- RUN rm -rf /etc/nginx/conf.d/default.conf
- # Copy nginx configuration
- COPY shop-recycle-web/nginx.conf /etc/nginx/conf.d/default.conf
- # Copy built static files from builder stage
- COPY --from=builder /build/dist /usr/share/nginx/html
- EXPOSE 80
- # Health check
- HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
- CMD wget --no-verbose --tries=1 --spider http://localhost/health || exit 0
- ENTRYPOINT ["nginx", "-g", "daemon off;"]
|