diff --git a/src/log/scripts/load_images.sh b/src/log/scripts/load_images.sh new file mode 100755 index 0000000..553b37c --- /dev/null +++ b/src/log/scripts/load_images.sh @@ -0,0 +1,127 @@ +#!/usr/bin/env bash +set -euo pipefail + +echo "=======================================" +echo "ARGUS Log System - Image Import Tool" +echo "=======================================" +echo "" + +# 获取脚本所在目录和镜像目录 +script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +images_dir="$script_dir/../images" + +# 定义镜像文件名 +ES_TAR="argus-elasticsearch-latest.tar" +KIBANA_TAR="argus-kibana-latest.tar" + +# 函数:检查文件是否存在 +check_file() { + local file_path="$1" + local file_name="$2" + if [[ -f "$file_path" ]]; then + local size=$(du -h "$file_path" | cut -f1) + echo "✅ Found: $file_name ($size)" + return 0 + else + echo "❌ Missing: $file_name" + return 1 + fi +} + +# 函数:加载镜像 +load_image() { + local file_path="$1" + local file_name="$2" + + echo "🔄 Loading $file_name..." + + if docker load -i "$file_path"; then + echo "✅ Successfully loaded: $file_name" + return 0 + else + echo "❌ Failed to load: $file_name" + return 1 + fi +} + +echo "🔍 Checking for ARGUS image files in $images_dir..." +echo "" + +# 检查镜像文件是否存在 +es_file="$images_dir/$ES_TAR" +kibana_file="$images_dir/$KIBANA_TAR" + +es_exists=false +kibana_exists=false + +if check_file "$es_file" "$ES_TAR"; then + es_exists=true +fi + +if check_file "$kibana_file" "$KIBANA_TAR"; then + kibana_exists=true +fi + +echo "" + +# 如果没有任何文件存在,退出 +if [[ "$es_exists" == false && "$kibana_exists" == false ]]; then + echo "❌ No ARGUS image files found in $images_dir" + echo " Please run './scripts/save_images.sh' first to export images" + exit 1 +fi + +echo "💾 Starting image import process..." +echo "" + +loaded_count=0 +failed_count=0 + +# 加载 Elasticsearch 镜像 +if [[ "$es_exists" == true ]]; then + if load_image "$es_file" "$ES_TAR"; then + ((loaded_count++)) + else + ((failed_count++)) + fi + echo "" +fi + +# 加载 Kibana 镜像 +if [[ "$kibana_exists" == true ]]; then + if load_image "$kibana_file" "$KIBANA_TAR"; then + ((loaded_count++)) + else + ((failed_count++)) + fi + echo "" +fi + +echo "=======================================" +echo "📦 Import Summary" +echo "=======================================" +echo "✅ Successfully loaded: $loaded_count images" + +if [[ $failed_count -gt 0 ]]; then + echo "❌ Failed to load: $failed_count images" +fi + +echo "" +echo "🔍 Verifying loaded images:" +docker images | grep "argus-" || echo " No ARGUS images found" + +echo "" + +if [[ $failed_count -eq 0 ]]; then + echo "✅ All images imported successfully!" + echo "" + echo "🚀 Next steps:" + echo " You can now use the imported images with:" + echo " ./scripts/02_up.sh # Start services" + echo " ./scripts/00_e2e_test.sh # Run end-to-end test" +else + echo "⚠️ Some images failed to import. Please check the error messages above." + exit 1 +fi + +echo "" \ No newline at end of file diff --git a/src/log/scripts/save_images.sh b/src/log/scripts/save_images.sh index 5a9b268..60054b0 100755 --- a/src/log/scripts/save_images.sh +++ b/src/log/scripts/save_images.sh @@ -24,7 +24,7 @@ KIBANA_TAR="argus-kibana-latest.tar" # 函数:检查镜像是否存在 check_image() { local image_name="$1" - if docker images --format "table {{.Repository}}:{{.Tag}}" | grep -q "^$image_name$"; then + if docker images --format "{{.Repository}}:{{.Tag}}" | grep -q "^$image_name$"; then echo "✅ Image found: $image_name" return 0 else