refactor: metric e2e docker-compose中移除构建参数;metric e2e启动服务脚本中移除构建逻辑,迁移至build模块;
refs #29
This commit is contained in:
parent
a8bbf2d6e9
commit
299765ed40
@ -5,13 +5,6 @@ networks:
|
|||||||
|
|
||||||
services:
|
services:
|
||||||
ftp:
|
ftp:
|
||||||
build:
|
|
||||||
context: ../ftp/build
|
|
||||||
dockerfile: Dockerfile
|
|
||||||
args:
|
|
||||||
ARGUS_BUILD_UID: ${ARGUS_BUILD_UID:-2133}
|
|
||||||
ARGUS_BUILD_GID: ${ARGUS_BUILD_GID:-2015}
|
|
||||||
USE_INTRANET: ${USE_INTRANET:-false}
|
|
||||||
image: argus-metric-ftp:latest
|
image: argus-metric-ftp:latest
|
||||||
container_name: argus-ftp
|
container_name: argus-ftp
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
@ -41,13 +34,6 @@ services:
|
|||||||
max-file: "3"
|
max-file: "3"
|
||||||
|
|
||||||
prometheus:
|
prometheus:
|
||||||
build:
|
|
||||||
context: ../prometheus/build
|
|
||||||
dockerfile: Dockerfile
|
|
||||||
args:
|
|
||||||
ARGUS_BUILD_UID: ${ARGUS_BUILD_UID:-2133}
|
|
||||||
ARGUS_BUILD_GID: ${ARGUS_BUILD_GID:-2015}
|
|
||||||
USE_INTRANET: ${USE_INTRANET:-false}
|
|
||||||
image: argus-metric-prometheus:latest
|
image: argus-metric-prometheus:latest
|
||||||
container_name: argus-prometheus
|
container_name: argus-prometheus
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
@ -73,12 +59,6 @@ services:
|
|||||||
max-file: "3"
|
max-file: "3"
|
||||||
|
|
||||||
grafana:
|
grafana:
|
||||||
build:
|
|
||||||
context: ../grafana/build
|
|
||||||
dockerfile: Dockerfile
|
|
||||||
args:
|
|
||||||
ARGUS_BUILD_UID: ${ARGUS_BUILD_UID:-2133}
|
|
||||||
ARGUS_BUILD_GID: ${ARGUS_BUILD_GID:-2015}
|
|
||||||
image: argus-metric-grafana:latest
|
image: argus-metric-grafana:latest
|
||||||
container_name: argus-grafana
|
container_name: argus-grafana
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
@ -109,9 +89,6 @@ services:
|
|||||||
max-file: "3"
|
max-file: "3"
|
||||||
|
|
||||||
test-node:
|
test-node:
|
||||||
build:
|
|
||||||
context: ./client-test-node/build
|
|
||||||
dockerfile: Dockerfile
|
|
||||||
image: argus-metric-test-node:latest
|
image: argus-metric-test-node:latest
|
||||||
container_name: argus-metric-test-node
|
container_name: argus-metric-test-node
|
||||||
hostname: test-metric-node-001
|
hostname: test-metric-node-001
|
||||||
@ -143,9 +120,6 @@ services:
|
|||||||
max-file: "3"
|
max-file: "3"
|
||||||
|
|
||||||
test-gpu-node:
|
test-gpu-node:
|
||||||
build:
|
|
||||||
context: ./client-test-gpu-node/build
|
|
||||||
dockerfile: Dockerfile
|
|
||||||
image: argus-metric-test-gpu-node:latest
|
image: argus-metric-test-gpu-node:latest
|
||||||
container_name: argus-metric-test-gpu-node
|
container_name: argus-metric-test-gpu-node
|
||||||
hostname: test-metric-gpu-node-001
|
hostname: test-metric-gpu-node-001
|
||||||
|
|||||||
@ -3,15 +3,8 @@ set -e
|
|||||||
|
|
||||||
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
|
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
|
||||||
|
|
||||||
# 解析参数
|
|
||||||
REBUILD_FLAG=""
|
|
||||||
if [[ "$1" == "--rebuild" || "$1" == "-r" ]]; then
|
|
||||||
REBUILD_FLAG="--rebuild"
|
|
||||||
echo "[01] 启用强制重新构建模式"
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo "[01] 启动所有服务..."
|
echo "[01] 启动所有服务..."
|
||||||
bash "$SCRIPT_DIR/common/start-all.sh" $REBUILD_FLAG
|
bash "$SCRIPT_DIR/common/start-all.sh"
|
||||||
|
|
||||||
echo "[01] 等待服务就绪..."
|
echo "[01] 等待服务就绪..."
|
||||||
sleep 5
|
sleep 5
|
||||||
|
|||||||
@ -1,7 +1,8 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
# 一键启动脚本
|
# 一键启动脚本
|
||||||
# 用于初始化目录、构建镜像并启动所有服务
|
# 用于初始化目录并启动所有服务
|
||||||
|
# 镜像构建已移至 build/build_images.sh
|
||||||
|
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
@ -9,12 +10,6 @@ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|||||||
TEST_DIR="$(cd "$SCRIPT_DIR/../.." && pwd)"
|
TEST_DIR="$(cd "$SCRIPT_DIR/../.." && pwd)"
|
||||||
cd "$TEST_DIR"
|
cd "$TEST_DIR"
|
||||||
|
|
||||||
# 解析参数
|
|
||||||
FORCE_REBUILD=false
|
|
||||||
if [[ "$1" == "--rebuild" ]]; then
|
|
||||||
FORCE_REBUILD=true
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo "=========================================="
|
echo "=========================================="
|
||||||
echo " Argus Metrics 一键启动脚本"
|
echo " Argus Metrics 一键启动脚本"
|
||||||
echo "=========================================="
|
echo "=========================================="
|
||||||
@ -37,26 +32,6 @@ echo "使用: docker compose"
|
|||||||
echo "Compose 文件: $TEST_DIR/docker-compose.yml"
|
echo "Compose 文件: $TEST_DIR/docker-compose.yml"
|
||||||
echo ""
|
echo ""
|
||||||
|
|
||||||
# 检查必要的构建目录
|
|
||||||
echo "检查构建目录..."
|
|
||||||
BUILD_DIRS=(
|
|
||||||
"../ftp/build"
|
|
||||||
"../prometheus/build"
|
|
||||||
"../grafana/build"
|
|
||||||
"client-test-node/build"
|
|
||||||
"client-test-gpu-node/build"
|
|
||||||
)
|
|
||||||
|
|
||||||
for dir in "${BUILD_DIRS[@]}"; do
|
|
||||||
if [ ! -d "$dir" ]; then
|
|
||||||
echo "错误: 构建目录不存在: $dir"
|
|
||||||
echo "完整路径: $(cd "$(dirname "$dir")" 2>/dev/null && pwd)/$(basename "$dir")"
|
|
||||||
exit 1
|
|
||||||
else
|
|
||||||
echo " ✓ 找到: $dir"
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
echo ""
|
|
||||||
|
|
||||||
# 检查并创建 .env 文件
|
# 检查并创建 .env 文件
|
||||||
if [ ! -f .env ]; then
|
if [ ! -f .env ]; then
|
||||||
@ -84,111 +59,29 @@ echo "1. 初始化目录结构..."
|
|||||||
bash "$SCRIPT_DIR/init-directories.sh"
|
bash "$SCRIPT_DIR/init-directories.sh"
|
||||||
|
|
||||||
echo ""
|
echo ""
|
||||||
echo "2. 准备 Docker 镜像..."
|
echo "2. 检查 Docker 镜像..."
|
||||||
|
|
||||||
# 检查镜像是否存在
|
# 检查必要的镜像是否存在
|
||||||
IMAGE_CACHE_DIR="$TEST_DIR/images-cache"
|
|
||||||
IMAGES=("argus-metric-ftp:latest" "argus-metric-prometheus:latest" "argus-metric-grafana:latest" "argus-metric-test-node:latest" "argus-metric-test-gpu-node:latest")
|
IMAGES=("argus-metric-ftp:latest" "argus-metric-prometheus:latest" "argus-metric-grafana:latest" "argus-metric-test-node:latest" "argus-metric-test-gpu-node:latest")
|
||||||
all_images_exist=true
|
missing_images=()
|
||||||
|
|
||||||
for image in "${IMAGES[@]}"; do
|
for image in "${IMAGES[@]}"; do
|
||||||
if ! docker images --format "{{.Repository}}:{{.Tag}}" | grep -q "^${image}$"; then
|
if ! docker images --format "{{.Repository}}:{{.Tag}}" | grep -q "^${image}$"; then
|
||||||
all_images_exist=false
|
missing_images+=("$image")
|
||||||
break
|
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
if $FORCE_REBUILD; then
|
if [ ${#missing_images[@]} -gt 0 ]; then
|
||||||
echo "强制重新构建镜像(--rebuild 模式)..."
|
echo "以下镜像缺失,请先运行 build/build_images.sh 构建镜像:"
|
||||||
cd "$TEST_DIR"
|
for image in "${missing_images[@]}"; do
|
||||||
docker compose build --no-cache
|
echo " • $image"
|
||||||
echo "镜像重新构建完成"
|
|
||||||
elif $all_images_exist; then
|
|
||||||
echo "所有镜像已存在,跳过构建"
|
|
||||||
else
|
|
||||||
echo "检测到缺失镜像,尝试从缓存加载..."
|
|
||||||
|
|
||||||
# 尝试从缓存加载
|
|
||||||
loaded_from_cache=false
|
|
||||||
if [ -d "$IMAGE_CACHE_DIR" ]; then
|
|
||||||
for image in "${IMAGES[@]}"; do
|
|
||||||
if ! docker images --format "{{.Repository}}:{{.Tag}}" | grep -q "^${image}$"; then
|
|
||||||
# 镜像不存在,尝试加载
|
|
||||||
case "$image" in
|
|
||||||
"argus-metric-ftp:latest")
|
|
||||||
cache_file="${IMAGE_CACHE_DIR}/argus-ftp.tar"
|
|
||||||
;;
|
|
||||||
"argus-metric-prometheus:latest")
|
|
||||||
cache_file="${IMAGE_CACHE_DIR}/argus-prometheus.tar"
|
|
||||||
;;
|
|
||||||
"argus-metric-grafana:latest")
|
|
||||||
cache_file="${IMAGE_CACHE_DIR}/argus-grafana.tar"
|
|
||||||
;;
|
|
||||||
"argus-metric-test-node:latest")
|
|
||||||
cache_file="${IMAGE_CACHE_DIR}/argus-test-node.tar"
|
|
||||||
;;
|
|
||||||
"argus-metric-test-gpu-node:latest")
|
|
||||||
cache_file="${IMAGE_CACHE_DIR}/argus-test-gpu-node.tar"
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
|
|
||||||
if [ -f "$cache_file" ]; then
|
|
||||||
echo " 从缓存加载: $image"
|
|
||||||
docker load -i "$cache_file"
|
|
||||||
loaded_from_cache=true
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
fi
|
|
||||||
|
|
||||||
# 检查加载后是否还有缺失的镜像
|
|
||||||
need_build=false
|
|
||||||
for image in "${IMAGES[@]}"; do
|
|
||||||
if ! docker images --format "{{.Repository}}:{{.Tag}}" | grep -q "^${image}$"; then
|
|
||||||
need_build=true
|
|
||||||
break
|
|
||||||
fi
|
|
||||||
done
|
done
|
||||||
|
echo ""
|
||||||
if $need_build; then
|
echo "构建命令:"
|
||||||
echo ""
|
echo " ./build/build_images.sh --metric"
|
||||||
echo "部分镜像缺失,开始构建..."
|
exit 1
|
||||||
echo "工作目录: $(pwd)"
|
else
|
||||||
cd "$TEST_DIR"
|
echo "所有必要镜像已存在"
|
||||||
docker compose build --no-cache
|
|
||||||
|
|
||||||
# 询问是否保存镜像
|
|
||||||
echo ""
|
|
||||||
read -p "是否保存镜像到缓存以便下次快速启动? (Y/n): " -n 1 -r
|
|
||||||
echo
|
|
||||||
if [[ ! $REPLY =~ ^[Nn]$ ]]; then
|
|
||||||
mkdir -p "$IMAGE_CACHE_DIR"
|
|
||||||
echo "保存镜像到缓存..."
|
|
||||||
for image in "${IMAGES[@]}"; do
|
|
||||||
case "$image" in
|
|
||||||
"argus-metric-ftp:latest")
|
|
||||||
docker save -o "${IMAGE_CACHE_DIR}/argus-ftp.tar" "$image" && echo " 已保存: argus-ftp.tar"
|
|
||||||
;;
|
|
||||||
"argus-metric-prometheus:latest")
|
|
||||||
docker save -o "${IMAGE_CACHE_DIR}/argus-prometheus.tar" "$image" && echo " 已保存: argus-prometheus.tar"
|
|
||||||
;;
|
|
||||||
"argus-metric-grafana:latest")
|
|
||||||
docker save -o "${IMAGE_CACHE_DIR}/argus-grafana.tar" "$image" && echo " 已保存: argus-grafana.tar"
|
|
||||||
;;
|
|
||||||
"argus-metric-test-node:latest")
|
|
||||||
docker save -o "${IMAGE_CACHE_DIR}/argus-test-node.tar" "$image" && echo " 已保存: argus-test-node.tar"
|
|
||||||
;;
|
|
||||||
"argus-metric-test-gpu-node:latest")
|
|
||||||
docker save -o "${IMAGE_CACHE_DIR}/argus-test-gpu-node.tar" "$image" && echo " 已保存: argus-test-gpu-node.tar"
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
done
|
|
||||||
echo "镜像已保存到: $IMAGE_CACHE_DIR/"
|
|
||||||
fi
|
|
||||||
elif $loaded_from_cache; then
|
|
||||||
echo ""
|
|
||||||
echo "所有镜像已从缓存加载完成!"
|
|
||||||
fi
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo ""
|
echo ""
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user