2026-01-19 11:55:17 +01:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
|
|
# Base Image Pre-Pull Script for Bakery-IA
|
|
|
|
|
# This script pre-pulls all required base images to reduce Docker Hub usage
|
|
|
|
|
# Run this script before building services to cache base images locally
|
|
|
|
|
|
|
|
|
|
set -e
|
|
|
|
|
|
2026-01-20 22:05:10 +01:00
|
|
|
# Function to check if required tools are available
|
|
|
|
|
check_required_tools() {
|
|
|
|
|
local missing_tools=()
|
|
|
|
|
|
|
|
|
|
# Check for required tools
|
|
|
|
|
for tool in docker curl jq; do
|
|
|
|
|
if ! command -v "$tool" &> /dev/null; then
|
|
|
|
|
missing_tools+=("$tool")
|
|
|
|
|
fi
|
|
|
|
|
done
|
|
|
|
|
|
|
|
|
|
if [ ${#missing_tools[@]} -gt 0 ]; then
|
|
|
|
|
echo "Error: Missing required tools: ${missing_tools[*]}"
|
|
|
|
|
echo "Please install them before running this script."
|
|
|
|
|
echo ""
|
|
|
|
|
echo "On macOS (with Homebrew):"
|
|
|
|
|
echo " brew install docker curl jq"
|
|
|
|
|
echo ""
|
|
|
|
|
echo "On Ubuntu/Debian:"
|
|
|
|
|
echo " sudo apt-get install docker.io curl jq"
|
|
|
|
|
echo ""
|
|
|
|
|
echo "On CentOS/RHEL:"
|
|
|
|
|
echo " sudo yum install docker curl jq"
|
|
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# Check for required tools
|
|
|
|
|
check_required_tools
|
|
|
|
|
|
2026-01-19 11:55:17 +01:00
|
|
|
echo "=========================================="
|
|
|
|
|
echo "Bakery-IA Base Image Pre-Pull Script"
|
|
|
|
|
echo "=========================================="
|
|
|
|
|
echo ""
|
|
|
|
|
|
|
|
|
|
# Docker Hub credentials (use the same as in your Kubernetes setup)
|
|
|
|
|
DOCKER_USERNAME="uals"
|
|
|
|
|
DOCKER_PASSWORD="dckr_pat_zzEY5Q58x1S0puraIoKEtbpue3A"
|
|
|
|
|
|
|
|
|
|
# Authenticate with Docker Hub
|
|
|
|
|
echo "Authenticating with Docker Hub..."
|
2026-01-20 22:05:10 +01:00
|
|
|
echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin
|
2026-01-19 11:55:17 +01:00
|
|
|
echo "✓ Authentication successful"
|
|
|
|
|
echo ""
|
|
|
|
|
|
|
|
|
|
# Define all base images used in the project
|
|
|
|
|
# All images are cached in local registry for dev environment
|
|
|
|
|
BASE_IMAGES=(
|
|
|
|
|
# Service base images
|
|
|
|
|
"python:3.11-slim"
|
|
|
|
|
# Database images
|
|
|
|
|
"postgres:17-alpine"
|
|
|
|
|
"redis:7.4-alpine"
|
|
|
|
|
"rabbitmq:4.1-management-alpine"
|
|
|
|
|
# Utility images
|
|
|
|
|
"busybox:1.36"
|
|
|
|
|
"curlimages/curl:latest"
|
|
|
|
|
"bitnami/kubectl:latest"
|
|
|
|
|
# Alpine variants
|
|
|
|
|
"alpine:3.18"
|
|
|
|
|
"alpine:3.19"
|
|
|
|
|
"alpine/git:2.43.0"
|
|
|
|
|
# CI/CD images
|
|
|
|
|
"gcr.io/kaniko-project/executor:v1.23.0"
|
|
|
|
|
"gcr.io/go-containerregistry/crane:latest"
|
|
|
|
|
"registry.k8s.io/kustomize/kustomize:v5.3.0"
|
|
|
|
|
# Storage images
|
|
|
|
|
"minio/minio:RELEASE.2024-11-07T00-52-20Z"
|
|
|
|
|
"minio/mc:RELEASE.2024-11-17T19-35-25Z"
|
|
|
|
|
# Geocoding
|
|
|
|
|
"mediagis/nominatim:4.4"
|
|
|
|
|
# Mail server (Mailu - from GHCR)
|
|
|
|
|
"ghcr.io/mailu/nginx:2024.06"
|
|
|
|
|
"ghcr.io/mailu/admin:2024.06"
|
|
|
|
|
"ghcr.io/mailu/postfix:2024.06"
|
|
|
|
|
"ghcr.io/mailu/dovecot:2024.06"
|
|
|
|
|
"ghcr.io/mailu/rspamd:2024.06"
|
|
|
|
|
)
|
|
|
|
|
|
2026-01-19 22:28:53 +01:00
|
|
|
# Registry configuration
|
|
|
|
|
# Read from environment variables (set by Tiltfile or manually)
|
|
|
|
|
# USE_LOCAL_REGISTRY=true to push images to local registry after pulling
|
2026-01-20 22:05:10 +01:00
|
|
|
USE_LOCAL_REGISTRY="${USE_LOCAL_REGISTRY:-true}"
|
2026-01-19 22:28:53 +01:00
|
|
|
|
|
|
|
|
echo "Registry configuration:"
|
|
|
|
|
echo " USE_LOCAL_REGISTRY=$USE_LOCAL_REGISTRY"
|
|
|
|
|
echo ""
|
|
|
|
|
|
2026-01-20 22:05:10 +01:00
|
|
|
# Use local registry (kind registry)
|
|
|
|
|
REGISTRY="localhost:5000"
|
2026-01-19 22:28:53 +01:00
|
|
|
|
2026-01-20 22:05:10 +01:00
|
|
|
# If using local registry, verify it's running
|
|
|
|
|
if [ "$USE_LOCAL_REGISTRY" = "true" ]; then
|
|
|
|
|
echo "Checking local registry at $REGISTRY..."
|
|
|
|
|
if curl -s http://$REGISTRY/v2/ >/dev/null 2>&1; then
|
|
|
|
|
echo "✓ Local registry is accessible"
|
2026-01-19 22:28:53 +01:00
|
|
|
else
|
2026-01-20 22:05:10 +01:00
|
|
|
echo "⚠ Local registry is not accessible at $REGISTRY"
|
|
|
|
|
echo "Will only pull images locally (no registry push)"
|
|
|
|
|
USE_LOCAL_REGISTRY="false"
|
2026-01-19 22:28:53 +01:00
|
|
|
fi
|
|
|
|
|
fi
|
2026-01-19 11:55:17 +01:00
|
|
|
|
2026-01-20 22:05:10 +01:00
|
|
|
echo ""
|
2026-01-19 11:55:17 +01:00
|
|
|
echo "Base images to pre-pull:"
|
|
|
|
|
echo "----------------------------------------"
|
|
|
|
|
for image in "${BASE_IMAGES[@]}"; do
|
|
|
|
|
echo " - $image"
|
|
|
|
|
done
|
|
|
|
|
echo ""
|
|
|
|
|
|
|
|
|
|
echo "Starting pre-pull process..."
|
|
|
|
|
echo "----------------------------------------"
|
|
|
|
|
|
2026-01-20 22:05:10 +01:00
|
|
|
# Track success/failure
|
|
|
|
|
FAILED_IMAGES=()
|
|
|
|
|
SUCCESS_COUNT=0
|
|
|
|
|
|
2026-01-19 11:55:17 +01:00
|
|
|
# Pull each base image
|
|
|
|
|
for image in "${BASE_IMAGES[@]}"; do
|
|
|
|
|
echo "Pulling: $image"
|
2026-01-20 22:05:10 +01:00
|
|
|
|
2026-01-19 11:55:17 +01:00
|
|
|
# Pull the image
|
2026-01-20 22:05:10 +01:00
|
|
|
if ! docker pull "$image"; then
|
|
|
|
|
echo " ⚠ Failed to pull $image"
|
|
|
|
|
FAILED_IMAGES+=("$image")
|
|
|
|
|
continue
|
|
|
|
|
fi
|
|
|
|
|
|
2026-01-19 22:28:53 +01:00
|
|
|
# Tag for registry if enabled
|
2026-01-20 22:05:10 +01:00
|
|
|
if [ "$USE_LOCAL_REGISTRY" = "true" ]; then
|
|
|
|
|
# Local registry format: replace /, :, -, and . with _
|
|
|
|
|
local_repo="$(echo $image | sed 's|/|_|g' | sed 's|:|_|g' | sed 's|-|_|g' | sed 's|\.|_|g' | tr '[:upper:]' '[:lower:]')"
|
|
|
|
|
registry_image="$REGISTRY/${local_repo}:latest"
|
2026-01-20 07:20:56 +01:00
|
|
|
|
2026-01-19 22:28:53 +01:00
|
|
|
docker tag "$image" "$registry_image"
|
|
|
|
|
echo " Tagged as: $registry_image"
|
|
|
|
|
|
|
|
|
|
# Push to registry
|
2026-01-20 22:05:10 +01:00
|
|
|
if docker push "$registry_image"; then
|
|
|
|
|
echo " ✓ Pushed to local registry"
|
2026-01-19 22:28:53 +01:00
|
|
|
else
|
2026-01-20 22:05:10 +01:00
|
|
|
echo " ⚠ Failed to push to registry (image still available locally)"
|
2026-01-19 22:28:53 +01:00
|
|
|
fi
|
2026-01-19 11:55:17 +01:00
|
|
|
fi
|
2026-01-20 22:05:10 +01:00
|
|
|
|
2026-01-19 11:55:17 +01:00
|
|
|
echo " ✓ Successfully pulled $image"
|
2026-01-20 22:05:10 +01:00
|
|
|
SUCCESS_COUNT=$((SUCCESS_COUNT + 1))
|
2026-01-19 11:55:17 +01:00
|
|
|
echo ""
|
|
|
|
|
done
|
|
|
|
|
|
|
|
|
|
echo "=========================================="
|
|
|
|
|
echo "Base Image Pre-Pull Complete!"
|
|
|
|
|
echo "=========================================="
|
|
|
|
|
echo ""
|
|
|
|
|
echo "Summary:"
|
2026-01-20 22:05:10 +01:00
|
|
|
echo " - Total images: ${#BASE_IMAGES[@]}"
|
|
|
|
|
echo " - Successfully pulled: $SUCCESS_COUNT"
|
|
|
|
|
if [ ${#FAILED_IMAGES[@]} -gt 0 ]; then
|
|
|
|
|
echo " - Failed: ${#FAILED_IMAGES[@]}"
|
|
|
|
|
echo " - Failed images: ${FAILED_IMAGES[*]}"
|
2026-01-19 22:28:53 +01:00
|
|
|
fi
|
2026-01-20 22:05:10 +01:00
|
|
|
if [ "$USE_LOCAL_REGISTRY" = "true" ]; then
|
|
|
|
|
echo " - Registry: Local ($REGISTRY)"
|
|
|
|
|
else
|
|
|
|
|
echo " - Registry: None (local Docker only)"
|
2026-01-19 11:55:17 +01:00
|
|
|
fi
|
|
|
|
|
echo ""
|
|
|
|
|
|
2026-01-20 22:05:10 +01:00
|
|
|
# Exit with error if any images failed
|
|
|
|
|
if [ ${#FAILED_IMAGES[@]} -gt 0 ]; then
|
|
|
|
|
echo "⚠ Some images failed to pull. This may be due to Docker Hub rate limits."
|
|
|
|
|
echo "Please try again later or configure Docker Hub credentials."
|
|
|
|
|
exit 1
|
2026-01-19 22:28:53 +01:00
|
|
|
fi
|
2026-01-19 11:55:17 +01:00
|
|
|
|
2026-01-20 22:05:10 +01:00
|
|
|
echo "✓ All images pulled successfully!"
|