智慧水务管理系统 - 精河县供水工程综合管理平台

build.sh 2.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. #!/bin/bash
  2. # ============================================================
  3. # 智慧水务管理系统 - Docker 镜像构建脚本
  4. # 用法: ./docker/ci/build.sh [--push] [--registry registry.example.com]
  5. # ============================================================
  6. set -e
  7. REGISTRY="${REGISTRY:-}"
  8. PUSH=false
  9. TAG="latest"
  10. # 解析参数
  11. while [[ $# -gt 0 ]]; do
  12. case $1 in
  13. --push) PUSH=true; shift ;;
  14. --registry) REGISTRY="$2"; shift 2 ;;
  15. --tag) TAG="$2"; shift 2 ;;
  16. *) echo "Unknown option: $1"; exit 1 ;;
  17. esac
  18. done
  19. # 模块列表 (名称:端口)
  20. MODULES=(
  21. "wm-gateway:8080"
  22. "wm-base:8081"
  23. "wm-iot:8082"
  24. "wm-data-engine:8083"
  25. "wm-bpm:8084"
  26. "wm-production:8085"
  27. "wm-revenue:8086"
  28. "wm-patrol:8087"
  29. "wm-bi:8088"
  30. "wm-notify:8089"
  31. "wm-job:8090"
  32. )
  33. echo "========================================="
  34. echo " 智慧水务 Docker 镜像构建"
  35. echo " Tag: ${TAG}"
  36. echo " Registry: ${REGISTRY:-local}"
  37. echo "========================================="
  38. # 1. 构建前端
  39. echo ""
  40. echo "▶ Building frontend..."
  41. docker build -t ${REGISTRY:+$REGISTRY/}water/frontend:${TAG} -f Dockerfile.frontend .
  42. echo " ✅ frontend built"
  43. # 2. 构建巡检服务 (专用 Dockerfile)
  44. echo ""
  45. echo "▶ Building wm-patrol (multi-stage)..."
  46. docker build -t ${REGISTRY:+$REGISTRY/}water/wm-patrol:${TAG} -f Dockerfile.patrol .
  47. echo " ✅ wm-patrol built"
  48. # 3. 构建其他 Java 模块 (通用 Dockerfile)
  49. for entry in "${MODULES[@]}"; do
  50. IFS=':' read -r module port <<< "$entry"
  51. # wm-patrol already built above
  52. if [ "$module" = "wm-patrol" ]; then
  53. continue
  54. fi
  55. echo ""
  56. echo "▶ Building ${module} (port ${port})..."
  57. docker build \
  58. --build-arg MODULE=${module} \
  59. --build-arg PORT=${port} \
  60. -t ${REGISTRY:+$REGISTRY/}water/${module}:${TAG} \
  61. -f Dockerfile .
  62. echo " ✅ ${module} built"
  63. done
  64. echo ""
  65. echo "========================================="
  66. echo " ✅ All images built successfully!"
  67. echo "========================================="
  68. # 4. 推送 (可选)
  69. if [ "$PUSH" = true ]; then
  70. echo ""
  71. echo "▶ Pushing images..."
  72. docker push ${REGISTRY:+$REGISTRY/}water/frontend:${TAG}
  73. for entry in "${MODULES[@]}"; do
  74. IFS=':' read -r module port <<< "$entry"
  75. docker push ${REGISTRY:+$REGISTRY/}water/${module}:${TAG}
  76. done
  77. echo " ✅ All images pushed"
  78. fi