From 3c5df92c06e7c307ff5aada928490d9978f0ad36 Mon Sep 17 00:00:00 2001 From: aipper Date: Sat, 1 Nov 2025 16:42:15 +0800 Subject: [PATCH] test --- archive-manager.sh | 35 +++++++++++++++++++++++++++-------- check-images.sh | 43 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 70 insertions(+), 8 deletions(-) create mode 100755 check-images.sh diff --git a/archive-manager.sh b/archive-manager.sh index 82b817c..d08fdc9 100755 --- a/archive-manager.sh +++ b/archive-manager.sh @@ -197,22 +197,41 @@ deploy_app() { log_info "部署应用到: $deploy_dir" - # 确定要使用的镜像版本 - if [ "$FAST_BUILD" = true ]; then + # 自动检测可用的镜像版本 + local fast_image=$(docker images "${PROJECT_NAME}:fast" --format "{{.Repository}}:{{.Tag}}" | head -1) + local stable_image=$(docker images "${PROJECT_NAME}:stable" --format "{{.Repository}}:{{.Tag}}" | head -1) + + if [ "$FAST_BUILD" = true ] && [ -n "$fast_image" ]; then VERSION="fast" log_info "使用快速构建版本: ${PROJECT_NAME}:fast" - else + elif [ -n "$stable_image" ]; then VERSION="stable" log_info "使用完整构建版本: ${PROJECT_NAME}:stable" + elif [ -n "$fast_image" ]; then + VERSION="fast" + log_info "找到快速版本,使用: ${PROJECT_NAME}:fast" + else + log_error "未找到任何可用的镜像" + log_error "请先构建镜像: $0 build" + exit 1 fi - # 检查镜像 - if ! docker images | grep -q "${PROJECT_NAME}:${VERSION}"; then - log_error "镜像 ${PROJECT_NAME}:${VERSION} 不存在,请先构建: $0 build" - if [ "$FAST_BUILD" = true ]; then - log_error "或使用: $0 build -f" + # 检查镜像 - 更可靠的检测方式 + local image_exists=$(docker images "${PROJECT_NAME}:${VERSION}" --format "{{.Repository}}:{{.Tag}}" | head -1) + if [ -z "$image_exists" ]; then + log_error "镜像 ${PROJECT_NAME}:${VERSION} 不存在" + log_error "请先构建镜像:" + if [ "$VERSION" = "fast" ]; then + log_error " $0 build -f" + else + log_error " $0 build" fi + echo + log_info "可用的镜像列表:" + docker images "${PROJECT_NAME}*" --format "table {{.Repository}}\t{{.Tag}}\t{{.Size}}" 2>/dev/null || echo " 无可用镜像" exit 1 + else + log_success "找到镜像: $image_exists" fi # 创建部署目录 diff --git a/check-images.sh b/check-images.sh new file mode 100755 index 0000000..ba5024d --- /dev/null +++ b/check-images.sh @@ -0,0 +1,43 @@ +#!/bin/bash + +echo "=== 镜像检测测试 ===" +echo + +# 检查 digital-archive 镜像 +echo "🔍 检查可用的 digital-archive 镜像:" +docker images "digital-archive*" --format "table {{.Repository}}\t{{.Tag}}\t{{.Size}}\t{{.CreatedAt}}" || echo "❌ 未找到任何 digital-archive 镜像" + +echo +echo "🧪 测试镜像检测逻辑:" + +# 测试 stable 镜像 +stable_image=$(docker images "digital-archive:stable" --format "{{.Repository}}:{{.Tag}}" | head -1) +if [ -n "$stable_image" ]; then + echo "✅ 找到 stable 镜像: $stable_image" +else + echo "❌ 未找到 stable 镜像" +fi + +# 测试 fast 镜像 +fast_image=$(docker images "digital-archive:fast" --format "{{.Repository}}:{{.Tag}}" | head -1) +if [ -n "$fast_image" ]; then + echo "✅ 找到 fast 镜像: $fast_image" +else + echo "❌ 未找到 fast 镜像" +fi + +echo +echo "📋 推荐操作:" +if [ -n "$stable_image" ]; then + echo " ./archive-manager.sh deploy # 使用 stable 版本" +fi +if [ -n "$fast_image" ]; then + echo " ./archive-manager.sh deploy -f # 使用 fast 版本" +fi +if [ -z "$stable_image" ] && [ -z "$fast_image" ]; then + echo " ./archive-manager.sh build # 构建镜像" + echo " ./archive-manager.sh build -f # 快速构建" +fi + +echo +echo "=== 测试完成 ===" \ No newline at end of file