#!/bin/bash
# Script to push base images to Harbor for offline/isolated cluster builds

set -e

HARBOR_REGISTRY="harbor.dvirlabs.com"
HARBOR_PROJECT="dockerhub"

echo "🐳 Pushing base images to Harbor..."
echo "Registry: $HARBOR_REGISTRY"
echo "Project: $HARBOR_PROJECT"
echo ""

# Login to Harbor (you may need to provide credentials)
echo "Please login to Harbor:"
docker login $HARBOR_REGISTRY

# Base images needed for the project
BASE_IMAGES=(
    "python:3.11-slim"
    "node:18-alpine"
    "nginx:alpine"
    "postgres:16-alpine"
    "alpine:3.19"
    "busybox:1.35"
    "busybox:latest"
)

echo ""
echo "📦 Processing ${#BASE_IMAGES[@]} base images..."
echo ""

for IMAGE in "${BASE_IMAGES[@]}"; do
    echo "➡️  Processing: $IMAGE"
    
    # Pull from Docker Hub
    echo "   Pulling from Docker Hub..."
    docker pull $IMAGE
    
    # Tag for Harbor
    HARBOR_IMAGE="$HARBOR_REGISTRY/$HARBOR_PROJECT/$IMAGE"
    echo "   Tagging as: $HARBOR_IMAGE"
    docker tag $IMAGE $HARBOR_IMAGE
    
    # Push to Harbor
    echo "   Pushing to Harbor..."
    docker push $HARBOR_IMAGE
    
    echo "   ✅ Done: $IMAGE"
    echo ""
done

echo "🎉 All base images pushed successfully!"
echo ""
echo "Your Harbor now contains:"
for IMAGE in "${BASE_IMAGES[@]}"; do
    echo "  - $HARBOR_REGISTRY/$HARBOR_PROJECT/$IMAGE"
done
echo ""
echo "You can now build your application in the cluster without Docker Hub access!"
