Use multistage build for a fully static Docker binary build.

master
Icedream 2018-06-03 01:01:08 +02:00
parent 3ea158f25a
commit 6a761c4655
Signed by: icedream
GPG Key ID: 1573F6D8EFE4D0CF
1 changed files with 8 additions and 5 deletions

View File

@ -1,4 +1,4 @@
FROM golang:1.10 FROM golang:1.10 AS builder
RUN mkdir -p /go/src/app RUN mkdir -p /go/src/app
WORKDIR /go/src/app WORKDIR /go/src/app
@ -7,8 +7,11 @@ ARG ROOT_IMPORT_PATH=github.com/icedream/embot
COPY . /go/src/app COPY . /go/src/app
RUN \ RUN \
mkdir -p "$GOPATH/src/$(dirname "$ROOT_IMPORT_PATH")" &&\ mkdir -p "$GOPATH/src/$(dirname "$ROOT_IMPORT_PATH")" &&\
ln -sf /go/src/app "$GOPATH/src/$ROOT_IMPORT_PATH" &&\ ln -sf "$GOPATH/src/app" "$GOPATH/src/$ROOT_IMPORT_PATH" &&\
go-wrapper download &&\ CGO_ENABLED=0 go build -a -ldflags '-extldflags "-static"' -o /soccerbot "$ROOT_IMPORT_PATH"
go-wrapper install
CMD ["go-wrapper", "run"] ###
FROM scratch
COPY --from=builder /soccerbot /
ENTRYPOINT ["/soccerbot"]