From 99db0017f82b23ce065dc98ab88da21a4f6d98d1 Mon Sep 17 00:00:00 2001 From: Julian Kornberger Date: Mon, 28 Jan 2019 01:26:44 +0100 Subject: [PATCH] Update Dockerfile to use Go 1.11 with modules --- Dockerfile | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/Dockerfile b/Dockerfile index bad4572..16f9a50 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,14 +1,23 @@ -FROM golang:1.8 -ADD . /go/src/github.com/kumina/postfix_exporter -WORKDIR /go/src/github.com/kumina/postfix_exporter +FROM golang:1.11 AS builder +WORKDIR /src + +# avoid downloading the dependencies on succesive builds RUN apt-get update -qq && apt-get install -qqy \ build-essential \ libsystemd-dev -RUN go get -v ./... -RUN go build + +COPY go.mod go.sum ./ +RUN go mod download +RUN go mod verify + +COPY . . + +# Force the go compiler to use modules +ENV GO111MODULE=on +RUN go build -o /bin/postfix_exporter FROM debian:latest EXPOSE 9154 WORKDIR / -COPY --from=0 /go/src/github.com/kumina/postfix_exporter/postfix_exporter . -ENTRYPOINT ["/postfix_exporter"] +COPY --from=builder /bin/postfix_exporter /bin/ +ENTRYPOINT ["/bin/postfix_exporter"]