This commit is contained in:
2025-11-01 16:42:15 +08:00
parent da355d8bd3
commit 3c5df92c06
2 changed files with 70 additions and 8 deletions

View File

@@ -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
# 创建部署目录

43
check-images.sh Executable file
View File

@@ -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 "=== 测试完成 ==="