-
Notifications
You must be signed in to change notification settings - Fork 3
Added workflow to publish to dockerhub #41
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,94 @@ | ||
| name: Docker Publish - Latest | ||
|
|
||
| on: | ||
| push: | ||
| branches: [master] | ||
| paths-ignore: | ||
| - '**.md' | ||
| - 'docs/**' | ||
|
|
||
| env: | ||
| REGISTRY: docker.io | ||
| IMAGE_NAME: redis/redis-benchmark-go | ||
|
|
||
| jobs: | ||
| docker-publish: | ||
| runs-on: ubuntu-latest | ||
| permissions: | ||
| contents: read | ||
| packages: write | ||
|
|
||
| steps: | ||
| - name: Checkout repository | ||
| uses: actions/checkout@v4 | ||
| with: | ||
| fetch-depth: 0 # Fetch full history for Git info | ||
|
|
||
| - name: Set up Docker Buildx | ||
| uses: docker/setup-buildx-action@v3 | ||
|
|
||
| - name: Check Docker Hub credentials | ||
| run: | | ||
| if [[ -z "${{ secrets.DOCKER_USERNAME }}" || -z "${{ secrets.DOCKER_PASSWORD }}" ]]; then | ||
| echo "❌ Docker Hub credentials not configured!" | ||
| echo "Please set DOCKER_USERNAME and DOCKER_PASSWORD secrets in repository settings." | ||
| exit 1 | ||
| fi | ||
| echo "✅ Docker Hub credentials are configured" | ||
|
|
||
| - name: Log in to Docker Hub | ||
| uses: docker/login-action@v3 | ||
| with: | ||
| registry: ${{ env.REGISTRY }} | ||
| username: ${{ secrets.DOCKER_USERNAME }} | ||
| password: ${{ secrets.DOCKER_PASSWORD }} | ||
|
|
||
| - name: Extract Git metadata | ||
| id: meta | ||
| run: | | ||
| GIT_SHA=$(git rev-parse HEAD) | ||
| GIT_DIRTY=$(git diff --no-ext-diff 2>/dev/null | wc -l) | ||
| echo "git_sha=${GIT_SHA}" >> $GITHUB_OUTPUT | ||
| echo "git_dirty=${GIT_DIRTY}" >> $GITHUB_OUTPUT | ||
| echo "short_sha=${GIT_SHA:0:7}" >> $GITHUB_OUTPUT | ||
|
|
||
| - name: Extract metadata for Docker | ||
| id: docker_meta | ||
| uses: docker/metadata-action@v5 | ||
| with: | ||
| images: ${{ env.IMAGE_NAME }} | ||
| tags: | | ||
| type=raw,value=latest | ||
|
|
||
| - name: Build and push Docker image | ||
| uses: docker/build-push-action@v5 | ||
| with: | ||
| context: . | ||
| platforms: linux/amd64,linux/arm64 | ||
| push: true | ||
| tags: ${{ steps.docker_meta.outputs.tags }} | ||
| labels: ${{ steps.docker_meta.outputs.labels }} | ||
| build-args: | | ||
| GIT_SHA=${{ steps.meta.outputs.git_sha }} | ||
| GIT_DIRTY=${{ steps.meta.outputs.git_dirty }} | ||
| cache-from: type=gha | ||
| cache-to: type=gha,mode=max | ||
|
|
||
| - name: Generate summary | ||
| run: | | ||
| echo "## 🐳 Docker Image Published" >> $GITHUB_STEP_SUMMARY | ||
| echo "" >> $GITHUB_STEP_SUMMARY | ||
| echo "**Repository:** \`${{ env.IMAGE_NAME }}\`" >> $GITHUB_STEP_SUMMARY | ||
| echo "**Tags:**" >> $GITHUB_STEP_SUMMARY | ||
| echo "\`\`\`" >> $GITHUB_STEP_SUMMARY | ||
| echo "${{ steps.docker_meta.outputs.tags }}" >> $GITHUB_STEP_SUMMARY | ||
| echo "\`\`\`" >> $GITHUB_STEP_SUMMARY | ||
| echo "" >> $GITHUB_STEP_SUMMARY | ||
| echo "**Git SHA:** \`${{ steps.meta.outputs.git_sha }}\`" >> $GITHUB_STEP_SUMMARY | ||
| echo "" >> $GITHUB_STEP_SUMMARY | ||
| echo "**Usage:**" >> $GITHUB_STEP_SUMMARY | ||
| echo "\`\`\`bash" >> $GITHUB_STEP_SUMMARY | ||
| echo "docker run --rm ${{ env.IMAGE_NAME }}:latest run.py --help" >> $GITHUB_STEP_SUMMARY | ||
| echo "\`\`\`" >> $GITHUB_STEP_SUMMARY | ||
| echo "" >> $GITHUB_STEP_SUMMARY | ||
| echo "🔗 [View on Docker Hub](https://hub.docker.com/r/redis/vector-db-benchmark)" >> $GITHUB_STEP_SUMMARY |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,186 @@ | ||
| #!/bin/bash | ||
|
|
||
| # Docker build script for redis-benchmark-go | ||
| # This script builds the Docker image with proper Git information | ||
|
|
||
| set -e | ||
|
|
||
| # Default values | ||
| IMAGE_NAME="redis/redis-benchmark-go" | ||
| 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/redis-benchmark-go)" | ||
| 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/redis-benchmark-go" | ||
| } | ||
|
|
||
| # 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 | ||
|
|
||
| # Get Git information for build args | ||
| GIT_SHA=$(git rev-parse HEAD 2>/dev/null || echo "unknown") | ||
| GIT_DIRTY=$(git diff --no-ext-diff 2>/dev/null | wc -l || echo "0") | ||
|
|
||
| print_info "Git SHA: $GIT_SHA" | ||
| print_info "Git dirty files: $GIT_DIRTY" | ||
|
|
||
| # Add build args and tags | ||
| BUILD_CMD="$BUILD_CMD --build-arg GIT_SHA=$GIT_SHA --build-arg GIT_DIRTY=$GIT_DIRTY -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 --help" | ||
| echo "" | ||
| print_info "To run with Redis connection:" | ||
| echo " docker run --rm --network=host $FULL_IMAGE_NAME -h localhost -c 50 -n 100000" | ||
| echo "" | ||
| print_info "To run with custom Redis server:" | ||
| echo " docker run --rm $FULL_IMAGE_NAME -h redis-server -p 6379 -c 100 -n 1000000" | ||
| echo "" | ||
| if [[ "$PUSH" == "true" ]]; then | ||
| print_info "Image available on Docker Hub: https://hub.docker.com/r/redis/redis-benchmark-go" | ||
| fi | ||
| else | ||
| print_error "❌ Docker build failed" | ||
| exit 1 | ||
| fi | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.