Skip to content

Build for more platforms #844

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Sep 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 23 additions & 18 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ on:
- main

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:
group: ${{ github.ref_name }}-ci
Expand Down Expand Up @@ -51,6 +51,11 @@ jobs:
packages: write # for docker/build-push-action to push to GHCR
issues: write # for goreleaser/goreleaser-action to close milestones
needs: unit-tests
services:
registry:
image: registry:2
ports:
- 5000:5000
steps:
- name: Checkout Repository
uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 # v4.2.0
Expand All @@ -64,14 +69,12 @@ jobs:

- name: Setup QEMU
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
uses: docker/setup-buildx-action@988b5a0280414f521da01fcc63a27aeeb4b104db # v3.6.1
with:
version: latest
driver-opts: network=host

- name: DockerHub Login
uses: docker/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567 # v3.3.0
Expand Down Expand Up @@ -114,15 +117,17 @@ jobs:
uses: docker/metadata-action@8e5442c4ef9f78752691e2d8f8d19755c6f78e81 # v5.5.1
with:
images: |
nginx/nginx-prometheus-exporter
ghcr.io/nginxinc/nginx-prometheus-exporter
public.ecr.aws/nginx/nginx-prometheus-exporter
quay.io/nginx/nginx-prometheus-exporter
name=nginx/nginx-prometheus-exporter,enable=${{ github.event_name != 'pull_request' }}
name=ghcr.io/nginxinc/nginx-prometheus-exporter,enable=${{ github.event_name != 'pull_request' }}
name=public.ecr.aws/nginx/nginx-prometheus-exporter,enable=${{ github.event_name != 'pull_request' }}
name=quay.io/nginx/nginx-prometheus-exporter,enable=${{ github.event_name != 'pull_request' }}
name=localhost:5000/nginx/nginx-prometheus-exporter
tags: |
type=edge
type=ref,event=pr
type=schedule
type=semver,pattern={{version}}
type=semver,pattern={{major}}
type=semver,pattern={{major}}.{{minor}}
labels: |
org.opencontainers.image.vendor=NGINX Inc <integrations@nginx.com>
Expand Down Expand Up @@ -174,7 +179,7 @@ jobs:
uses: goreleaser/goreleaser-action@286f3b13b1b49da4ac219696163fb8c1c93e1200 # v6.0.0
with:
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:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NGINX_GITHUB_TOKEN: ${{ secrets.NGINX_PAT }}
Expand All @@ -191,23 +196,23 @@ jobs:
file: build/Dockerfile
context: "."
target: goreleaser
platforms: ${{ github.event_name != 'pull_request' && env.DOCKER_PLATFORMS || '' }}
platforms: ${{ env.DOCKER_PLATFORMS }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
annotations: ${{ github.event_name != 'pull_request' && steps.meta.outputs.annotations || '' }}
load: ${{ github.event_name == 'pull_request' }}
push: ${{ github.event_name != 'pull_request' }}
cache-from: type=gha
cache-to: type=gha,mode=max
provenance: ${{ github.event_name != 'pull_request' && 'mode=max' || 'false' }}
sbom: ${{ github.event_name != 'pull_request' }}
annotations: ${{ steps.meta.outputs.annotations }}
push: true
cache-from: type=gha,scope=exporter
cache-to: type=gha,scope=exporter,mode=max
no-cache: ${{ github.event_name != 'pull_request' }}
provenance: mode=max
sbom: true

- name: Scan image
uses: anchore/scan-action@64a33b277ea7a1215a3c142735a1091341939ff5 # v4.1.2
id: scan
continue-on-error: true
with:
image: nginx/nginx-prometheus-exporter:${{ steps.meta.outputs.version }}
image: localhost:5000/nginx/nginx-prometheus-exporter:${{ steps.meta.outputs.version }}
only-fixed: true
add-cpes-if-none: true

Expand Down
12 changes: 7 additions & 5 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,21 @@ builds:
- env:
- CGO_ENABLED=0
goos:
- linux
- darwin
- freebsd
- linux
- solaris
- windows
goarch:
- 386
- amd64
- arm
- arm64
- ppc64le
- mips64
- mips64le
- ppc64
- ppc64le
- riscv64
- s390x
goarm:
- 5
Expand Down Expand Up @@ -89,9 +94,6 @@ announce:
milestones:
- close: true

snapshot:
name_template: "edge"

snapcrafts:
- name_template: "{{ .ProjectName }}_{{ .Arch }}{{ if .Arm }}v{{ .Arm }}{{ end }}"
title: NGINX Prometheus Exporter
Expand Down
17 changes: 10 additions & 7 deletions build/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,35 +1,38 @@
# syntax=docker/dockerfile:1.10
FROM golang:1.23 AS base
FROM golang:1.23 AS builder
ARG VERSION
ARG TARGETARCH

WORKDIR /go/src/github.com/nginxinc/nginx-prometheus-exporter

FROM base AS builder
COPY --link go.mod go.sum ./
RUN go mod download

COPY --link *.go ./
COPY --link collector ./collector
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 .


FROM scratch AS intermediate
COPY --from=base --link /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
FROM --platform=$BUILDPLATFORM alpine:3.20 AS certs

FROM scratch AS base
COPY --from=certs --link /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
USER 1001:1001
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/


FROM intermediate AS goreleaser
FROM base AS goreleaser
ARG TARGETARCH
ARG TARGETVARIANT
ARG TARGETPLATFORM

LABEL org.nginx.exporter.image.build.target="${TARGETPLATFORM}"
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/