Skip to content

Upgrade jmx-exporter to v1.5.0 #1

Upgrade jmx-exporter to v1.5.0

Upgrade jmx-exporter to v1.5.0 #1

Workflow file for this run

name: PR JMX Agent Build
on:
pull_request:
types: [opened, synchronize, reopened]
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
env:
# GitHub Container Registry
GHCR_REGISTRY: ghcr.io
# github.repository as <account>/<repo>
GHCR_JMX_IMAGE_NAME: ${{ github.repository }}/jmx-javaagent
jobs:
build-and-push-jmx-agent-image:
name: Build and push JMX agent image
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Checkout code
uses: actions/checkout@v5
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Extract JMX exporter version from Dockerfile
id: jmx_exporter_version
run: |
JMX_VERSION=$(grep "ARG JMX_EXPORTER_VERSION=" docker/jmx_exporter/Dockerfile | cut -d'=' -f2 | cut -d' ' -f1)
echo "jmx_version=$JMX_VERSION" >> $GITHUB_OUTPUT
echo "JMX Exporter version: $JMX_VERSION"
- name: Log into GitHub Container Registry ${{ env.GHCR_REGISTRY }}
uses: docker/login-action@v3
with:
registry: ${{ env.GHCR_REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Delete existing package if it exists
continue-on-error: true
run: |
PACKAGE_NAME="${{ github.repository }}/jmx-javaagent"
VERSION_TAG="${{ steps.jmx_exporter_version.outputs.jmx_version }}"
echo "Checking for existing package: $PACKAGE_NAME with version: $VERSION_TAG"
# URL encode the package name for API calls
ENCODED_PACKAGE_NAME=$(echo "$PACKAGE_NAME" | sed 's/\//%2F/g')
# Check if package version exists using GitHub API
RESPONSE=$(curl -s -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
-H "Accept: application/vnd.github.v3+json" \
"https://api.github.com/user/packages/container/$ENCODED_PACKAGE_NAME/versions" 2>/dev/null || echo "[]")
# Extract version ID for the specific tag
VERSION_ID=$(echo "$RESPONSE" | jq -r --arg tag "$VERSION_TAG" '.[] | select(.metadata.container.tags[]? == $tag) | .id' 2>/dev/null || echo "")
if [ -n "$VERSION_ID" ] && [ "$VERSION_ID" != "null" ] && [ "$VERSION_ID" != "" ]; then
echo "Found existing package version with ID: $VERSION_ID"
echo "Deleting existing package version..."
DELETE_RESPONSE=$(curl -s -X DELETE \
-H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
-H "Accept: application/vnd.github.v3+json" \
"https://api.github.com/user/packages/container/$ENCODED_PACKAGE_NAME/versions/$VERSION_ID")
if [ $? -eq 0 ]; then
echo "Successfully deleted existing package version"
else
echo "Failed to delete existing package version, but continuing..."
fi
else
echo "No existing package version found for tag: $VERSION_TAG"
fi
- name: Extract Docker metadata for JMX exporter
id: meta
uses: docker/metadata-action@v5
with:
images: |
${{ env.GHCR_REGISTRY }}/${{ env.GHCR_JMX_IMAGE_NAME }}
tags: |
type=raw,value=${{ steps.jmx_exporter_version.outputs.jmx_version }}
type=raw,value=pr-${{ github.event.number }}
labels: |
org.opencontainers.image.description=Prometheus JMX Exporter for Kafka monitoring (PR build)
- name: Build and push JMX exporter image
uses: docker/build-push-action@v6
with:
context: docker/jmx_exporter
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
annotations: ${{ steps.meta.outputs.annotations }}
- name: Output image information
run: |
echo "Built and pushed JMX agent image with tags:"
echo "${{ steps.meta.outputs.tags }}"
echo "Image digest: ${{ steps.build.outputs.digest }}"