From 6a761c4655d07e89e1e3724be9761b6fd2511fd2 Mon Sep 17 00:00:00 2001 From: Carl Kittelberger Date: Sun, 3 Jun 2018 01:01:08 +0200 Subject: [PATCH] Use multistage build for a fully static Docker binary build. --- Dockerfile | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/Dockerfile b/Dockerfile index 472b3f1..324296d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM golang:1.10 +FROM golang:1.10 AS builder RUN mkdir -p /go/src/app WORKDIR /go/src/app @@ -7,8 +7,11 @@ ARG ROOT_IMPORT_PATH=github.com/icedream/embot COPY . /go/src/app RUN \ mkdir -p "$GOPATH/src/$(dirname "$ROOT_IMPORT_PATH")" &&\ - ln -sf /go/src/app "$GOPATH/src/$ROOT_IMPORT_PATH" &&\ - go-wrapper download &&\ - go-wrapper install + ln -sf "$GOPATH/src/app" "$GOPATH/src/$ROOT_IMPORT_PATH" &&\ + CGO_ENABLED=0 go build -a -ldflags '-extldflags "-static"' -o /soccerbot "$ROOT_IMPORT_PATH" -CMD ["go-wrapper", "run"] +### + +FROM scratch +COPY --from=builder /soccerbot / +ENTRYPOINT ["/soccerbot"]