Add new infra architecture
This commit is contained in:
139
scripts/prepull-base-images.sh
Executable file
139
scripts/prepull-base-images.sh
Executable file
@@ -0,0 +1,139 @@
|
||||
#!/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
|
||||
|
||||
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..."
|
||||
docker login -u "$DOCKER_USERNAME" -p "$DOCKER_PASSWORD"
|
||||
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"
|
||||
)
|
||||
|
||||
# Local registry configuration
|
||||
# Set USE_LOCAL_REGISTRY=true to push images to local registry after pulling
|
||||
USE_LOCAL_REGISTRY=true
|
||||
LOCAL_REGISTRY="localhost:5000"
|
||||
|
||||
echo "Base images to pre-pull:"
|
||||
echo "----------------------------------------"
|
||||
for image in "${BASE_IMAGES[@]}"; do
|
||||
echo " - $image"
|
||||
done
|
||||
echo ""
|
||||
|
||||
echo "Starting pre-pull process..."
|
||||
echo "----------------------------------------"
|
||||
|
||||
# Pull each base image
|
||||
for image in "${BASE_IMAGES[@]}"; do
|
||||
echo "Pulling: $image"
|
||||
|
||||
# Pull the image
|
||||
docker pull "$image"
|
||||
|
||||
# Tag for local registry if enabled
|
||||
if [ "$USE_LOCAL_REGISTRY" = true ]; then
|
||||
# Convert image name to local registry format:
|
||||
# - Replace / with _
|
||||
# - Replace : with _
|
||||
# - Convert to lowercase (Docker requires lowercase repository names)
|
||||
# - Add :latest tag for Kustomize compatibility
|
||||
# Example: gcr.io/kaniko-project/executor:v1.23.0 -> gcr.io_kaniko-project_executor_v1.23.0:latest
|
||||
local_repo="$(echo $image | sed 's|/|_|g' | sed 's|:|_|g' | tr '[:upper:]' '[:lower:]')"
|
||||
local_image="$LOCAL_REGISTRY/${local_repo}:latest"
|
||||
docker tag "$image" "$local_image"
|
||||
echo " Tagged as: $local_image"
|
||||
|
||||
# Push to local registry
|
||||
docker push "$local_image"
|
||||
echo " Pushed to local registry"
|
||||
fi
|
||||
|
||||
echo " ✓ Successfully pulled $image"
|
||||
echo ""
|
||||
done
|
||||
|
||||
echo "=========================================="
|
||||
echo "Base Image Pre-Pull Complete!"
|
||||
echo "=========================================="
|
||||
echo ""
|
||||
echo "Summary:"
|
||||
echo " - Total images pulled: ${#BASE_IMAGES[@]}"
|
||||
echo " - Local registry enabled: $USE_LOCAL_REGISTRY"
|
||||
echo ""
|
||||
|
||||
if [ "$USE_LOCAL_REGISTRY" = true ]; then
|
||||
echo "Local registry contents:"
|
||||
curl -s http://$LOCAL_REGISTRY/v2/_catalog | jq .
|
||||
echo ""
|
||||
fi
|
||||
|
||||
echo "Next steps:"
|
||||
echo " 1. Run your service builds - they will use cached images"
|
||||
echo " 2. For Kubernetes: Consider setting up a pull-through cache"
|
||||
echo " 3. For CI/CD: Run this script before your build pipeline"
|
||||
echo ""
|
||||
|
||||
echo "To use local registry in your builds:"
|
||||
echo " - Update Dockerfiles to use: $LOCAL_REGISTRY/..."
|
||||
echo " - Or configure Docker daemon to use local registry as mirror"
|
||||
echo ""
|
||||
|
||||
# Optional: Configure Docker daemon to use local registry as mirror
|
||||
if [ "$USE_LOCAL_REGISTRY" = true ]; then
|
||||
echo "To configure Docker daemon to use local registry as mirror:"
|
||||
echo ""
|
||||
cat << 'EOF'
|
||||
{
|
||||
"registry-mirrors": ["http://localhost:5000"]
|
||||
}
|
||||
EOF
|
||||
echo ""
|
||||
echo "Add this to /etc/docker/daemon.json and restart Docker"
|
||||
fi
|
||||
Reference in New Issue
Block a user