#!/bin/bash
# Build and push Alpine with git and yq for CI/CD
set -e

HARBOR_REGISTRY="harbor.dvirlabs.com"
HARBOR_PROJECT="base-images"
IMAGE_NAME="alpine-git-yq"
TAG="3.19"

echo "🏗️  Building Alpine image with git and yq..."
echo "Registry: $HARBOR_REGISTRY"
echo "Image: $HARBOR_PROJECT/$IMAGE_NAME:$TAG"
echo ""

# Build the image
cd base-images/alpine-git-yq
docker build -t $HARBOR_REGISTRY/$HARBOR_PROJECT/$IMAGE_NAME:$TAG .
docker tag $HARBOR_REGISTRY/$HARBOR_PROJECT/$IMAGE_NAME:$TAG $HARBOR_REGISTRY/$HARBOR_PROJECT/$IMAGE_NAME:latest
cd ../..

echo ""
echo "✅ Image built successfully!"
echo ""

# Login to Harbor
echo "Please login to Harbor:"
docker login $HARBOR_REGISTRY

# Push to Harbor
echo ""
echo "🚀 Pushing to Harbor..."
docker push $HARBOR_REGISTRY/$HARBOR_PROJECT/$IMAGE_NAME:$TAG
docker push $HARBOR_REGISTRY/$HARBOR_PROJECT/$IMAGE_NAME:latest

echo ""
echo "🎉 Alpine CI image pushed successfully!"
echo ""
echo "Image: $HARBOR_REGISTRY/$HARBOR_PROJECT/$IMAGE_NAME:$TAG"
echo ""
