Dockerfile.multiarch 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. # ============================================
  2. # Build stage for Frontend with multi-registry support
  3. # Node.js + Nginx 多镜像源支持
  4. # ============================================
  5. # 使用方式:
  6. # docker build -t web:latest -f shop-recycle-web/Dockerfile.multiarch . # 默认使用官方镜像
  7. # docker build --build-arg NODE_REGISTRY=registry.aliyuncs.com -t web:latest -f shop-recycle-web/Dockerfile.multiarch .
  8. ARG NODE_REGISTRY=node
  9. ARG NGINX_REGISTRY=nginx
  10. # ====== Build Stage ======
  11. FROM ${NODE_REGISTRY}:18-alpine AS builder
  12. ARG BUILD_NUMBER=local
  13. ARG GIT_COMMIT=unknown
  14. WORKDIR /build
  15. # Copy package files
  16. COPY shop-recycle-web/package*.json ./
  17. # Install dependencies (cached layer - only changes if package.json changes)
  18. RUN npm ci
  19. # Copy source code
  20. COPY shop-recycle-web/src ./src
  21. COPY shop-recycle-web/public ./public
  22. COPY shop-recycle-web/vite.config.js ./
  23. COPY shop-recycle-web/index.html ./
  24. # Build application
  25. RUN npm run build
  26. # ====== Runtime Stage ======
  27. FROM ${NGINX_REGISTRY}:1.25-alpine
  28. LABEL maintainer="shop-recycle"
  29. LABEL service="shop-recycle-web"
  30. LABEL build.number=${BUILD_NUMBER}
  31. LABEL git.commit=${GIT_COMMIT}
  32. ENV TZ=Asia/Shanghai
  33. # Remove default nginx config
  34. RUN rm -rf /etc/nginx/conf.d/default.conf
  35. # Copy nginx configuration
  36. COPY shop-recycle-web/nginx.conf /etc/nginx/conf.d/default.conf
  37. # Copy built static files from builder stage
  38. COPY --from=builder /build/dist /usr/share/nginx/html
  39. EXPOSE 80
  40. # Health check
  41. HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
  42. CMD wget --no-verbose --tries=1 --spider http://localhost/health || exit 0
  43. ENTRYPOINT ["nginx", "-g", "daemon off;"]