#!/bin/bash # Script to sync base images to registry.nxtgauge.com # Run this on one of the cluster nodes that has Docker access REGISTRY="registry.nxtgauge.com" REGISTRY_USER="admin" echo "==================================" echo "Syncing base images to $REGISTRY" echo "==================================" # Get registry password from secret REGISTRY_PASS=$(kubectl get secret -n registry registry-auth -o jsonpath='{.data.htpasswd}' | base64 -d | cut -d':' -f2) # Login to registry echo "Logging into registry..." echo "$REGISTRY_PASS" | docker login $REGISTRY -u $REGISTRY_USER --password-stdin 2>/dev/null || { echo "Failed to login to registry. Make sure you're running this on a node with kubectl access." exit 1 } # Base images required by the project Dockerfiles images=( "node:20-alpine" "rust:alpine" "alpine:3.20" "alpine:latest" "python:3.12-slim" "docker:27-dind" "busybox:1.36" ) for image in "${images[@]}"; do echo "" echo "Processing $image..." # Pull from Docker Hub echo " Pulling docker.io/$image..." if docker pull docker.io/library/$image 2>/dev/null; then SOURCE="docker.io/library/$image" elif docker pull docker.io/$image 2>/dev/null; then SOURCE="docker.io/$image" else echo " ERROR: Failed to pull $image" continue fi # Tag for registry TARGET="$REGISTRY/$image" echo " Tagging as $TARGET..." docker tag $SOURCE $TARGET # Push to registry echo " Pushing to $REGISTRY..." if docker push $TARGET; then echo " SUCCESS: $image synced" else echo " ERROR: Failed to push $image" fi done echo "" echo "==================================" echo "Base image sync complete!" echo "==================================" echo "" echo "Synced images:" for image in "${images[@]}"; do echo " - $REGISTRY/$image" done