Dockerfile 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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/vite.config.js ./
  18. COPY shop-recycle-web/index.html ./
  19. # Build application
  20. RUN npm run build
  21. # ============================================
  22. # Runtime stage - ultra-minimal image
  23. # 使用Nginx Alpine基础镜像提供静态资源服务
  24. # ============================================
  25. FROM nginx:1.25-alpine
  26. LABEL maintainer="shop-recycle"
  27. LABEL service="shop-recycle-web"
  28. LABEL build.number=${BUILD_NUMBER}
  29. LABEL git.commit=${GIT_COMMIT}
  30. ENV TZ=Asia/Shanghai
  31. # Remove default nginx config
  32. RUN rm -rf /etc/nginx/conf.d/default.conf
  33. # Copy nginx configuration
  34. COPY shop-recycle-web/nginx.conf /etc/nginx/conf.d/default.conf
  35. # Copy built static files from builder stage
  36. COPY --from=builder /build/dist /usr/share/nginx/html
  37. EXPOSE 80
  38. # Health check
  39. HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
  40. CMD wget --no-verbose --tries=1 --spider http://localhost/health || exit 0
  41. ENTRYPOINT ["nginx", "-g", "daemon off;"]