PublishImage/scripts/validate_input.sh
mrrpnya 9b5294bb7e
Some checks failed
Test Deploy to OCI Registry / deploy (push) Failing after 1m17s
.
2025-03-06 13:39:23 -08:00

127 lines
4.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 --------------------------- #
echo "🔍 Validating architectures..."
for arch in $ARCHITECTURES; do
echo "→ Checking architecture: $arch"
if [[ $VALID_ARCHITECTURES != *"$arch"* ]]; then
echo "❌ Invalid architecture detected: $arch"
echo " Allowed architectures are: $VALID_ARCHITECTURES"
exit 1
fi
done
echo "✅ All specified architectures are valid."
# ---------------------------- Validate Tags --------------------------- #
echo "🔍 Validating tags..."
# Ensure tags are lowercase.
if sh ./ensure_lowercase.sh "Tag" $TAGS; then
echo "✅ All tags are lowercase."
else
echo "❌ One or more tags are not lowercase. Please update the tags."
exit 1
fi
# Ensure tags do not contain spaces.
if sh ./ensure_no_spaces.sh "Tag" $TAGS; then
echo "✅ Tags do not contain spaces."
else
echo "❌ One or more tags contain spaces. Please update the tags."
exit 1
fi
# ---------------------------- Validate Image Name --------------------------- #
if [ "$NAME" != "auto" ]; then
echo "🔍 Validating image name..."
# Ensure image name is lowercase.
if sh ./ensure_lowercase.sh "Name" $NAME; then
echo "✅ Image name is lowercase."
else
echo "❌ Image name is not lowercase. Please update the name."
exit 1
fi
# Ensure image name does not contain spaces.
if sh ./ensure_no_spaces.sh "Name" $NAME; then
echo "✅ Image name does not contain spaces."
else
echo "❌ Image name contains spaces. Please update the name."
exit 1
fi
else
echo " Image name is set to auto-detect."
fi
# ---------------------------- Validate Registry URL --------------------------- #
echo "🔍 Validating Registry URL..."
# Ensure Registry URL does not contain spaces.
if sh ./ensure_no_spaces.sh "Registry URL" $REGISTRY_URL; then
echo "✅ Registry URL does not contain spaces."
else
echo "❌ Registry URL contains spaces. Please update the URL."
exit 1
fi
# Ensure Registry URL is lowercase.
if sh ./ensure_lowercase.sh "Registry URL" $REGISTRY_URL; then
echo "✅ Registry URL is lowercase."
else
echo "❌ Registry URL is not lowercase. Please update the URL."
exit 1
fi
# Ensure Registry URL starts with "https://"
if [[ $REGISTRY_URL != https://* ]]; then
echo "❌ Invalid Registry URL: $REGISTRY_URL"
echo " Registry URL must start with 'https://'"
exit 1
fi
echo "✅ Registry URL starts with 'https://'"
# Check if Registry URL is reachable.
echo "🔍 Checking if Registry URL is reachable..."
if curl -s --head "$REGISTRY_URL" | head -n 1 | grep "HTTP/[12]\.[0-9] [23].." >/dev/null; then
echo "✅ Registry URL is reachable: $REGISTRY_URL"
else
echo "❌ Registry URL is not reachable: $REGISTRY_URL"
echo " Please verify the URL and check your network connection."
exit 1
fi
echo "============================================"
echo "All validations passed successfully!"
echo "============================================"