#!/bin/bash # Docker build and push script with error handling set -e # Exit on any error # Configuration ImageName="abdanhafidz/runpod-rag-backend" Tag="v1.0.2" Dockerfile="Dockerfile.runpod" # Colors for output RED='\033[0;31m' GREEN='\033[0;32m' YELLOW='\033[1;33m' NC='\033[0m' # No Color # Function to print colored output print_status() { echo -e "${GREEN}[INFO]${NC} $1" } print_warning() { echo -e "${YELLOW}[WARNING]${NC} $1" } print_error() { echo -e "${RED}[ERROR]${NC} $1" } # Check if Docker is running if ! docker info > /dev/null 2>&1; then print_error "Docker is not running. Please start Docker first." exit 1 fi # Check if Dockerfile exists if [ ! -f "$Dockerfile" ]; then print_error "Dockerfile '$Dockerfile' not found!" exit 1 fi print_status "Starting Docker build and push process..." print_status "Image: ${ImageName}:${Tag}" print_status "Dockerfile: ${Dockerfile}" # Build image print_status "Building Image..." if docker build --platform linux/amd64 -f "$Dockerfile" -t "${ImageName}:${Tag}" .; then print_status "Build Finished Successfully!" else print_error "Build Failed!" exit 1 fi # Ask user if they want to test locally read -p "Do you want to test the image locally? (y/N): " -n 1 -r echo if [[ $REPLY =~ ^[Yy]$ ]]; then print_status "Testing image locally..." print_warning "Press Ctrl+C to stop the container when done testing" docker run --rm -p 7860:7860 "${ImageName}:${Tag}" fi # Ask user if they want to push read -p "Do you want to push the image to Docker Hub? (y/N): " -n 1 -r echo if [[ $REPLY =~ ^[Yy]$ ]]; then print_status "Pushing image to Docker Hub..." if docker push "${ImageName}:${Tag}"; then print_status "🎉 Push Successful!" else print_error "Push Failed! Make sure you're logged in to Docker Hub." exit 1 fi else print_status "Skipping push to Docker Hub." fi print_status "🎉 Selesai!"