#!/bin/bash # Script: validate_input.sh # Description: Validates prerequisites and input parameters for building and pushing a Docker image. # This script ensures that Docker, Docker Buildx, and input variables (architectures, tags, image name, registry URL) # meet the required criteria. If any check fails, the script provides informative error messages and exits. # Exit immediately if a command exits with a non-zero status. set -e echo "============================================" echo "Starting Validation Script" echo "============================================" # ---------------------------- Docker Installation --------------------------- # echo "🔍 Checking Docker installation..." if docker --version >/dev/null 2>&1; then DOCKER_VERSION=$(docker --version) echo "✅ Docker is installed: $DOCKER_VERSION" else echo "❌ Docker is not installed." echo "â„šī¸ Please install Docker from: https://docs.docker.com/get-docker/" exit 1 fi # ---------------------------- Buildx Installation --------------------------- # echo "🔍 Checking Docker Buildx installation..." if docker buildx version >/dev/null 2>&1; then BUILDX_VERSION=$(docker buildx version) echo "✅ Docker Buildx is installed: $BUILDX_VERSION" else echo "❌ Docker Buildx is not installed." echo "â„šī¸ Please install Docker Buildx. See: https://docs.docker.com/buildx/working-with-buildx/" exit 1 fi # ---------------------------- Validate Architectures --------------------------- # # Architectures are CSV (amd64,arm64) # Usage: ./ensure_lowercase.sh "Architecture" amd64,arm64 echo "🔍 Validating architectures..." for arch in $(echo $ARCHITECTURES | tr "," "\n"); do # Ensure architecture is lowercase. if [[ "$arch" != "${arch,,}" ]]; then echo "❌ Invalid Architecture: $arch" echo "â„šī¸ Architecture must be lowercase" exit 1 else echo "✅ Architecture is valid: $arch" fi # Ensure architecture is supported by Docker Buildx. if docker buildx inspect --bootstrap | grep -q $arch; then echo "✅ Architecture is supported by Docker Buildx: $arch" else echo "❌ Architecture is not supported by Docker Buildx: $arch" echo "â„šī¸ Please check the supported platforms: https://docs.docker.com/buildx/working-with-buildx/" exit 1 fi done echo "✅ All specified architectures are valid."