From c2c186320ee24639d246bdcfe7c67a026d6610eb Mon Sep 17 00:00:00 2001 From: Luca Comellini Date: Mon, 22 Mar 2021 09:57:32 -0700 Subject: [PATCH] Use scratch to support building for more archs (#167) Support mips64le and 386 --- .github/workflows/ci.yml | 4 ++-- build/Dockerfile | 13 ++++++++----- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f4b05b53..024964d6 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -70,7 +70,7 @@ jobs: file: build/Dockerfile context: '.' target: local - platforms: linux/arm,linux/arm64,linux/amd64,linux/ppc64le,linux/s390x + platforms: linux/arm,linux/arm64,linux/amd64,linux/ppc64le,linux/s390x,linux/mips64le,linux/386 cache-from: type=local,src=/tmp/.buildx-cache cache-to: type=local,dest=/tmp/.buildx-cache tags: nginx/nginx-prometheus-exporter:${{ github.sha }} @@ -119,7 +119,7 @@ jobs: file: build/Dockerfile context: '.' target: local - platforms: linux/arm,linux/arm64,linux/amd64,linux/ppc64le,linux/s390x + platforms: linux/arm,linux/arm64,linux/amd64,linux/ppc64le,linux/s390x,linux/mips64le,linux/386 tags: | nginx/nginx-prometheus-exporter:latest nginx/nginx-prometheus-exporter:${{ steps.get_version.outputs.GIT_TAG }} diff --git a/build/Dockerfile b/build/Dockerfile index ff16efda..64b9e210 100644 --- a/build/Dockerfile +++ b/build/Dockerfile @@ -1,4 +1,4 @@ -FROM golang:1.16-alpine as builder +FROM golang:1.16 as base ARG VERSION ARG GIT_COMMIT ARG TARGETARCH @@ -9,20 +9,23 @@ COPY vendor ./vendor COPY go.mod go.sum ./ COPY collector ./collector COPY client ./client + +FROM base as builder 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 . -FROM gcr.io/distroless/static-debian10:nonroot as base +FROM scratch as intermediate +COPY --from=base /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ USER 1001:1001 ENTRYPOINT [ "/usr/bin/nginx-prometheus-exporter" ] -FROM base as container +FROM intermediate as container COPY --from=builder /go/src/github.com/nginxinc/nginx-prometheus-exporter/nginx-prometheus-exporter /usr/bin/ -FROM base as local +FROM intermediate as local ARG TARGETARCH ARG TARGETVARIANT -COPY dist/nginx-prometheus-exporter_linux_$TARGETARCH${TARGETVARIANT:+_7}/nginx-prometheus-exporter /usr/bin +COPY dist/nginx-prometheus-exporter_linux_$TARGETARCH${TARGETVARIANT:+_7}*/nginx-prometheus-exporter /usr/bin/