Dockerfile 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. # ============================================
  2. # Build stage with incremental cache support
  3. # Node.js前端构建
  4. # ============================================
  5. FROM node:18-alpine AS builder
  6. ARG BUILD_NUMBER=local
  7. ARG GIT_COMMIT=unknown
  8. WORKDIR /build
  9. # Copy package files
  10. COPY shop-recycle-web/package.json .
  11. COPY shop-recycle-web/package-lock.json ./
  12. # Install dependencies (cached layer - only changes if package.json changes)
  13. RUN npm ci --only=production && \
  14. npm ci
  15. # Copy source code
  16. COPY shop-recycle-web/src ./src
  17. COPY shop-recycle-web/public ./public
  18. COPY shop-recycle-web/vite.config.js ./
  19. COPY shop-recycle-web/index.html ./
  20. # Build application
  21. RUN npm run build
  22. # ============================================
  23. # Runtime stage - ultra-minimal image
  24. # 使用Nginx Alpine基础镜像提供静态资源服务
  25. # ============================================
  26. FROM nginx:1.25-alpine
  27. LABEL maintainer="shop-recycle"
  28. LABEL service="shop-recycle-web"
  29. LABEL build.number=${BUILD_NUMBER}
  30. LABEL git.commit=${GIT_COMMIT}
  31. ENV TZ=Asia/Shanghai
  32. # Remove default nginx config
  33. RUN rm -rf /etc/nginx/conf.d/default.conf
  34. # Copy nginx configuration
  35. COPY shop-recycle-web/nginx.conf /etc/nginx/conf.d/default.conf
  36. # Copy built static files from builder stage
  37. COPY --from=builder /build/dist /usr/share/nginx/html
  38. EXPOSE 80
  39. # Health check
  40. HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
  41. CMD wget --no-verbose --tries=1 --spider http://localhost/health || exit 0
  42. ENTRYPOINT ["nginx", "-g", "daemon off;"]