232 lines
6.3 KiB
Bash
232 lines
6.3 KiB
Bash
#!/bin/bash
|
|
|
|
# Docker Image Import Script
|
|
# Imports Docker images on target environment for migration
|
|
|
|
set -e
|
|
|
|
echo "🚀 Legal Document Masker - Docker Image Import"
|
|
echo "=============================================="
|
|
|
|
# Function to check if Docker is running
|
|
check_docker() {
|
|
if ! docker info > /dev/null 2>&1; then
|
|
echo "❌ Docker is not running. Please start Docker and try again."
|
|
exit 1
|
|
fi
|
|
echo "✅ Docker is running"
|
|
}
|
|
|
|
# Function to check for tar files
|
|
check_tar_files() {
|
|
echo "🔍 Checking for Docker image files..."
|
|
|
|
local missing_files=()
|
|
|
|
if [ ! -f "backend-api.tar" ]; then
|
|
missing_files+=("backend-api.tar")
|
|
fi
|
|
|
|
if [ ! -f "frontend.tar" ]; then
|
|
missing_files+=("frontend.tar")
|
|
fi
|
|
|
|
if [ ! -f "mineru-api.tar" ]; then
|
|
missing_files+=("mineru-api.tar")
|
|
fi
|
|
|
|
if [ ! -f "redis.tar" ]; then
|
|
missing_files+=("redis.tar")
|
|
fi
|
|
|
|
if [ ${#missing_files[@]} -ne 0 ]; then
|
|
echo "❌ Missing files: ${missing_files[*]}"
|
|
echo ""
|
|
echo "Please ensure all .tar files are in the current directory."
|
|
echo "If you have a compressed archive, extract it first:"
|
|
echo " tar -xzf legal-doc-masker-images-*.tar.gz"
|
|
exit 1
|
|
fi
|
|
|
|
echo "✅ All required files found"
|
|
}
|
|
|
|
# Function to check available disk space
|
|
check_disk_space() {
|
|
echo "💾 Checking available disk space..."
|
|
|
|
local required_space=0
|
|
for file in *.tar; do
|
|
local file_size=$(stat -f%z "$file" 2>/dev/null || stat -c%s "$file" 2>/dev/null || echo 0)
|
|
required_space=$((required_space + file_size))
|
|
done
|
|
|
|
local available_space=$(df . | awk 'NR==2 {print $4}')
|
|
available_space=$((available_space * 1024)) # Convert to bytes
|
|
|
|
if [ $required_space -gt $available_space ]; then
|
|
echo "❌ Insufficient disk space"
|
|
echo "Required: $(numfmt --to=iec $required_space)"
|
|
echo "Available: $(numfmt --to=iec $available_space)"
|
|
exit 1
|
|
fi
|
|
|
|
echo "✅ Sufficient disk space available"
|
|
}
|
|
|
|
# Function to import images
|
|
import_images() {
|
|
echo "📦 Importing Docker images..."
|
|
|
|
# Import backend image
|
|
echo " 📦 Importing backend-api image..."
|
|
docker load -i backend-api.tar
|
|
|
|
# Import frontend image
|
|
echo " 📦 Importing frontend image..."
|
|
docker load -i frontend.tar
|
|
|
|
# Import mineru image
|
|
echo " 📦 Importing mineru-api image..."
|
|
docker load -i mineru-api.tar
|
|
|
|
# Import redis image
|
|
echo " 📦 Importing redis image..."
|
|
docker load -i redis.tar
|
|
|
|
echo "✅ All images imported successfully!"
|
|
}
|
|
|
|
# Function to verify imported images
|
|
verify_images() {
|
|
echo "🔍 Verifying imported images..."
|
|
|
|
local missing_images=()
|
|
|
|
if ! docker images | grep -q "legal-doc-masker-backend-api"; then
|
|
missing_images+=("legal-doc-masker-backend-api")
|
|
fi
|
|
|
|
if ! docker images | grep -q "legal-doc-masker-frontend"; then
|
|
missing_images+=("legal-doc-masker-frontend")
|
|
fi
|
|
|
|
if ! docker images | grep -q "legal-doc-masker-mineru-api"; then
|
|
missing_images+=("legal-doc-masker-mineru-api")
|
|
fi
|
|
|
|
if ! docker images | grep -q "redis:alpine"; then
|
|
missing_images+=("redis:alpine")
|
|
fi
|
|
|
|
if [ ${#missing_images[@]} -ne 0 ]; then
|
|
echo "❌ Missing imported images: ${missing_images[*]}"
|
|
exit 1
|
|
fi
|
|
|
|
echo "✅ All images verified successfully!"
|
|
}
|
|
|
|
# Function to show imported images
|
|
show_imported_images() {
|
|
echo ""
|
|
echo "📊 Imported Images:"
|
|
echo "==================="
|
|
docker images --format "table {{.Repository}}\t{{.Tag}}\t{{.Size}}" | grep legal-doc-masker
|
|
docker images --format "table {{.Repository}}\t{{.Tag}}\t{{.Size}}" | grep redis
|
|
}
|
|
|
|
# Function to create necessary directories
|
|
create_directories() {
|
|
echo ""
|
|
echo "📁 Creating necessary directories..."
|
|
|
|
mkdir -p backend/storage
|
|
mkdir -p mineru/storage/uploads
|
|
mkdir -p mineru/storage/processed
|
|
|
|
echo "✅ Directories created"
|
|
}
|
|
|
|
# Function to check for required files
|
|
check_required_files() {
|
|
echo ""
|
|
echo "🔍 Checking for required configuration files..."
|
|
|
|
local missing_files=()
|
|
|
|
if [ ! -f "docker-compose.yml" ]; then
|
|
missing_files+=("docker-compose.yml")
|
|
fi
|
|
|
|
if [ ! -f "DOCKER_COMPOSE_README.md" ]; then
|
|
missing_files+=("DOCKER_COMPOSE_README.md")
|
|
fi
|
|
|
|
if [ ${#missing_files[@]} -ne 0 ]; then
|
|
echo "⚠️ Missing files: ${missing_files[*]}"
|
|
echo "Please copy these files from the source environment:"
|
|
echo " - docker-compose.yml"
|
|
echo " - DOCKER_COMPOSE_README.md"
|
|
echo " - backend/.env (if exists)"
|
|
echo " - frontend/.env (if exists)"
|
|
echo " - mineru/.env (if exists)"
|
|
else
|
|
echo "✅ All required configuration files found"
|
|
fi
|
|
}
|
|
|
|
# Function to show next steps
|
|
show_next_steps() {
|
|
echo ""
|
|
echo "🎉 Import completed successfully!"
|
|
echo ""
|
|
echo "📋 Next Steps:"
|
|
echo "=============="
|
|
echo ""
|
|
echo "1. Copy configuration files (if not already present):"
|
|
echo " - docker-compose.yml"
|
|
echo " - backend/.env"
|
|
echo " - frontend/.env"
|
|
echo " - mineru/.env"
|
|
echo ""
|
|
echo "2. Start the services:"
|
|
echo " docker-compose up -d"
|
|
echo ""
|
|
echo "3. Verify services are running:"
|
|
echo " docker-compose ps"
|
|
echo ""
|
|
echo "4. Test the endpoints:"
|
|
echo " - Frontend: http://localhost:3000"
|
|
echo " - Backend API: http://localhost:8000"
|
|
echo " - Mineru API: http://localhost:8001"
|
|
echo ""
|
|
echo "5. View logs if needed:"
|
|
echo " docker-compose logs -f [service-name]"
|
|
}
|
|
|
|
# Function to handle compressed archive
|
|
handle_compressed_archive() {
|
|
if ls legal-doc-masker-images-*.tar.gz 1> /dev/null 2>&1; then
|
|
echo "🗜️ Found compressed archive, extracting..."
|
|
tar -xzf legal-doc-masker-images-*.tar.gz
|
|
echo "✅ Archive extracted"
|
|
fi
|
|
}
|
|
|
|
# Main execution
|
|
main() {
|
|
check_docker
|
|
handle_compressed_archive
|
|
check_tar_files
|
|
check_disk_space
|
|
import_images
|
|
verify_images
|
|
show_imported_images
|
|
create_directories
|
|
check_required_files
|
|
show_next_steps
|
|
}
|
|
|
|
# Run main function
|
|
main "$@" |