From 650faef79b964057eacb430da89a8cdd2bb06d96 Mon Sep 17 00:00:00 2001 From: Nils Decker Date: Mon, 12 Dec 2022 22:21:41 +0100 Subject: [PATCH] improve Dockerfile: new golang and cache dependencies in extra layer --- Dockerfile | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/Dockerfile b/Dockerfile index ecd25ea..ebdcc72 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,15 +1,20 @@ -FROM golang:1.17-alpine AS builder +FROM golang:1.19.4-alpine AS builder WORKDIR /build -COPY . /build/ - ENV CGO_ENABLED=0 +# cache dependencies +# from https://github.com/montanaflynn/golang-docker-cache +COPY go.mod go.sum ./ +RUN go mod graph | awk '{if ($1 !~ "@") print $2}' | xargs -r go get + +COPY . ./ + RUN go build -v . FROM busybox -COPY --from=builder /build/fritzbox_exporter /usr/local/bin/fritzbox_exporter +COPY --from=builder /build/fritzbox_exporter /app/fritzbox_exporter EXPOSE 9133 -ENTRYPOINT /usr/local/bin/fritzbox_exporter +ENTRYPOINT /app/fritzbox_exporter