Skip to content

Commit 1cb1726

Browse files
committed
temp github action
1 parent d2bba3c commit 1cb1726

File tree

1 file changed

+111
-0
lines changed

1 file changed

+111
-0
lines changed

.github/workflows/pr-jmx-agent.yml

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
name: PR JMX Agent Build
2+
3+
on:
4+
pull_request:
5+
types: [opened, synchronize, reopened]
6+
7+
concurrency:
8+
group: ${{ github.workflow }}-${{ github.ref }}
9+
cancel-in-progress: true
10+
11+
env:
12+
# GitHub Container Registry
13+
GHCR_REGISTRY: ghcr.io
14+
# github.repository as <account>/<repo>
15+
GHCR_JMX_IMAGE_NAME: ${{ github.repository }}/jmx-javaagent
16+
17+
jobs:
18+
build-and-push-jmx-agent-image:
19+
name: Build and push JMX agent image
20+
runs-on: ubuntu-latest
21+
permissions:
22+
contents: read
23+
packages: write
24+
steps:
25+
- name: Checkout code
26+
uses: actions/checkout@v5
27+
28+
- name: Set up QEMU
29+
uses: docker/setup-qemu-action@v3
30+
31+
- name: Set up Docker Buildx
32+
uses: docker/setup-buildx-action@v3
33+
34+
- name: Extract JMX exporter version from Dockerfile
35+
id: jmx_exporter_version
36+
run: |
37+
JMX_VERSION=$(grep "ARG JMX_EXPORTER_VERSION=" docker/jmx_exporter/Dockerfile | cut -d'=' -f2 | cut -d' ' -f1)
38+
echo "jmx_version=$JMX_VERSION" >> $GITHUB_OUTPUT
39+
echo "JMX Exporter version: $JMX_VERSION"
40+
41+
- name: Log into GitHub Container Registry ${{ env.GHCR_REGISTRY }}
42+
uses: docker/login-action@v3
43+
with:
44+
registry: ${{ env.GHCR_REGISTRY }}
45+
username: ${{ github.actor }}
46+
password: ${{ secrets.GITHUB_TOKEN }}
47+
48+
- name: Delete existing package if it exists
49+
continue-on-error: true
50+
run: |
51+
PACKAGE_NAME="${{ github.repository }}/jmx-javaagent"
52+
VERSION_TAG="${{ steps.jmx_exporter_version.outputs.jmx_version }}"
53+
54+
echo "Checking for existing package: $PACKAGE_NAME with version: $VERSION_TAG"
55+
56+
# URL encode the package name for API calls
57+
ENCODED_PACKAGE_NAME=$(echo "$PACKAGE_NAME" | sed 's/\//%2F/g')
58+
59+
# Check if package version exists using GitHub API
60+
RESPONSE=$(curl -s -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
61+
-H "Accept: application/vnd.github.v3+json" \
62+
"https://api.github.com/user/packages/container/$ENCODED_PACKAGE_NAME/versions" 2>/dev/null || echo "[]")
63+
64+
# Extract version ID for the specific tag
65+
VERSION_ID=$(echo "$RESPONSE" | jq -r --arg tag "$VERSION_TAG" '.[] | select(.metadata.container.tags[]? == $tag) | .id' 2>/dev/null || echo "")
66+
67+
if [ -n "$VERSION_ID" ] && [ "$VERSION_ID" != "null" ] && [ "$VERSION_ID" != "" ]; then
68+
echo "Found existing package version with ID: $VERSION_ID"
69+
echo "Deleting existing package version..."
70+
71+
DELETE_RESPONSE=$(curl -s -X DELETE \
72+
-H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
73+
-H "Accept: application/vnd.github.v3+json" \
74+
"https://api.github.com/user/packages/container/$ENCODED_PACKAGE_NAME/versions/$VERSION_ID")
75+
76+
if [ $? -eq 0 ]; then
77+
echo "Successfully deleted existing package version"
78+
else
79+
echo "Failed to delete existing package version, but continuing..."
80+
fi
81+
else
82+
echo "No existing package version found for tag: $VERSION_TAG"
83+
fi
84+
85+
- name: Extract Docker metadata for JMX exporter
86+
id: meta
87+
uses: docker/metadata-action@v5
88+
with:
89+
images: |
90+
${{ env.GHCR_REGISTRY }}/${{ env.GHCR_JMX_IMAGE_NAME }}
91+
tags: |
92+
type=raw,value=${{ steps.jmx_exporter_version.outputs.jmx_version }}
93+
type=raw,value=pr-${{ github.event.number }}
94+
labels: |
95+
org.opencontainers.image.description=Prometheus JMX Exporter for Kafka monitoring (PR build)
96+
97+
- name: Build and push JMX exporter image
98+
uses: docker/build-push-action@v6
99+
with:
100+
context: docker/jmx_exporter
101+
platforms: linux/amd64,linux/arm64
102+
push: true
103+
tags: ${{ steps.meta.outputs.tags }}
104+
labels: ${{ steps.meta.outputs.labels }}
105+
annotations: ${{ steps.meta.outputs.annotations }}
106+
107+
- name: Output image information
108+
run: |
109+
echo "Built and pushed JMX agent image with tags:"
110+
echo "${{ steps.meta.outputs.tags }}"
111+
echo "Image digest: ${{ steps.build.outputs.digest }}"

0 commit comments

Comments
 (0)