Skip to content

Commit 9cd3941

Browse files
authored
Build for more platforms (#844)
Signed-off-by: Luca Comellini <[email protected]>
1 parent 5228afd commit 9cd3941

File tree

3 files changed

+40
-30
lines changed

3 files changed

+40
-30
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@d632683dd7b4114ad314bca15554477dd762a938 # v4.2.0
@@ -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]>
@@ -174,7 +179,7 @@ jobs:
174179
uses: goreleaser/goreleaser-action@286f3b13b1b49da4ac219696163fb8c1c93e1200 # v6.0.0
175180
with:
176181
version: v2.3.2 # renovate: datasource=github-tags depName=goreleaser/goreleaser
177-
args: ${{ github.ref_type == 'tag' && 'release' || 'build --snapshot' }} ${{ github.event_name == 'pull_request' && '--single-target' || '' }} --clean
182+
args: ${{ github.ref_type == 'tag' && 'release' || 'build --snapshot' }} --clean
178183
env:
179184
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
180185
NGINX_GITHUB_TOKEN: ${{ secrets.NGINX_PAT }}
@@ -191,23 +196,23 @@ jobs:
191196
file: build/Dockerfile
192197
context: "."
193198
target: goreleaser
194-
platforms: ${{ github.event_name != 'pull_request' && env.DOCKER_PLATFORMS || '' }}
199+
platforms: ${{ env.DOCKER_PLATFORMS }}
195200
tags: ${{ steps.meta.outputs.tags }}
196201
labels: ${{ steps.meta.outputs.labels }}
197-
annotations: ${{ github.event_name != 'pull_request' && steps.meta.outputs.annotations || '' }}
198-
load: ${{ github.event_name == 'pull_request' }}
199-
push: ${{ github.event_name != 'pull_request' }}
200-
cache-from: type=gha
201-
cache-to: type=gha,mode=max
202-
provenance: ${{ github.event_name != 'pull_request' && 'mode=max' || 'false' }}
203-
sbom: ${{ github.event_name != 'pull_request' }}
202+
annotations: ${{ steps.meta.outputs.annotations }}
203+
push: true
204+
cache-from: type=gha,scope=exporter
205+
cache-to: type=gha,scope=exporter,mode=max
206+
no-cache: ${{ github.event_name != 'pull_request' }}
207+
provenance: mode=max
208+
sbom: true
204209

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

.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: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,38 @@
11
# syntax=docker/dockerfile:1.10
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

17-
FROM scratch AS intermediate
18-
COPY --from=base --link /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
18+
FROM --platform=$BUILDPLATFORM alpine:3.20 AS certs
19+
20+
FROM scratch AS base
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

2225

23-
FROM intermediate AS container
26+
FROM base AS container
2427
COPY --from=builder --link /go/src/github.com/nginxinc/nginx-prometheus-exporter/nginx-prometheus-exporter /usr/bin/
2528

2629

27-
FROM intermediate AS goreleaser
30+
FROM base AS goreleaser
2831
ARG TARGETARCH
2932
ARG TARGETVARIANT
3033
ARG TARGETPLATFORM
3134

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)