#!/bin/bash

# AAF Systems Homepage - Docker Package Script
# This script builds and packages the Docker image for transfer to another computer

echo "📦 AAF Systems Homepage Docker Packaging"
echo "========================================"

IMAGE_NAME="aaf-systems-homepage"
PACKAGE_NAME="aaf-systems-homepage-docker.tar"

# Check if Docker is running
if ! sudo docker info > /dev/null 2>&1; then
    echo "❌ Docker is not running. Please start Docker and try again."
    exit 1
fi

echo "🔨 Building Docker image..."
sudo docker build -t $IMAGE_NAME .

if [ $? -ne 0 ]; then
    echo "❌ Failed to build Docker image"
    exit 1
fi

echo "📦 Packaging Docker image to $PACKAGE_NAME..."
sudo docker save -o $PACKAGE_NAME $IMAGE_NAME

if [ $? -eq 0 ]; then
    echo "✅ Docker image packaged successfully!"
    echo ""
    echo "📋 Transfer Instructions:"
    echo "========================"
    echo "1. Copy '$PACKAGE_NAME' to the target computer"
    echo "2. On the target computer, run:"
    echo "   sudo docker load -i $PACKAGE_NAME"
    echo "3. Run the container:"
    echo "   sudo docker run -p 8080:8080 --name aaf-systems-homepage $IMAGE_NAME"
    echo ""
    echo "📊 Package Info:"
    echo "==============="
    ls -lh $PACKAGE_NAME
else
    echo "❌ Failed to package Docker image"
    exit 1
fi
