1
0
mirror of https://github.com/nginxinc/nginx-prometheus-exporter.git synced 2025-07-30 10:03:04 +03:00

Build for more platforms (#844)

Signed-off-by: Luca Comellini <luca.com@gmail.com>
This commit is contained in:
Luca Comellini
2024-09-30 08:44:34 -07:00
committed by GitHub
parent 5228afdf30
commit 9cd3941e7c
3 changed files with 40 additions and 30 deletions

View File

@ -11,7 +11,7 @@ on:
- main - main
env: env:
DOCKER_PLATFORMS: "linux/arm,linux/arm64,linux/amd64,linux/ppc64le,linux/s390x,linux/mips64le,linux/386" 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: concurrency:
group: ${{ github.ref_name }}-ci group: ${{ github.ref_name }}-ci
@ -51,6 +51,11 @@ jobs:
packages: write # for docker/build-push-action to push to GHCR packages: write # for docker/build-push-action to push to GHCR
issues: write # for goreleaser/goreleaser-action to close milestones issues: write # for goreleaser/goreleaser-action to close milestones
needs: unit-tests needs: unit-tests
services:
registry:
image: registry:2
ports:
- 5000:5000
steps: steps:
- name: Checkout Repository - name: Checkout Repository
uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 # v4.2.0 uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 # v4.2.0
@ -64,14 +69,12 @@ jobs:
- name: Setup QEMU - name: Setup QEMU
uses: docker/setup-qemu-action@49b3bc8e6bdd4a60e6116a5414239cba5943d3cf # v3.2.0 uses: docker/setup-qemu-action@49b3bc8e6bdd4a60e6116a5414239cba5943d3cf # v3.2.0
with:
platforms: arm,arm64,ppc64le,s390x,mips64le,386
if: github.event_name != 'pull_request'
- name: Docker Buildx - name: Docker Buildx
uses: docker/setup-buildx-action@988b5a0280414f521da01fcc63a27aeeb4b104db # v3.6.1 uses: docker/setup-buildx-action@988b5a0280414f521da01fcc63a27aeeb4b104db # v3.6.1
with: with:
version: latest version: latest
driver-opts: network=host
- name: DockerHub Login - name: DockerHub Login
uses: docker/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567 # v3.3.0 uses: docker/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567 # v3.3.0
@ -114,15 +117,17 @@ jobs:
uses: docker/metadata-action@8e5442c4ef9f78752691e2d8f8d19755c6f78e81 # v5.5.1 uses: docker/metadata-action@8e5442c4ef9f78752691e2d8f8d19755c6f78e81 # v5.5.1
with: with:
images: | images: |
nginx/nginx-prometheus-exporter name=nginx/nginx-prometheus-exporter,enable=${{ github.event_name != 'pull_request' }}
ghcr.io/nginxinc/nginx-prometheus-exporter name=ghcr.io/nginxinc/nginx-prometheus-exporter,enable=${{ github.event_name != 'pull_request' }}
public.ecr.aws/nginx/nginx-prometheus-exporter name=public.ecr.aws/nginx/nginx-prometheus-exporter,enable=${{ github.event_name != 'pull_request' }}
quay.io/nginx/nginx-prometheus-exporter name=quay.io/nginx/nginx-prometheus-exporter,enable=${{ github.event_name != 'pull_request' }}
name=localhost:5000/nginx/nginx-prometheus-exporter
tags: | tags: |
type=edge type=edge
type=ref,event=pr type=ref,event=pr
type=schedule type=schedule
type=semver,pattern={{version}} type=semver,pattern={{version}}
type=semver,pattern={{major}}
type=semver,pattern={{major}}.{{minor}} type=semver,pattern={{major}}.{{minor}}
labels: | labels: |
org.opencontainers.image.vendor=NGINX Inc <integrations@nginx.com> org.opencontainers.image.vendor=NGINX Inc <integrations@nginx.com>
@ -174,7 +179,7 @@ jobs:
uses: goreleaser/goreleaser-action@286f3b13b1b49da4ac219696163fb8c1c93e1200 # v6.0.0 uses: goreleaser/goreleaser-action@286f3b13b1b49da4ac219696163fb8c1c93e1200 # v6.0.0
with: with:
version: v2.3.2 # renovate: datasource=github-tags depName=goreleaser/goreleaser version: v2.3.2 # renovate: datasource=github-tags depName=goreleaser/goreleaser
args: ${{ github.ref_type == 'tag' && 'release' || 'build --snapshot' }} ${{ github.event_name == 'pull_request' && '--single-target' || '' }} --clean args: ${{ github.ref_type == 'tag' && 'release' || 'build --snapshot' }} --clean
env: env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NGINX_GITHUB_TOKEN: ${{ secrets.NGINX_PAT }} NGINX_GITHUB_TOKEN: ${{ secrets.NGINX_PAT }}
@ -191,23 +196,23 @@ jobs:
file: build/Dockerfile file: build/Dockerfile
context: "." context: "."
target: goreleaser target: goreleaser
platforms: ${{ github.event_name != 'pull_request' && env.DOCKER_PLATFORMS || '' }} platforms: ${{ env.DOCKER_PLATFORMS }}
tags: ${{ steps.meta.outputs.tags }} tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }} labels: ${{ steps.meta.outputs.labels }}
annotations: ${{ github.event_name != 'pull_request' && steps.meta.outputs.annotations || '' }} annotations: ${{ steps.meta.outputs.annotations }}
load: ${{ github.event_name == 'pull_request' }} push: true
push: ${{ github.event_name != 'pull_request' }} cache-from: type=gha,scope=exporter
cache-from: type=gha cache-to: type=gha,scope=exporter,mode=max
cache-to: type=gha,mode=max no-cache: ${{ github.event_name != 'pull_request' }}
provenance: ${{ github.event_name != 'pull_request' && 'mode=max' || 'false' }} provenance: mode=max
sbom: ${{ github.event_name != 'pull_request' }} sbom: true
- name: Scan image - name: Scan image
uses: anchore/scan-action@64a33b277ea7a1215a3c142735a1091341939ff5 # v4.1.2 uses: anchore/scan-action@64a33b277ea7a1215a3c142735a1091341939ff5 # v4.1.2
id: scan id: scan
continue-on-error: true continue-on-error: true
with: with:
image: nginx/nginx-prometheus-exporter:${{ steps.meta.outputs.version }} image: localhost:5000/nginx/nginx-prometheus-exporter:${{ steps.meta.outputs.version }}
only-fixed: true only-fixed: true
add-cpes-if-none: true add-cpes-if-none: true

View File

@ -8,16 +8,21 @@ builds:
- env: - env:
- CGO_ENABLED=0 - CGO_ENABLED=0
goos: goos:
- linux
- darwin - darwin
- freebsd
- linux
- solaris
- windows - windows
goarch: goarch:
- 386 - 386
- amd64 - amd64
- arm - arm
- arm64 - arm64
- ppc64le - mips64
- mips64le - mips64le
- ppc64
- ppc64le
- riscv64
- s390x - s390x
goarm: goarm:
- 5 - 5
@ -89,9 +94,6 @@ announce:
milestones: milestones:
- close: true - close: true
snapshot:
name_template: "edge"
snapcrafts: snapcrafts:
- name_template: "{{ .ProjectName }}_{{ .Arch }}{{ if .Arm }}v{{ .Arm }}{{ end }}" - name_template: "{{ .ProjectName }}_{{ .Arch }}{{ if .Arm }}v{{ .Arm }}{{ end }}"
title: NGINX Prometheus Exporter title: NGINX Prometheus Exporter

View File

@ -1,30 +1,33 @@
# syntax=docker/dockerfile:1.10 # syntax=docker/dockerfile:1.10
FROM golang:1.23 AS base FROM golang:1.23 AS builder
ARG VERSION ARG VERSION
ARG TARGETARCH ARG TARGETARCH
WORKDIR /go/src/github.com/nginxinc/nginx-prometheus-exporter WORKDIR /go/src/github.com/nginxinc/nginx-prometheus-exporter
FROM base AS builder
COPY --link go.mod go.sum ./ COPY --link go.mod go.sum ./
RUN go mod download RUN go mod download
COPY --link *.go ./ COPY --link *.go ./
COPY --link collector ./collector COPY --link collector ./collector
COPY --link client ./client COPY --link client ./client
RUN CGO_ENABLED=0 GOOS=linux GOARCH=$TARGETARCH go build -trimpath -a -ldflags "-s -w -X main.version=${VERSION}" -o nginx-prometheus-exporter . RUN CGO_ENABLED=0 GOOS=linux GOARCH=$TARGETARCH go build -trimpath -a -ldflags "-s -w -X main.version=${VERSION}" -o nginx-prometheus-exporter .
FROM scratch AS intermediate FROM --platform=$BUILDPLATFORM alpine:3.20 AS certs
COPY --from=base --link /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
FROM scratch AS base
COPY --from=certs --link /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
USER 1001:1001 USER 1001:1001
ENTRYPOINT [ "/usr/bin/nginx-prometheus-exporter" ] ENTRYPOINT [ "/usr/bin/nginx-prometheus-exporter" ]
FROM intermediate AS container FROM base AS container
COPY --from=builder --link /go/src/github.com/nginxinc/nginx-prometheus-exporter/nginx-prometheus-exporter /usr/bin/ COPY --from=builder --link /go/src/github.com/nginxinc/nginx-prometheus-exporter/nginx-prometheus-exporter /usr/bin/
FROM intermediate AS goreleaser FROM base AS goreleaser
ARG TARGETARCH ARG TARGETARCH
ARG TARGETVARIANT ARG TARGETVARIANT
ARG TARGETPLATFORM ARG TARGETPLATFORM
@ -32,4 +35,4 @@ ARG TARGETPLATFORM
LABEL org.nginx.exporter.image.build.target="${TARGETPLATFORM}" LABEL org.nginx.exporter.image.build.target="${TARGETPLATFORM}"
LABEL org.nginx.exporter.image.build.version="goreleaser" LABEL org.nginx.exporter.image.build.version="goreleaser"
COPY --link dist/nginx-prometheus-exporter_linux_$TARGETARCH${TARGETVARIANT:+_7}*/nginx-prometheus-exporter /usr/bin/ COPY --link dist/nginx-prometheus-exporter_linux_$TARGETARCH${TARGETVARIANT/v/_}*/nginx-prometheus-exporter /usr/bin/