File size: 1,960 Bytes
7ae0310
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#!/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!"