#!/bin/bash echo "=== Docker Build Test Script ===" echo "Choose build type:" echo "1. Fast build (skip Tesseract, ~3-5 minutes)" echo "2. Full build (include all features, ~10-15 minutes)" echo read -p "Enter choice (1 or 2, default=1): " choice # 默认选择快速构建 if [ -z "$choice" ]; then choice=1 fi if [ "$choice" = "1" ]; then DOCKERFILE="Dockerfile.fast" TAG="digital-archive:fast" echo "🚀 Using fast build (Dockerfile.fast)" else DOCKERFILE="Dockerfile.stable" TAG="digital-archive:stable" echo "🔧 Using full build (Dockerfile.stable)" fi echo # 检查Docker是否可用 if ! command -v docker &> /dev/null; then echo "❌ Docker is not available on this system" echo "Please run this script on a server with Docker installed" exit 1 fi echo "✓ Docker found: $(docker --version)" # 构建镜像 echo echo "🏗️ Building Docker image..." echo "Using $DOCKERFILE, tag: $TAG" echo "This may take several minutes..." if docker build -f $DOCKERFILE -t $TAG .; then echo echo "✅ Build successful!" echo echo "📋 Image details:" docker images $TAG echo echo "🧪 Testing container startup..." # 测试容器启动 if docker run --rm --name test-container $TAG java -version; then echo "✅ Container test successful!" else echo "❌ Container test failed" fi # 清理测试镜像 echo echo "🧹 Cleaning up test image..." docker rmi $TAG else echo echo "❌ Build failed!" echo echo "🔍 Debugging info:" echo "1. Check Dockerfile.stable for syntax errors" echo "2. Verify all required files are present" echo "3. Check network connectivity for package downloads" echo "4. Verify src/main/lib/ directory contains all required JAR files" echo "5. Try running with --no-cache flag:" if [ "$choice" = "1" ]; then echo " docker build --no-cache -f Dockerfile.fast -t digital-archive:fast ." else echo " docker build --no-cache -f Dockerfile.stable -t digital-archive:stable ." fi echo echo "📋 Checking required files..." if [ -f "pom.xml" ]; then echo "✓ pom.xml found" else echo "❌ pom.xml missing" fi if [ -f "settings.xml" ]; then echo "✓ settings.xml found" else echo "❌ settings.xml missing" fi if [ -d "src/main/lib" ]; then echo "✓ src/main/lib directory found" echo " JAR files in lib:" ls -la src/main/lib/*.jar 2>/dev/null || echo " No JAR files found" else echo "❌ src/main/lib directory missing" fi fi echo echo "=== Test completed ==="