Skip to content

Commit 85f013d

Browse files
authored
Add support for more platforms, push to Docker Hub (#164)
- Build binaries for more versions of arm, 386, ppc64le, mips64le and s390x - Build docker images for ARM and ppc64 (other platforms are not supported by distroless docker image) and push them to Docker Hub
1 parent e31ef71 commit 85f013d

File tree

4 files changed

+45
-19
lines changed

4 files changed

+45
-19
lines changed

.github/workflows/ci.yml

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ jobs:
2929

3030
unit-tests:
3131
name: Unit Tests
32-
runs-on: ubuntu-18.04
32+
runs-on: ubuntu-20.04
3333
steps:
3434
- name: Checkout Repository
3535
uses: actions/checkout@v2
@@ -42,12 +42,10 @@ jobs:
4242

4343
build:
4444
name: Build Image
45-
runs-on: ubuntu-18.04
45+
runs-on: ubuntu-20.04
4646
steps:
4747
- name: Checkout Repository
4848
uses: actions/checkout@v2
49-
- name: Build Prometheus-Exporter
50-
run: make nginx-prometheus-exporter
5149
- name: Docker Buildx
5250
uses: docker/setup-buildx-action@v1
5351
with:
@@ -59,19 +57,28 @@ jobs:
5957
key: ${{ runner.os }}-buildx-${{ github.sha }}
6058
restore-keys: |
6159
${{ runner.os }}-buildx-
60+
- name: Run GoReleaser
61+
uses: goreleaser/goreleaser-action@v2
62+
with:
63+
version: latest
64+
args: --rm-dist --debug --skip-publish --snapshot
65+
env:
66+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
6267
- name: Build Image
6368
uses: docker/build-push-action@v2
6469
with:
6570
file: build/Dockerfile
6671
context: '.'
72+
target: local
73+
platforms: linux/arm,linux/arm64,linux/amd64,linux/ppc64le,linux/s390x
6774
cache-from: type=local,src=/tmp/.buildx-cache
6875
cache-to: type=local,dest=/tmp/.buildx-cache
6976
tags: nginx/nginx-prometheus-exporter:${{ github.sha }}
7077
push: false
7178

7279
release-docker:
7380
name: Release Image
74-
runs-on: ubuntu-18.04
81+
runs-on: ubuntu-20.04
7582
needs: [build, unit-tests]
7683
if:
7784
github.repository == 'nginxinc/nginx-prometheus-exporter' &&
@@ -99,11 +106,20 @@ jobs:
99106
with:
100107
username: ${{ secrets.DOCKER_USERNAME }}
101108
password: ${{ secrets.DOCKER_PASSWORD }}
109+
- name: Run GoReleaser
110+
uses: goreleaser/goreleaser-action@v2
111+
with:
112+
version: latest
113+
args: release --rm-dist
114+
env:
115+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
102116
- name: Push to Dockerhub
103117
uses: docker/build-push-action@v2
104118
with:
105119
file: build/Dockerfile
106120
context: '.'
121+
target: local
122+
platforms: linux/arm,linux/arm64,linux/amd64,linux/ppc64le,linux/s390x
107123
tags: |
108124
nginx/nginx-prometheus-exporter:latest
109125
nginx/nginx-prometheus-exporter:${{ steps.get_version.outputs.GIT_TAG }}
@@ -117,17 +133,10 @@ jobs:
117133
publish: true
118134
env:
119135
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
120-
- name: Run GoReleaser
121-
uses: goreleaser/goreleaser-action@v2
122-
with:
123-
version: latest
124-
args: release --rm-dist
125-
env:
126-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
127136

128137
notify:
129138
name: Notify
130-
runs-on: ubuntu-18.04
139+
runs-on: ubuntu-20.04
131140
needs: release-docker
132141
if: always() && github.ref == 'refs/heads/master'
133142
steps:

.goreleaser.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,15 @@ builds:
1616
- amd64
1717
- arm
1818
- arm64
19+
- ppc64le
20+
- mips64le
21+
- s390x
1922
goarm:
23+
- 5
2024
- 6
2125
- 7
26+
gomips:
27+
- softfloat
2228
flags:
2329
- -mod=vendor
2430
checksum:

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ test:
2828

2929
.PHONY: container
3030
container:
31-
docker build --build-arg VERSION=$(VERSION) --build-arg GIT_COMMIT=$(GIT_COMMIT) -f $(DOCKERFILEPATH)/$(DOCKERFILE) -t $(PREFIX):$(TAG) .
31+
docker build --build-arg VERSION=$(VERSION) --build-arg GIT_COMMIT=$(GIT_COMMIT) --target container -f $(DOCKERFILEPATH)/$(DOCKERFILE) -t $(PREFIX):$(TAG) .
3232

3333
.PHONY: push
3434
push: container

build/Dockerfile

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,28 @@
1-
FROM golang:1.16 as builder
1+
FROM golang:1.16-alpine as builder
22
ARG VERSION
33
ARG GIT_COMMIT
4+
ARG TARGETARCH
5+
46
WORKDIR /go/src/github.com/nginxinc/nginx-prometheus-exporter
57
COPY *.go ./
68
COPY vendor ./vendor
79
COPY go.mod go.sum ./
810
COPY collector ./collector
911
COPY client ./client
10-
RUN GO111MODULE=on CGO_ENABLED=0 GOOS=linux go build -mod=vendor -a -ldflags "-X main.version=${VERSION} -X main.commit=${GIT_COMMIT}" -o exporter .
12+
RUN GO111MODULE=on CGO_ENABLED=0 GOOS=linux GOARCH=$TARGETARCH go build -mod=vendor -a -ldflags "-s -w -X main.version=${VERSION} -X main.commit=${GIT_COMMIT}" -o nginx-prometheus-exporter .
1113

12-
FROM gcr.io/distroless/static-debian10:nonroot
13-
COPY --from=builder /go/src/github.com/nginxinc/nginx-prometheus-exporter/exporter /usr/bin/
1414

15+
FROM gcr.io/distroless/static-debian10:nonroot as base
1516
USER 1001:1001
17+
ENTRYPOINT [ "/usr/bin/nginx-prometheus-exporter" ]
18+
19+
20+
FROM base as container
21+
COPY --from=builder /go/src/github.com/nginxinc/nginx-prometheus-exporter/nginx-prometheus-exporter /usr/bin/
22+
23+
24+
FROM base as local
25+
ARG TARGETARCH
26+
ARG TARGETVARIANT
1627

17-
ENTRYPOINT [ "/usr/bin/exporter" ]
28+
COPY dist/nginx-prometheus-exporter_linux_$TARGETARCH${TARGETVARIANT:+_7}/nginx-prometheus-exporter /usr/bin

0 commit comments

Comments
 (0)