PublishImage/scripts/validate_input.sh
mrrpnya 924bc279d9
Some checks failed
Test Deploy to OCI Registry / deploy (push) Failing after 3m34s
.
2025-03-06 16:13:20 -08:00

59 lines
2.4 KiB
Bash
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/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."