#!/bin/bash # ============================================================ # 智慧水务管理系统 - Docker 镜像构建脚本 # 用法: ./docker/ci/build.sh [--push] [--registry registry.example.com] # ============================================================ set -e REGISTRY="${REGISTRY:-}" PUSH=false TAG="latest" # 解析参数 while [[ $# -gt 0 ]]; do case $1 in --push) PUSH=true; shift ;; --registry) REGISTRY="$2"; shift 2 ;; --tag) TAG="$2"; shift 2 ;; *) echo "Unknown option: $1"; exit 1 ;; esac done # 模块列表 (名称:端口) MODULES=( "wm-gateway:8080" "wm-base:8081" "wm-iot:8082" "wm-data-engine:8083" "wm-bpm:8084" "wm-production:8085" "wm-revenue:8086" "wm-patrol:8087" "wm-bi:8088" "wm-notify:8089" "wm-job:8090" ) echo "=========================================" echo " 智慧水务 Docker 镜像构建" echo " Tag: ${TAG}" echo " Registry: ${REGISTRY:-local}" echo "=========================================" # 1. 构建前端 echo "" echo "▶ Building frontend..." docker build -t ${REGISTRY:+$REGISTRY/}water/frontend:${TAG} -f Dockerfile.frontend . echo " ✅ frontend built" # 2. 构建巡检服务 (专用 Dockerfile) echo "" echo "▶ Building wm-patrol (multi-stage)..." docker build -t ${REGISTRY:+$REGISTRY/}water/wm-patrol:${TAG} -f Dockerfile.patrol . echo " ✅ wm-patrol built" # 3. 构建其他 Java 模块 (通用 Dockerfile) for entry in "${MODULES[@]}"; do IFS=':' read -r module port <<< "$entry" # wm-patrol already built above if [ "$module" = "wm-patrol" ]; then continue fi echo "" echo "▶ Building ${module} (port ${port})..." docker build \ --build-arg MODULE=${module} \ --build-arg PORT=${port} \ -t ${REGISTRY:+$REGISTRY/}water/${module}:${TAG} \ -f Dockerfile . echo " ✅ ${module} built" done echo "" echo "=========================================" echo " ✅ All images built successfully!" echo "=========================================" # 4. 推送 (可选) if [ "$PUSH" = true ]; then echo "" echo "▶ Pushing images..." docker push ${REGISTRY:+$REGISTRY/}water/frontend:${TAG} for entry in "${MODULES[@]}"; do IFS=':' read -r module port <<< "$entry" docker push ${REGISTRY:+$REGISTRY/}water/${module}:${TAG} done echo " ✅ All images pushed" fi