From 1441b942a913c92ce34a57ae03a2af80ff5e67be Mon Sep 17 00:00:00 2001 From: Hendrik Schlehlein Date: Thu, 31 Jan 2019 16:26:30 +0000 Subject: [PATCH] dockerfile update --- Dockerfile | 37 ++++++++++++++++++++++++++++++------- 1 file changed, 30 insertions(+), 7 deletions(-) diff --git a/Dockerfile b/Dockerfile index 02a7b1f..95ac34b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,7 +1,30 @@ -FROM golang:latest -RUN mkdir -p /app -WORKDIR /app -ADD main.go /app -RUN go get -u -RUN go build ./main.go -CMD ["./main"] \ No newline at end of file +############################ +# STEP 1 build executable binary +############################ +FROM golang:alpine AS builder + +# Install git. +# Git is required for fetching the dependencies. +RUN apk update && apk add --no-cache git + +WORKDIR $GOPATH/src/git.cliffbreak.de/Cliffbreak/tsviewer +COPY . . + +# Fetch dependencies. + +# Using go get. +RUN go get -d -v + +# Build the binary. +RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -installsuffix cgo -ldflags="-w -s" -o /go/bin/main + +############################ +# STEP 2 build a small image +############################ +FROM scratch + +# Copy our static executable. +COPY --from=builder /go/bin/main /go/bin/main + +# Run the hello binary. +ENTRYPOINT ["/go/bin/main"] \ No newline at end of file