forked from qdrant/vector-db-benchmark
-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathdocker-build.sh
More file actions
executable file
·176 lines (153 loc) · 5.31 KB
/
docker-build.sh
File metadata and controls
executable file
·176 lines (153 loc) · 5.31 KB
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
#!/bin/bash
# Docker build script for vector-db-benchmark
# This script builds the Docker image with proper Git information
set -e
# Default values
IMAGE_NAME="redis/vector-db-benchmark"
TAG="latest"
PLATFORM=""
PUSH=false
# 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_info() {
echo -e "${GREEN}[INFO]${NC} $1"
}
print_warning() {
echo -e "${YELLOW}[WARNING]${NC} $1"
}
print_error() {
echo -e "${RED}[ERROR]${NC} $1"
}
# Function to show usage
usage() {
echo "Usage: $0 [OPTIONS]"
echo ""
echo "Options:"
echo " -n, --name NAME Docker image name (default: redis/vector-db-benchmark)"
echo " -t, --tag TAG Docker image tag (default: latest)"
echo " -p, --platform PLATFORM Target platform (e.g., linux/amd64,linux/arm64)"
echo " --push Push image to Docker Hub after building"
echo " -h, --help Show this help message"
echo ""
echo "Examples:"
echo " $0 # Build with defaults (latest tag)"
echo " $0 -t v1.0.0 --push # Build and push version tag"
echo " $0 -p linux/amd64,linux/arm64 --push # Multi-platform build and push"
echo ""
echo "Docker Hub Repository: redis/vector-db-benchmark"
}
# Parse command line arguments
while [[ $# -gt 0 ]]; do
case $1 in
-n|--name)
IMAGE_NAME="$2"
shift 2
;;
-t|--tag)
TAG="$2"
shift 2
;;
-p|--platform)
PLATFORM="$2"
shift 2
;;
--push)
PUSH=true
shift
;;
-h|--help)
usage
exit 0
;;
*)
print_error "Unknown option: $1"
usage
exit 1
;;
esac
done
# Prepare for build
print_info "Preparing Docker build..."
# Build Docker image
FULL_IMAGE_NAME="${IMAGE_NAME}:${TAG}"
print_info "Building Docker image: $FULL_IMAGE_NAME"
# Prepare build command
if [[ -n "$PLATFORM" ]]; then
# Multi-platform build requires buildx
print_info "Target platform(s): $PLATFORM"
print_info "Setting up Docker Buildx for multi-platform build..."
# Create buildx builder if it doesn't exist
if ! docker buildx ls | grep -q "multiplatform"; then
print_info "Creating multiplatform builder..."
docker buildx create --name multiplatform --use --bootstrap
else
print_info "Using existing multiplatform builder..."
docker buildx use multiplatform
fi
BUILD_CMD="docker buildx build --platform $PLATFORM"
if [[ "$PUSH" == "true" ]]; then
BUILD_CMD="$BUILD_CMD --push"
else
BUILD_CMD="$BUILD_CMD --load"
print_warning "Multi-platform builds without --push will only load the native platform image"
fi
else
# Single platform build uses regular docker build
BUILD_CMD="docker build"
fi
# Add tags
BUILD_CMD="$BUILD_CMD -t $FULL_IMAGE_NAME ."
print_info "Executing: $BUILD_CMD"
# Execute build
if eval $BUILD_CMD; then
print_info "✅ Docker image built successfully: $FULL_IMAGE_NAME"
# Show image size (only for single platform builds or when image is loaded locally)
if [[ -z "$PLATFORM" ]] || [[ "$PUSH" != "true" ]]; then
IMAGE_SIZE=$(docker images --format "table {{.Size}}" $FULL_IMAGE_NAME 2>/dev/null | tail -n 1)
if [[ -n "$IMAGE_SIZE" && "$IMAGE_SIZE" != "SIZE" ]]; then
print_info "Image size: $IMAGE_SIZE"
fi
fi
# Handle push for single platform builds (multi-platform builds push automatically with buildx)
if [[ "$PUSH" == "true" && -z "$PLATFORM" ]]; then
print_info "🚀 Pushing image to Docker Hub..."
# Check if logged in to Docker Hub
if ! docker info | grep -q "Username:"; then
print_warning "Not logged in to Docker Hub. Please run: docker login"
print_info "Or set DOCKER_USERNAME and DOCKER_PASSWORD environment variables"
if [[ -n "$DOCKER_USERNAME" && -n "$DOCKER_PASSWORD" ]]; then
print_info "Using environment variables for Docker login..."
echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin
else
print_error "❌ Docker Hub authentication required"
exit 1
fi
fi
# Push the image
if docker push $FULL_IMAGE_NAME; then
print_info "✅ Image pushed successfully to Docker Hub: $FULL_IMAGE_NAME"
else
print_error "❌ Failed to push image to Docker Hub"
exit 1
fi
elif [[ "$PUSH" == "true" && -n "$PLATFORM" ]]; then
print_info "✅ Multi-platform image pushed successfully to Docker Hub: $FULL_IMAGE_NAME"
fi
echo ""
print_info "To run the container:"
echo " docker run --rm $FULL_IMAGE_NAME run.py --help"
echo ""
print_info "To run with Redis connection:"
echo " docker run --rm --network=host $FULL_IMAGE_NAME run.py --host localhost --engines redis"
echo ""
if [[ "$PUSH" == "true" ]]; then
print_info "Image available on Docker Hub: https://hub.docker.com/r/redis/vector-db-benchmark"
fi
else
print_error "❌ Docker build failed"
exit 1
fi