#!/usr/bin/env bash # Import Findings Ledger container images into local Docker/containerd # Usage: ./import-images.sh [registry-prefix] # # Example: # ./import-images.sh # Loads as stellaops/* # ./import-images.sh myregistry.local/ # Loads and tags as myregistry.local/stellaops/* set -euo pipefail SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" IMAGES_DIR="${SCRIPT_DIR}/../images" REGISTRY_PREFIX="${1:-}" # Color output helpers RED='\033[0;31m' GREEN='\033[0;32m' YELLOW='\033[1;33m' NC='\033[0m' log_info() { echo -e "${GREEN}[INFO]${NC} $*"; } log_warn() { echo -e "${YELLOW}[WARN]${NC} $*"; } log_error() { echo -e "${RED}[ERROR]${NC} $*"; } # Detect container runtime detect_runtime() { if command -v docker &>/dev/null; then echo "docker" elif command -v nerdctl &>/dev/null; then echo "nerdctl" elif command -v podman &>/dev/null; then echo "podman" else log_error "No container runtime found (docker, nerdctl, podman)" exit 1 fi } RUNTIME=$(detect_runtime) log_info "Using container runtime: $RUNTIME" # Load images from tarballs load_images() { local count=0 for tarball in "${IMAGES_DIR}"/*.tar; do if [[ -f "$tarball" ]]; then log_info "Loading image from: $(basename "$tarball")" if $RUNTIME load -i "$tarball"; then ((count++)) else log_error "Failed to load: $tarball" return 1 fi fi done if [[ $count -eq 0 ]]; then log_warn "No image tarballs found in $IMAGES_DIR" log_warn "Run the offline kit builder first to populate images" return 1 fi log_info "Loaded $count image(s)" } # Re-tag images with custom registry prefix retag_images() { if [[ -z "$REGISTRY_PREFIX" ]]; then log_info "No registry prefix specified, skipping re-tag" return 0 fi local images=( "stellaops/findings-ledger" "stellaops/findings-ledger-migrations" ) for image in "${images[@]}"; do # Get the loaded tag local loaded_tag loaded_tag=$($RUNTIME images --format '{{.Repository}}:{{.Tag}}' | grep "^${image}:" | head -1) if [[ -n "$loaded_tag" ]]; then local new_tag="${REGISTRY_PREFIX}${loaded_tag}" log_info "Re-tagging: $loaded_tag -> $new_tag" $RUNTIME tag "$loaded_tag" "$new_tag" fi done } # Verify loaded images verify_images() { log_info "Verifying loaded images..." local images=( "stellaops/findings-ledger" "stellaops/findings-ledger-migrations" ) local missing=0 for image in "${images[@]}"; do if $RUNTIME images --format '{{.Repository}}' | grep -q "^${REGISTRY_PREFIX}${image}$"; then log_info " ✓ ${REGISTRY_PREFIX}${image}" else log_error " ✗ ${REGISTRY_PREFIX}${image} not found" ((missing++)) fi done if [[ $missing -gt 0 ]]; then log_error "$missing image(s) missing" return 1 fi log_info "All images verified" } main() { log_info "Findings Ledger - Image Import" log_info "==============================" load_images retag_images verify_images log_info "Image import complete" } main "$@"