#!/bin/bash # Configuration (Based on Jenkinsfile) DOCKER_HUB_USERNAME="aimodocker" IMAGE_NAME="i-rcfa" TIMESTAMP=$(date +%Y%m%d%H%M%S) TAG=${1:-"latest"} FULL_IMAGE_NAME="${DOCKER_HUB_USERNAME}/${IMAGE_NAME}" # Enable Docker BuildKit for faster builds and cache mounts export DOCKER_BUILDKIT=1 echo "--------------------------------------------------------" echo "🚀 Starting Local Docker Build for ${FULL_IMAGE_NAME}:${TAG}" echo "--------------------------------------------------------" # Optional: Pull latest for caching (only if internet is fast) echo "đŸ“Ĩ Attempting to pull latest image for caching..." docker pull "${FULL_IMAGE_NAME}:latest" || echo "âš ī¸ Warning: Could not pull latest image, proceeding with local cache only." # Run the Build echo "đŸ—ī¸ Building image..." docker build \ --build-arg BUILDKIT_INLINE_CACHE=1 \ --cache-from "${FULL_IMAGE_NAME}:latest" \ -t "${FULL_IMAGE_NAME}:${TAG}" \ -t "${FULL_IMAGE_NAME}:${TIMESTAMP}" \ . if [ $? -eq 0 ]; then echo "✅ Build Successful!" # Ask if user wants to push read -p "❓ Do you want to push this image to Docker Hub? (y/n): " confirm_push if [[ $confirm_push == [yY] || $confirm_push == [yY][eE][sS] ]]; then echo "âŦ†ī¸ Pushing images..." docker push "${FULL_IMAGE_NAME}:${TAG}" docker push "${FULL_IMAGE_NAME}:${TIMESTAMP}" echo "✅ Push completed successfully!" else echo "â„šī¸ Push cancelled by user." fi else echo "❌ Build Failed!" exit 1 fi echo "--------------------------------------------------------" echo "✨ Done! Image built as ${FULL_IMAGE_NAME}:${TAG}" echo "--------------------------------------------------------"