Skip to content

Commit 3672673

Browse files
committed
Build for more platforms
1 parent ed17e0f commit 3672673

File tree

3 files changed

+37
-27
lines changed

3 files changed

+37
-27
lines changed

.github/workflows/ci.yml

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ on:
1111
- main
1212

1313
env:
14-
DOCKER_PLATFORMS: "linux/arm,linux/arm64,linux/amd64,linux/ppc64le,linux/s390x,linux/mips64le,linux/386"
14+
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"
1515

1616
concurrency:
1717
group: ${{ github.ref_name }}-ci
@@ -51,6 +51,11 @@ jobs:
5151
packages: write # for docker/build-push-action to push to GHCR
5252
issues: write # for goreleaser/goreleaser-action to close milestones
5353
needs: unit-tests
54+
services:
55+
registry:
56+
image: registry:2
57+
ports:
58+
- 5000:5000
5459
steps:
5560
- name: Checkout Repository
5661
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
@@ -64,14 +69,12 @@ jobs:
6469

6570
- name: Setup QEMU
6671
uses: docker/setup-qemu-action@49b3bc8e6bdd4a60e6116a5414239cba5943d3cf # v3.2.0
67-
with:
68-
platforms: arm,arm64,ppc64le,s390x,mips64le,386
69-
if: github.event_name != 'pull_request'
7072

7173
- name: Docker Buildx
7274
uses: docker/setup-buildx-action@988b5a0280414f521da01fcc63a27aeeb4b104db # v3.6.1
7375
with:
7476
version: latest
77+
driver-opts: network=host
7578

7679
- name: DockerHub Login
7780
uses: docker/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567 # v3.3.0
@@ -114,15 +117,17 @@ jobs:
114117
uses: docker/metadata-action@8e5442c4ef9f78752691e2d8f8d19755c6f78e81 # v5.5.1
115118
with:
116119
images: |
117-
nginx/nginx-prometheus-exporter
118-
ghcr.io/nginxinc/nginx-prometheus-exporter
119-
public.ecr.aws/nginx/nginx-prometheus-exporter
120-
quay.io/nginx/nginx-prometheus-exporter
120+
name=nginx/nginx-prometheus-exporter,enable=${{ github.event_name != 'pull_request' }}
121+
name=ghcr.io/nginxinc/nginx-prometheus-exporter,enable=${{ github.event_name != 'pull_request' }}
122+
name=public.ecr.aws/nginx/nginx-prometheus-exporter,enable=${{ github.event_name != 'pull_request' }}
123+
name=quay.io/nginx/nginx-prometheus-exporter,enable=${{ github.event_name != 'pull_request' }}
124+
name=localhost:5000/nginx/nginx-prometheus-exporter
121125
tags: |
122126
type=edge
123127
type=ref,event=pr
124128
type=schedule
125129
type=semver,pattern={{version}}
130+
type=semver,pattern={{major}}
126131
type=semver,pattern={{major}}.{{minor}}
127132
labels: |
128133
org.opencontainers.image.vendor=NGINX Inc <[email protected]>
@@ -175,7 +180,7 @@ jobs:
175180
uses: goreleaser/goreleaser-action@286f3b13b1b49da4ac219696163fb8c1c93e1200 # v6.0.0
176181
with:
177182
version: v2.2.0 # renovate: datasource=github-tags depName=goreleaser/goreleaser
178-
args: ${{ github.ref_type == 'tag' && 'release' || 'build --snapshot' }} ${{ github.event_name == 'pull_request' && '--single-target' || '' }} --clean
183+
args: ${{ github.ref_type == 'tag' && 'release' || 'build --snapshot' }} --clean
179184
env:
180185
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
181186
NGINX_GITHUB_TOKEN: ${{ secrets.NGINX_PAT }}
@@ -192,23 +197,23 @@ jobs:
192197
file: build/Dockerfile
193198
context: "."
194199
target: goreleaser
195-
platforms: ${{ github.event_name != 'pull_request' && env.DOCKER_PLATFORMS || '' }}
200+
platforms: ${{ env.DOCKER_PLATFORMS }}
196201
tags: ${{ steps.meta.outputs.tags }}
197202
labels: ${{ steps.meta.outputs.labels }}
198-
annotations: ${{ github.event_name != 'pull_request' && steps.meta.outputs.annotations || '' }}
199-
load: ${{ github.event_name == 'pull_request' }}
200-
push: ${{ github.event_name != 'pull_request' }}
201-
cache-from: type=gha
202-
cache-to: type=gha,mode=max
203-
provenance: ${{ github.event_name != 'pull_request' && 'mode=max' || 'false' }}
204-
sbom: ${{ github.event_name != 'pull_request' }}
203+
annotations: ${{ steps.meta.outputs.annotations }}
204+
push: true
205+
cache-from: type=gha,scope=exporter
206+
cache-to: type=gha,scope=exporter,mode=max
207+
no-cache: ${{ github.event_name != 'pull_request' }}
208+
provenance: mode=max
209+
sbom: true
205210

206211
- name: Scan image
207212
uses: anchore/scan-action@64a33b277ea7a1215a3c142735a1091341939ff5 # v4.1.2
208213
id: scan
209214
continue-on-error: true
210215
with:
211-
image: nginx/nginx-prometheus-exporter:${{ steps.meta.outputs.version }}
216+
image: localhost:5000/nginx/nginx-prometheus-exporter:${{ steps.meta.outputs.version }}
212217
only-fixed: true
213218
add-cpes-if-none: true
214219

.goreleaser.yml

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,21 @@ builds:
88
- env:
99
- CGO_ENABLED=0
1010
goos:
11-
- linux
1211
- darwin
12+
- freebsd
13+
- linux
14+
- solaris
1315
- windows
1416
goarch:
1517
- 386
1618
- amd64
1719
- arm
1820
- arm64
19-
- ppc64le
21+
- mips64
2022
- mips64le
23+
- ppc64
24+
- ppc64le
25+
- riscv64
2126
- s390x
2227
goarm:
2328
- 5
@@ -89,9 +94,6 @@ announce:
8994
milestones:
9095
- close: true
9196

92-
snapshot:
93-
name_template: "edge"
94-
9597
snapcrafts:
9698
- name_template: "{{ .ProjectName }}_{{ .Arch }}{{ if .Arm }}v{{ .Arm }}{{ end }}"
9799
title: NGINX Prometheus Exporter

build/Dockerfile

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,24 @@
11
# syntax=docker/dockerfile:1.9
2-
FROM golang:1.23 AS base
2+
FROM golang:1.23 AS builder
33
ARG VERSION
44
ARG TARGETARCH
55

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

8-
FROM base AS builder
98
COPY --link go.mod go.sum ./
109
RUN go mod download
10+
1111
COPY --link *.go ./
1212
COPY --link collector ./collector
1313
COPY --link client ./client
14+
1415
RUN CGO_ENABLED=0 GOOS=linux GOARCH=$TARGETARCH go build -trimpath -a -ldflags "-s -w -X main.version=${VERSION}" -o nginx-prometheus-exporter .
1516

1617

18+
FROM --platform=$BUILDPLATFORM alpine:3.20 AS certs
19+
1720
FROM scratch AS intermediate
18-
COPY --from=base --link /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
21+
COPY --from=certs --link /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
1922
USER 1001:1001
2023
ENTRYPOINT [ "/usr/bin/nginx-prometheus-exporter" ]
2124

@@ -32,4 +35,4 @@ ARG TARGETPLATFORM
3235
LABEL org.nginx.exporter.image.build.target="${TARGETPLATFORM}"
3336
LABEL org.nginx.exporter.image.build.version="goreleaser"
3437

35-
COPY --link dist/nginx-prometheus-exporter_linux_$TARGETARCH${TARGETVARIANT:+_7}*/nginx-prometheus-exporter /usr/bin/
38+
COPY --link dist/nginx-prometheus-exporter_linux_$TARGETARCH${TARGETVARIANT/v/_}*/nginx-prometheus-exporter /usr/bin/

0 commit comments

Comments
 (0)