You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

51 lines
1.7 KiB
Bash

This file contains invisible Unicode characters!

This file contains invisible Unicode characters that may be processed differently from what appears below. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to reveal hidden characters.

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

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