Skip to content

Commit ad62a97

Browse files
Added workflow to publish to dockerhub (#41)
* Added workflow to publish to dockerhub from master * Enabled multiple entrypoints on docker
1 parent 8c0f829 commit ad62a97

File tree

3 files changed

+307
-4
lines changed

3 files changed

+307
-4
lines changed
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
name: Docker Publish - Latest
2+
3+
on:
4+
push:
5+
branches: [master]
6+
paths-ignore:
7+
- '**.md'
8+
- 'docs/**'
9+
10+
env:
11+
REGISTRY: docker.io
12+
IMAGE_NAME: redis/redis-benchmark-go
13+
14+
jobs:
15+
docker-publish:
16+
runs-on: ubuntu-latest
17+
permissions:
18+
contents: read
19+
packages: write
20+
21+
steps:
22+
- name: Checkout repository
23+
uses: actions/checkout@v4
24+
with:
25+
fetch-depth: 0 # Fetch full history for Git info
26+
27+
- name: Set up Docker Buildx
28+
uses: docker/setup-buildx-action@v3
29+
30+
- name: Check Docker Hub credentials
31+
run: |
32+
if [[ -z "${{ secrets.DOCKER_USERNAME }}" || -z "${{ secrets.DOCKER_PASSWORD }}" ]]; then
33+
echo "❌ Docker Hub credentials not configured!"
34+
echo "Please set DOCKER_USERNAME and DOCKER_PASSWORD secrets in repository settings."
35+
exit 1
36+
fi
37+
echo "✅ Docker Hub credentials are configured"
38+
39+
- name: Log in to Docker Hub
40+
uses: docker/login-action@v3
41+
with:
42+
registry: ${{ env.REGISTRY }}
43+
username: ${{ secrets.DOCKER_USERNAME }}
44+
password: ${{ secrets.DOCKER_PASSWORD }}
45+
46+
- name: Extract Git metadata
47+
id: meta
48+
run: |
49+
GIT_SHA=$(git rev-parse HEAD)
50+
GIT_DIRTY=$(git diff --no-ext-diff 2>/dev/null | wc -l)
51+
echo "git_sha=${GIT_SHA}" >> $GITHUB_OUTPUT
52+
echo "git_dirty=${GIT_DIRTY}" >> $GITHUB_OUTPUT
53+
echo "short_sha=${GIT_SHA:0:7}" >> $GITHUB_OUTPUT
54+
55+
- name: Extract metadata for Docker
56+
id: docker_meta
57+
uses: docker/metadata-action@v5
58+
with:
59+
images: ${{ env.IMAGE_NAME }}
60+
tags: |
61+
type=raw,value=latest
62+
63+
- name: Build and push Docker image
64+
uses: docker/build-push-action@v5
65+
with:
66+
context: .
67+
platforms: linux/amd64,linux/arm64
68+
push: true
69+
tags: ${{ steps.docker_meta.outputs.tags }}
70+
labels: ${{ steps.docker_meta.outputs.labels }}
71+
build-args: |
72+
GIT_SHA=${{ steps.meta.outputs.git_sha }}
73+
GIT_DIRTY=${{ steps.meta.outputs.git_dirty }}
74+
cache-from: type=gha
75+
cache-to: type=gha,mode=max
76+
77+
- name: Generate summary
78+
run: |
79+
echo "## 🐳 Docker Image Published" >> $GITHUB_STEP_SUMMARY
80+
echo "" >> $GITHUB_STEP_SUMMARY
81+
echo "**Repository:** \`${{ env.IMAGE_NAME }}\`" >> $GITHUB_STEP_SUMMARY
82+
echo "**Tags:**" >> $GITHUB_STEP_SUMMARY
83+
echo "\`\`\`" >> $GITHUB_STEP_SUMMARY
84+
echo "${{ steps.docker_meta.outputs.tags }}" >> $GITHUB_STEP_SUMMARY
85+
echo "\`\`\`" >> $GITHUB_STEP_SUMMARY
86+
echo "" >> $GITHUB_STEP_SUMMARY
87+
echo "**Git SHA:** \`${{ steps.meta.outputs.git_sha }}\`" >> $GITHUB_STEP_SUMMARY
88+
echo "" >> $GITHUB_STEP_SUMMARY
89+
echo "**Usage:**" >> $GITHUB_STEP_SUMMARY
90+
echo "\`\`\`bash" >> $GITHUB_STEP_SUMMARY
91+
echo "docker run --rm ${{ env.IMAGE_NAME }}:latest run.py --help" >> $GITHUB_STEP_SUMMARY
92+
echo "\`\`\`" >> $GITHUB_STEP_SUMMARY
93+
echo "" >> $GITHUB_STEP_SUMMARY
94+
echo "🔗 [View on Docker Hub](https://hub.docker.com/r/redis/vector-db-benchmark)" >> $GITHUB_STEP_SUMMARY

Dockerfile

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,32 @@ COPY . /
33
WORKDIR /
44
RUN make
55

6-
FROM ubuntu:24.10
6+
FROM ubuntu:22.04
77
LABEL Description="redis-benchmark-go"
8-
COPY --from=builder /redis-benchmark-go /usr/local/bin
98

10-
ENTRYPOINT ["redis-benchmark-go"]
11-
CMD [ "--help" ]
9+
# Install basic utilities that might be needed
10+
RUN apt-get update && apt-get install -y \
11+
ca-certificates \
12+
curl \
13+
bash \
14+
&& rm -rf /var/lib/apt/lists/*
15+
16+
COPY --from=builder /redis-benchmark-go /usr/local/bin/redis-benchmark-go
17+
18+
# Create a flexible entrypoint script
19+
RUN echo '#!/bin/bash\n\
20+
# Flexible entrypoint script\n\
21+
if [ "$1" = "/bin/bash" ] || [ "$1" = "bash" ] || [ "$1" = "/bin/sh" ] || [ "$1" = "sh" ]; then\n\
22+
# If the first argument is a shell, execute it directly\n\
23+
exec "$@"\n\
24+
elif [ "$#" -eq 0 ] || [ "$1" = "--help" ]; then\n\
25+
# Default behavior - run redis-benchmark-go with help\n\
26+
exec redis-benchmark-go --help\n\
27+
else\n\
28+
# Otherwise, assume arguments are for redis-benchmark-go\n\
29+
exec redis-benchmark-go "$@"\n\
30+
fi' > /usr/local/bin/entrypoint.sh && \
31+
chmod +x /usr/local/bin/entrypoint.sh
32+
33+
ENTRYPOINT ["/usr/local/bin/entrypoint.sh"]
34+
CMD ["--help"]

docker-build.sh

Lines changed: 186 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,186 @@
1+
#!/bin/bash
2+
3+
# Docker build script for redis-benchmark-go
4+
# This script builds the Docker image with proper Git information
5+
6+
set -e
7+
8+
# Default values
9+
IMAGE_NAME="redis/redis-benchmark-go"
10+
TAG="latest"
11+
PLATFORM=""
12+
PUSH=false
13+
14+
# Colors for output
15+
RED='\033[0;31m'
16+
GREEN='\033[0;32m'
17+
YELLOW='\033[1;33m'
18+
NC='\033[0m' # No Color
19+
20+
# Function to print colored output
21+
print_info() {
22+
echo -e "${GREEN}[INFO]${NC} $1"
23+
}
24+
25+
print_warning() {
26+
echo -e "${YELLOW}[WARNING]${NC} $1"
27+
}
28+
29+
print_error() {
30+
echo -e "${RED}[ERROR]${NC} $1"
31+
}
32+
33+
# Function to show usage
34+
usage() {
35+
echo "Usage: $0 [OPTIONS]"
36+
echo ""
37+
echo "Options:"
38+
echo " -n, --name NAME Docker image name (default: redis/redis-benchmark-go)"
39+
echo " -t, --tag TAG Docker image tag (default: latest)"
40+
echo " -p, --platform PLATFORM Target platform (e.g., linux/amd64,linux/arm64)"
41+
echo " --push Push image to Docker Hub after building"
42+
echo " -h, --help Show this help message"
43+
echo ""
44+
echo "Examples:"
45+
echo " $0 # Build with defaults (latest tag)"
46+
echo " $0 -t v1.0.0 --push # Build and push version tag"
47+
echo " $0 -p linux/amd64,linux/arm64 --push # Multi-platform build and push"
48+
echo ""
49+
echo "Docker Hub Repository: redis/redis-benchmark-go"
50+
}
51+
52+
# Parse command line arguments
53+
while [[ $# -gt 0 ]]; do
54+
case $1 in
55+
-n|--name)
56+
IMAGE_NAME="$2"
57+
shift 2
58+
;;
59+
-t|--tag)
60+
TAG="$2"
61+
shift 2
62+
;;
63+
-p|--platform)
64+
PLATFORM="$2"
65+
shift 2
66+
;;
67+
--push)
68+
PUSH=true
69+
shift
70+
;;
71+
-h|--help)
72+
usage
73+
exit 0
74+
;;
75+
*)
76+
print_error "Unknown option: $1"
77+
usage
78+
exit 1
79+
;;
80+
esac
81+
done
82+
83+
# Prepare for build
84+
print_info "Preparing Docker build..."
85+
86+
# Build Docker image
87+
FULL_IMAGE_NAME="${IMAGE_NAME}:${TAG}"
88+
print_info "Building Docker image: $FULL_IMAGE_NAME"
89+
90+
# Prepare build command
91+
if [[ -n "$PLATFORM" ]]; then
92+
# Multi-platform build requires buildx
93+
print_info "Target platform(s): $PLATFORM"
94+
print_info "Setting up Docker Buildx for multi-platform build..."
95+
96+
# Create buildx builder if it doesn't exist
97+
if ! docker buildx ls | grep -q "multiplatform"; then
98+
print_info "Creating multiplatform builder..."
99+
docker buildx create --name multiplatform --use --bootstrap
100+
else
101+
print_info "Using existing multiplatform builder..."
102+
docker buildx use multiplatform
103+
fi
104+
105+
BUILD_CMD="docker buildx build --platform $PLATFORM"
106+
if [[ "$PUSH" == "true" ]]; then
107+
BUILD_CMD="$BUILD_CMD --push"
108+
else
109+
BUILD_CMD="$BUILD_CMD --load"
110+
print_warning "Multi-platform builds without --push will only load the native platform image"
111+
fi
112+
else
113+
# Single platform build uses regular docker build
114+
BUILD_CMD="docker build"
115+
fi
116+
117+
# Get Git information for build args
118+
GIT_SHA=$(git rev-parse HEAD 2>/dev/null || echo "unknown")
119+
GIT_DIRTY=$(git diff --no-ext-diff 2>/dev/null | wc -l || echo "0")
120+
121+
print_info "Git SHA: $GIT_SHA"
122+
print_info "Git dirty files: $GIT_DIRTY"
123+
124+
# Add build args and tags
125+
BUILD_CMD="$BUILD_CMD --build-arg GIT_SHA=$GIT_SHA --build-arg GIT_DIRTY=$GIT_DIRTY -t $FULL_IMAGE_NAME ."
126+
127+
print_info "Executing: $BUILD_CMD"
128+
129+
# Execute build
130+
if eval $BUILD_CMD; then
131+
print_info "✅ Docker image built successfully: $FULL_IMAGE_NAME"
132+
133+
# Show image size (only for single platform builds or when image is loaded locally)
134+
if [[ -z "$PLATFORM" ]] || [[ "$PUSH" != "true" ]]; then
135+
IMAGE_SIZE=$(docker images --format "table {{.Size}}" $FULL_IMAGE_NAME 2>/dev/null | tail -n 1)
136+
if [[ -n "$IMAGE_SIZE" && "$IMAGE_SIZE" != "SIZE" ]]; then
137+
print_info "Image size: $IMAGE_SIZE"
138+
fi
139+
fi
140+
141+
# Handle push for single platform builds (multi-platform builds push automatically with buildx)
142+
if [[ "$PUSH" == "true" && -z "$PLATFORM" ]]; then
143+
print_info "🚀 Pushing image to Docker Hub..."
144+
145+
# Check if logged in to Docker Hub
146+
if ! docker info | grep -q "Username:"; then
147+
print_warning "Not logged in to Docker Hub. Please run: docker login"
148+
print_info "Or set DOCKER_USERNAME and DOCKER_PASSWORD environment variables"
149+
150+
if [[ -n "$DOCKER_USERNAME" && -n "$DOCKER_PASSWORD" ]]; then
151+
print_info "Using environment variables for Docker login..."
152+
echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin
153+
else
154+
print_error "❌ Docker Hub authentication required"
155+
exit 1
156+
fi
157+
fi
158+
159+
# Push the image
160+
if docker push $FULL_IMAGE_NAME; then
161+
print_info "✅ Image pushed successfully to Docker Hub: $FULL_IMAGE_NAME"
162+
else
163+
print_error "❌ Failed to push image to Docker Hub"
164+
exit 1
165+
fi
166+
elif [[ "$PUSH" == "true" && -n "$PLATFORM" ]]; then
167+
print_info "✅ Multi-platform image pushed successfully to Docker Hub: $FULL_IMAGE_NAME"
168+
fi
169+
170+
echo ""
171+
print_info "To run the container:"
172+
echo " docker run --rm $FULL_IMAGE_NAME --help"
173+
echo ""
174+
print_info "To run with Redis connection:"
175+
echo " docker run --rm --network=host $FULL_IMAGE_NAME -h localhost -c 50 -n 100000"
176+
echo ""
177+
print_info "To run with custom Redis server:"
178+
echo " docker run --rm $FULL_IMAGE_NAME -h redis-server -p 6379 -c 100 -n 1000000"
179+
echo ""
180+
if [[ "$PUSH" == "true" ]]; then
181+
print_info "Image available on Docker Hub: https://hub.docker.com/r/redis/redis-benchmark-go"
182+
fi
183+
else
184+
print_error "❌ Docker build failed"
185+
exit 1
186+
fi

0 commit comments

Comments
 (0)