diff --git a/action.yml b/action.yml index 06a5012..e67ed2f 100644 --- a/action.yml +++ b/action.yml @@ -28,13 +28,23 @@ inputs: required: true default: ${{ github.repository_owner }} env: - VALID_ARCHITECTURES: 'amd64 arm64' + VALID_ARCHITECTURES: 'amd64,arm64' runs: using: "composite" steps: - name: Set up QEMU uses: docker/setup-qemu-action@v2 + - name: Install Docker + id: install-docker-quick + shell: bash + run: | + echo "🐋 Installing Docker..." + curl -fsSL https://get.docker.com | sh + echo "✅ Docker installed" + docker --version + + - name: Set up Docker Buildx id: setup-buildx uses: docker/setup-buildx-action@v3 diff --git a/scripts/ensure_lowercase.sh b/scripts/ensure_lowercase.sh index 92aec5b..222b2c1 100644 --- a/scripts/ensure_lowercase.sh +++ b/scripts/ensure_lowercase.sh @@ -4,15 +4,16 @@ # reserve first argument for the environment variable name ENV_VAR_NAME=$1 +# Check if the environment variable is lowercase for var in "${@:2}"; do # get the value of the specified environment variable value=$(eval echo \$$var) - # check if the value is not lowercase - if [[ $value =~ [A-Z] ]]; then + # check if the value is lowercase + if [[ "$value" != "${value,,}" ]]; then echo "❌ Invalid $ENV_VAR_NAME: $value" echo "â„šī¸ $ENV_VAR_NAME must be lowercase" exit 1 else - echo "✅ $ENV_VAR_NAME is lowercase: $value" + echo "✅ $ENV_VAR_NAME is valid: $value" fi -done +done \ No newline at end of file diff --git a/scripts/validate_input.sh b/scripts/validate_input.sh index cae2187..faaaa8e 100644 --- a/scripts/validate_input.sh +++ b/scripts/validate_input.sh @@ -11,95 +11,49 @@ 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 $ARCHITECTURES; do - echo "→ Checking architecture: $arch" - if [[ $VALID_ARCHITECTURES != *"$arch"* ]]; then - echo "❌ Invalid architecture detected: $arch" - echo "â„šī¸ Allowed architectures are: $VALID_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." - -# ---------------------------- 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 "============================================"