#!/bin/bash

# Build script for Debian bootc-image-builder container
set -e

# Configuration
CONTAINER_NAME="debian-bootc-image-builder"
CONTAINER_TAG="latest"
REGISTRY="git.raines.xyz/particle-os"

echo "Building Debian bootc-image-builder container..."

# Build the container
echo "Building container image..."
podman build -t "${CONTAINER_NAME}:${CONTAINER_TAG}" .

# Tag for registry
echo "Tagging for registry..."
podman tag "${CONTAINER_NAME}:${CONTAINER_TAG}" "${REGISTRY}/${CONTAINER_NAME}:${CONTAINER_TAG}"

echo "Container build completed successfully!"
echo "Local image: ${CONTAINER_NAME}:${CONTAINER_TAG}"
echo "Registry image: ${REGISTRY}/${CONTAINER_NAME}:${CONTAINER_TAG}"

# Optional: Push to registry
if [ "$1" = "--push" ]; then
    echo "Pushing to registry..."
    podman push "${REGISTRY}/${CONTAINER_NAME}:${CONTAINER_TAG}"
    echo "Container pushed to registry successfully!"
fi

echo "Usage:"
echo "  Local: podman run --rm -v \$(pwd)/output:/output ${CONTAINER_NAME}:${CONTAINER_TAG} --help"
echo "  Registry: podman run --rm -v \$(pwd)/output:/output ${REGISTRY}/${CONTAINER_NAME}:${CONTAINER_TAG} --help"
