Build and Publish Docker Images #1
This file contains 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
name: Build and Publish Docker Images | |
on: | |
workflow_dispatch: | |
inputs: | |
git_tag: | |
description: "Tag to build Docker images from" | |
required: true | |
default: "0.4.17" | |
permissions: | |
contents: read | |
packages: write | |
jobs: | |
docker-build-and-push: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Login to GitHub Container Registry | |
uses: docker/login-action@v3 | |
with: | |
registry: ghcr.io | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
# Step 1: Check out the repository | |
- name: Check out the repository | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
# Step 2: Set up JDK | |
- name: Set up JDK | |
uses: actions/setup-java@v4 | |
with: | |
java-version: "17" | |
distribution: "temurin" | |
cache: "gradle" | |
# Step 3: Fetch all branches and tags | |
- name: Fetch all branches and tags | |
run: | | |
git remote set-head origin --auto | |
git remote add upstream https://github.com/linkedin/venice | |
git fetch upstream | |
git fetch --tags | |
# Step 4: Validate and check out the tag | |
- name: Check out tag and validate | |
id: validate_tag | |
run: | | |
TAG="${{ github.event.inputs.git_tag }}" | |
if ! git rev-parse "refs/tags/$TAG" >/dev/null 2>&1; then | |
echo "Error: Tag '$TAG' does not exist." | |
# Emit an annotation warning that the tag was not valid | |
echo "::error title=Tag Validation Failed::The specified git tag '$TAG' does not exist in the repository." | |
exit 1 | |
fi | |
# Check out the specified tag | |
git checkout "tags/$TAG" | |
# Get latest commit information | |
COMMIT_SHA=$(git rev-parse HEAD) | |
COMMIT_MSG=$(git log -1 --pretty=%B) | |
COMMIT_DATE=$(git log -1 --pretty=%cd --date=format:"%Y-%m-%d %H:%M:%S") | |
echo "Latest commit SHA: $COMMIT_SHA" | |
echo "Latest commit date: $COMMIT_DATE" | |
# Set outputs | |
echo "commit_sha=$COMMIT_SHA" >> $GITHUB_OUTPUT | |
echo "commit_date=$COMMIT_DATE" >> $GITHUB_OUTPUT | |
# Step 5: Run Docker image build and push script | |
- name: Build Docker images | |
env: | |
TAG_VERSION: ${{ github.event.inputs.git_tag }} | |
run: | | |
# Pass the tag as the version | |
bash docker/build-venice-docker-images.sh "ghcr.io/${{ github.repository }}" "$TAG_VERSION" | |
# Step 6: List generated Docker images | |
- name: List generated Docker images | |
run: | | |
echo "Listing all Docker images:" | |
docker images | |
# Step 7: Verify that images were created | |
- name: Verify Docker images were created | |
run: | | |
TAG_VERSION="${{ github.event.inputs.git_tag }}" | |
TARGETS=("venice-controller" "venice-server" "venice-router" "venice-client") | |
for target in "${TARGETS[@]}"; do | |
IMAGE_NAME="ghcr.io/${{ github.repository }}/$target:$TAG_VERSION" | |
if ! docker inspect "$IMAGE_NAME" >/dev/null 2>&1; then | |
echo "Error: Docker image $IMAGE_NAME was not created." | |
exit 1 | |
else | |
echo "Docker image $IMAGE_NAME exists." | |
fi | |
done | |
# Step 8: Publish Docker images to repo's GHCR | |
- name: Push Docker images to repo's GHCR | |
id: publish_images | |
run: | | |
targets=("venice-controller" "venice-server" "venice-router" "venice-client") | |
TAG_VERSION="${{ github.event.inputs.git_tag }}" | |
TAG_VERSION=$(echo "$TAG_VERSION" | tr -d '[:space:]' | tr '[:upper:]' '[:lower:]') # Sanitize tag | |
IMAGE_URLS="" | |
for target in "${targets[@]}"; do | |
IMAGE_NAME="ghcr.io/${{ github.repository }}/$target:$TAG_VERSION" | |
echo "Pushing image: $IMAGE_NAME" | |
docker push "$IMAGE_NAME" | |
# Append URL to list with clickable full URL | |
IMAGE_URLS+="- $target - [$IMAGE_NAME](https://$IMAGE_NAME)\n" | |
done | |
# Save IMAGE_URLS to GITHUB_OUTPUT for later use in the workflow | |
echo -e "image_urls<<EOF\n$IMAGE_URLS\nEOF" >> $GITHUB_OUTPUT | |
- name: Display clickable image URLs | |
run: | | |
echo "## Published Docker Images" | |
echo -e "${{ steps.publish_images.outputs.image_urls }}" | |
# Step 9: Annotate workflow with Docker image metadata | |
- name: Annotate workflow with Docker image metadata | |
if: success() | |
run: | | |
# Capture the current date and time for the published date | |
PUBLISHED_DATE=$(date +"%Y-%m-%d %H:%M:%S") | |
echo "**Docker Images Published:** ✅" >> $GITHUB_STEP_SUMMARY | |
echo "**Published Date:** $PUBLISHED_DATE" >> $GITHUB_STEP_SUMMARY | |
echo "**Git Tag Used:** ${{ github.event.inputs.git_tag }}" >> $GITHUB_STEP_SUMMARY | |
echo "**Latest Commit SHA:** ${{ steps.validate_tag.outputs.commit_sha }}" >> $GITHUB_STEP_SUMMARY | |
echo "**Latest Commit Date:** ${{ steps.validate_tag.outputs.commit_date }}" >> $GITHUB_STEP_SUMMARY | |
echo "**Docker Image URLs:**" >> $GITHUB_STEP_SUMMARY | |
echo -e "${{ steps.publish_images.outputs.image_urls }}" >> $GITHUB_STEP_SUMMARY |