From 83102aa31e7470bdf302504897fcd1082753a773 Mon Sep 17 00:00:00 2001 From: Manuel Date: Sun, 18 Oct 2020 16:43:43 +0200 Subject: [PATCH] Docker multi-arch images --- Dockerfile | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/Dockerfile b/Dockerfile index 549fe1e..0950344 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,12 +1,23 @@ -FROM golang:1.15 +FROM --platform=$BUILDPLATFORM golang:1.15 AS build + +ARG TARGETOS +ARG TARGETARCH +ARG TARGETVARIANT + RUN git clone https://github.com/chr-fritz/fritzbox_exporter.git /go/src/github.com/chr-fritz/fritzbox_exporter WORKDIR /go/src/github.com/chr-fritz/fritzbox_exporter -RUN go mod download && \ - CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -ldflags '-w -extldflags "-static"' -o fritzbox-exporter . -FROM alpine:latest +RUN go mod download; \ + case "$TARGETVARIANT" in \ + v5) export GOARM=5 ;; \ + v6) export GOARM=6 ;; \ + v7) export GOARM=7 ;; \ + esac; \ + CGO_ENABLED=0 GOOS=$TARGETOS GOARCH=$TARGETARCH go build -a -ldflags '-w -extldflags "-static"' -o fritzbox-exporter . + +FROM --platform=$TARGETPLATFORM alpine:latest RUN apk --no-cache add ca-certificates -COPY --from=0 /go/src/github.com/chr-fritz/fritzbox_exporter/fritzbox-exporter /fritzbox-exporter/ -COPY --from=0 /go/src/github.com/chr-fritz/fritzbox_exporter/*.json /etc/fritzbox-exporter/ +COPY --from=build /go/src/github.com/chr-fritz/fritzbox_exporter/fritzbox-exporter /fritzbox-exporter/ +COPY --from=build /go/src/github.com/chr-fritz/fritzbox_exporter/*.json /etc/fritzbox-exporter/ ENTRYPOINT ["/fritzbox-exporter/fritzbox-exporter"] CMD ["--metrics-file","/etc/fritzbox-exporter/metrics.json","--listen-address","0.0.0.0:8080"]