Release NGINX Prometheus Exporter #1
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
name: Release NGINX Prometheus Exporter | |
on: | |
workflow_dispatch: | |
inputs: | |
version: | |
description: 'Release version (e.g. 1.0.0)' | |
required: true | |
dry_run: | |
description: 'Dry run' | |
required: false | |
default: false | |
type: boolean | |
goreleaser_args: | |
description: 'Additional GoReleaser args' | |
required: false | |
default: '' | |
type: string | |
skip_jobs: | |
description: 'Comma-separated list of jobs to skip (e.g. tag,build-docker,generate-assertion-doc)' | |
required: false | |
default: '' | |
type: string | |
env: | |
DOCKER_PLATFORMS: "linux/arm/v5,linux/arm/v6,linux/arm/v7,linux/arm64,linux/amd64,linux/ppc64le,linux/s390x,linux/mips64le,linux/386,linux/riscv64" | |
concurrency: | |
group: ${{ github.ref_name }}-release | |
cancel-in-progress: true | |
permissions: | |
contents: read | |
jobs: | |
variables: | |
name: Setup variables | |
runs-on: ubuntu-24.04 | |
outputs: | |
tag: ${{ steps.vars.outputs.tag }} | |
steps: | |
- name: Checkout Repository | |
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 | |
- name: Set up Go | |
uses: actions/setup-go@44694675825211faa026b3c33043df3e48a5fa00 # v6.0.0 | |
with: | |
go-version: stable | |
- name: Get version | |
id: vars | |
run: echo "tag=${{ github.event.inputs.version }}" >> $GITHUB_OUTPUT | |
tag: | |
if: ${{ !contains(inputs.skip_jobs, 'tag') }} | |
name: Create Tag for release | |
runs-on: ubuntu-24.04 | |
needs: [variables] | |
permissions: | |
contents: write | |
steps: | |
- name: Checkout Repository | |
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 | |
with: | |
fetch-depth: 0 | |
- name: Create new release Tag | |
run: | | |
git config --global user.email "[email protected]" | |
git config --global user.name "NGINX Kubernetes Team" | |
tag="v${{ needs.variables.outputs.tag }}" | |
if ! git rev-parse --verify refs/tags/${tag} 2>/dev/null; then | |
echo "Adding tag ${tag}." | |
git tag -a ${tag} -m "Version ${tag#v*}" | |
echo "Pushing tag ${tag} to main branch" | |
if ! ${{ inputs.dry_run }}; then | |
git push origin "${tag}" | |
else | |
echo "DRY RUN not making any changes" | |
git push --dry-run origin "${tag}" | |
fi | |
else | |
echo "Warning: Tag ${tag} already exists. Not making any changes" | |
fi | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
build-docker: | |
if: ${{ !contains(inputs.skip_jobs, 'build-docker') }} | |
name: Build Docker Image | |
runs-on: ubuntu-24.04-amd64 | |
permissions: | |
contents: write # for lucacome/draft-release to create/update release draft | |
security-events: write # for github/codeql-action/upload-sarif to upload SARIF results | |
id-token: write # for OIDC login to AWS ECR and goreleaser/goreleaser-action to sign artifacts | |
packages: write # for docker/build-push-action to push to GHCR | |
issues: write # for goreleaser/goreleaser-action to close milestones | |
env: | |
GOPROXY: ${{ secrets.ARTIFACTORY_ENDPOINT }} | |
outputs: | |
binaries: ${{ steps.prom_binaries.outputs.json }} | |
needs: [variables] | |
services: | |
registry: | |
image: registry:3 | |
ports: | |
- 5000:5000 | |
steps: | |
- name: Checkout Repository | |
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 | |
with: | |
fetch-depth: 0 | |
- name: Setup Golang Environment | |
uses: actions/setup-go@44694675825211faa026b3c33043df3e48a5fa00 # v6.0.0 | |
with: | |
go-version: stable | |
- name: Setup netrc | |
run: | | |
cat <<EOF > $HOME/.netrc | |
machine azr.artifactory.f5net.com | |
login ${{ secrets.ARTIFACTORY_USER }} | |
password ${{ secrets.ARTIFACTORY_TOKEN }} | |
EOF | |
chmod 600 $HOME/.netrc | |
- name: Setup QEMU | |
uses: docker/setup-qemu-action@29109295f81e9208d7d86ff1c6c12d2833863392 # v3.6.0 | |
- name: Docker Buildx | |
uses: docker/setup-buildx-action@e468171a9de216ec08956ac3ada2f0791b6bd435 # v3.11.1 | |
with: | |
version: latest | |
driver-opts: network=host | |
- name: DockerHub Login | |
uses: docker/login-action@5e57cd118135c172c3672efd75eb46360885c0ef # v3.6.0 | |
with: | |
username: ${{ secrets.DOCKER_USERNAME }} | |
password: ${{ secrets.DOCKER_PASSWORD }} | |
- name: Login to GitHub Container Registry | |
uses: docker/login-action@5e57cd118135c172c3672efd75eb46360885c0ef # v3.6.0 | |
with: | |
registry: ghcr.io | |
username: ${{ github.repository_owner }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Configure AWS Credentials | |
uses: aws-actions/configure-aws-credentials@00943011d9042930efac3dcd3a170e4273319bc8 # v5.1.0 | |
with: | |
aws-region: us-east-1 | |
role-to-assume: ${{ secrets.AWS_ROLE_PUBLIC_ECR }} | |
- name: Login to Public ECR | |
uses: docker/login-action@5e57cd118135c172c3672efd75eb46360885c0ef # v3.6.0 | |
with: | |
registry: public.ecr.aws | |
- name: Login to Quay.io | |
uses: docker/login-action@5e57cd118135c172c3672efd75eb46360885c0ef # v3.6.0 | |
with: | |
registry: quay.io | |
username: ${{ secrets.QUAY_USERNAME }} | |
password: ${{ secrets.QUAY_ROBOT_TOKEN }} | |
- name: Docker meta | |
id: meta | |
uses: docker/metadata-action@c1e51972afc2121e065aed6d45c65596fe445f3f # v5.8.0 | |
with: | |
images: | | |
name=nginx/nginx-prometheus-exporter,enable=true | |
name=ghcr.io/nginx/nginx-prometheus-exporter,enable=true | |
name=public.ecr.aws/nginx/nginx-prometheus-exporter,enable=true | |
name=quay.io/nginx/nginx-prometheus-exporter,enable=true | |
name=localhost:5000/nginx/nginx-prometheus-exporter | |
tags: | | |
type=raw,value=${{ needs.variables.outputs.tag }} | |
labels: | | |
org.opencontainers.image.vendor=NGINX Inc <[email protected]> | |
env: | |
DOCKER_METADATA_ANNOTATIONS_LEVELS: manifest,index | |
- name: Create/Update Draft | |
uses: lucacome/draft-release@fd099feb33710d1fa27b915a08a7acd6a1fb7fd2 # v2.0.0 | |
with: | |
minor-label: "enhancement" | |
major-label: "change" | |
publish: ${{ !github.event.inputs.dry_run }} | |
collapse-after: 30 | |
notes-footer: | | |
## Upgrade | |
- Use the {{version}} image from our [DockerHub](https://hub.docker.com/r/nginx/nginx-prometheus-exporter/tags?page=1&ordering=last_updated&name={{version-number}}), [GitHub Container](https://github.com/nginx/nginx-prometheus-exporter/pkgs/container/nginx-prometheus-exporter), [Amazon ECR Public Gallery](https://gallery.ecr.aws/nginx/nginx-prometheus-exporter) or [Quay.io](https://quay.io/repository/nginx/nginx-prometheus-exporter/tag/{{version-number}}?tab=tags). | |
- Download the latest binaries from the [GitHub releases page](https://github.com/nginx/nginx-prometheus-exporter/releases/tag/{{version}}). | |
- Update to the latest version with `brew upgrade nginx-prometheus-exporter` or `scoop update nginx-prometheus-exporter`. | |
## Compatibility | |
- NGINX 0.1.18 or newer. | |
- NGINX Plus R19 or newer. | |
- name: Download Syft | |
uses: anchore/sbom-action/download-syft@f8bdd1d8ac5e901a77a92f111440fdb1b593736b # v0.20.6 | |
- name: Install Cosign | |
uses: sigstore/cosign-installer@d7543c93d881b35a8faa02e8e3605f69b7a1ce62 # v3.10.0 | |
- name: Install Nix | |
uses: cachix/install-nix-action@9280e7aca88deada44c930f1e2c78e21c3ae3edd # v31 | |
with: | |
github_access_token: ${{ secrets.GITHUB_TOKEN }} | |
- name: Run GoReleaser | |
uses: goreleaser/goreleaser-action@e435ccd777264be153ace6237001ef4d979d3a7a # v6.4.0 | |
with: | |
version: v2.12.5 # renovate: datasource=github-tags depName=goreleaser/goreleaser | |
args: ${{ github.event.inputs.dry_run && 'build --snapshot' || 'release' }} --clean ${{ github.event.inputs.goreleaser_args }} | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
NGINX_GITHUB_TOKEN: ${{ secrets.NGINX_PAT }} | |
- name: Extract NGINX Prometheus Exporter binary info | |
id: prom_binaries | |
run: | | |
curl -sSL https://raw.githubusercontent.com/nginx/k8s-common/main/files/binary-json.sh -o binary-json.sh | |
chmod +x binary-json.sh | |
echo "json=$(./binary-json.sh ${{ github.workspace }}/dist ${{ github.event.repository.name }} "nginx-prometheus-exporter")" >> $GITHUB_OUTPUT | |
- name: Store Artifacts in Cache | |
uses: actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0 | |
with: | |
path: ${{ github.workspace }}/dist | |
key: nginx-prometheus-exporter-${{ github.sha }} | |
- name: Print NGINX Prometheus Exporter info | |
run: ./dist/nginx-prometheus-exporter_linux_amd64_v1/nginx-prometheus-exporter --version | |
continue-on-error: false | |
- name: Build and Push Docker Image | |
uses: docker/build-push-action@263435318d21b8e681c14492fe198d362a7d2c83 # v6.18.0 | |
with: | |
file: build/Dockerfile | |
context: "." | |
target: goreleaser | |
platforms: ${{ env.DOCKER_PLATFORMS }} | |
tags: ${{ steps.meta.outputs.tags }} | |
labels: ${{ steps.meta.outputs.labels }} | |
annotations: ${{ steps.meta.outputs.annotations }} | |
push: ${{ !github.event.inputs.dry_run }} | |
cache-from: type=gha,scope=exporter | |
cache-to: type=gha,scope=exporter,mode=max | |
no-cache: true | |
provenance: mode=max | |
sbom: true | |
- name: Scan image | |
uses: anchore/scan-action@1638637db639e0ade3258b51db49a9a137574c3e # v6.5.1 | |
id: scan | |
continue-on-error: true | |
with: | |
image: localhost:5000/nginx/nginx-prometheus-exporter:${{ steps.meta.outputs.version }} | |
only-fixed: true | |
add-cpes-if-none: true | |
- name: Upload scan result to GitHub Security tab | |
uses: github/codeql-action/upload-sarif@64d10c13136e1c5bce3e5fbde8d4906eeaafc885 # v3.30.6 | |
continue-on-error: true | |
with: | |
sarif_file: ${{ steps.scan.outputs.sarif }} | |
- name: Clean up NETRC | |
run: | | |
rm -f $HOME/.netrc | |
if: ${{ always() }} | |
# generate-assertion-doc: | |
# if: ${{ !contains(inputs.skip_jobs, 'generate-assertion-doc') }} | |
# name: Assertion Doc ${{ matrix.prometheus.os }}/${{ matrix.prometheus.arch }} | |
# needs: [build-docker, variables] | |
# runs-on: ubuntu-24.04-amd64 | |
# permissions: | |
# contents: read | |
# id-token: write # for compliance-rules action to sign assertion doc | |
# strategy: | |
# fail-fast: false | |
# matrix: | |
# prometheus: ${{ fromJSON( needs.build-docker.outputs.binaries ) }} | |
# steps: | |
# - name: Checkout Repository | |
# uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 | |
# - name: Setup Golang Environment | |
# uses: actions/setup-go@44694675825211faa026b3c33043df3e48a5fa00 # v6.0.0 | |
# with: | |
# go-version-file: go.mod | |
# - name: Configure pipeline Variables | |
# id: vars | |
# run: | | |
# timestamp=$(date --iso-8601=seconds) | |
# echo "timestamp=${timestamp}" >> $GITHUB_OUTPUT | |
# cat $GITHUB_OUTPUT | |
# - name: Setup netrc | |
# run: | | |
# cat <<EOF > $HOME/.netrc | |
# machine azr.artifactory.f5net.com | |
# login ${{ secrets.ARTIFACTORY_USER }} | |
# password ${{ secrets.ARTIFACTORY_TOKEN }} | |
# EOF | |
# chmod 600 $HOME/.netrc | |
# - name: Fetch Cached Artifacts | |
# uses: actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0 | |
# with: | |
# path: ${{ github.workspace }}/dist | |
# key: nginx-prometheus-exporter-${{ github.sha }} | |
# fail-on-cache-miss: true | |
# - name: List packages in Go binary | |
# id: godeps | |
# env: | |
# GOPROXY: ${{ secrets.ARTIFACTORY_ENDPOINT }} | |
# run: | | |
# go version -m ${{ matrix.prometheus.path }} > go_version_out_${{ github.run_id }}_${{ github.run_number }}.txt | |
# echo "go_version_out=$(find -type f -name "go_version_out*.txt" | head -n 1)" >> $GITHUB_OUTPUT | |
# echo "artifact_digest=$(openssl dgst -sha256 -r ${{ matrix.prometheus.path }} | cut -d ' ' -f 1)" >> $GITHUB_OUTPUT | |
# cat $GITHUB_OUTPUT | |
# - name: Generate Assertion Document | |
# id: assertiondoc | |
# uses: nginxinc/compliance-rules/.github/actions/assertion@83e452166aaf0ad8f07caf91a4f1f903b3dea1e6 # v0.3.0 | |
# with: | |
# artifact-name: "${{ github.event.repository.name }}_${{ github.sha }}_${{ github.run_number }}_${{ matrix.prometheus.os }}_${{ matrix.prometheus.arch }}" | |
# artifact-digest: ${{ steps.godeps.outputs.artifact_digest }} | |
# build-type: "github.com" | |
# builder-id: "github" | |
# builder-version: v0.1.0 | |
# started-on: ${{ steps.vars.outputs.timestamp }} | |
# finished-on: ${{ steps.vars.outputs.timestamp }} | |
# invocation-id: ${{ github.run_id }}.${{ github.run_number }}.${{ github.run_attempt }} | |
# artifactory-user: ${{ secrets.ARTIFACTORY_USER }} | |
# artifactory-api-token: ${{ secrets.ARTIFACTORY_TOKEN }} | |
# artifactory-url: ${{ secrets.ARTIFACTORY_URL }} | |
# artifactory-repo: 'f5-nginx-go-local-approved-dependency' | |
# assertion-doc-file: assertion_${{ github.event.repository.name }}_${{ github.sha }}_${{ github.run_id }}_${{ github.run_number }}_${{ matrix.prometheus.os }}_${{ matrix.prometheus.arch }}.json | |
# build-content-path: ${{ steps.godeps.outputs.go_version_out }} | |
# - name: Sign and Store Assertion Document | |
# id: sign | |
# uses: nginxinc/compliance-rules/.github/actions/sign@83e452166aaf0ad8f07caf91a4f1f903b3dea1e6 # v0.3.0 | |
# with: | |
# assertion-doc: ${{ steps.assertiondoc.outputs.assertion-document-path }} |