Last active
February 23, 2018 18:31
-
-
Save shahidhk/5bc4b1bfd5631730fa629555a1cfe868 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FROM golang:1.8.5-jessie as builder | |
# install xz | |
RUN apt-get update && apt-get install -y \ | |
xz-utils \ | |
&& rm -rf /var/lib/apt/lists/* | |
# install UPX | |
ADD https://github.com/upx/upx/releases/download/v3.94/upx-3.94-amd64_linux.tar.xz /usr/local | |
RUN xz -d -c /usr/local/upx-3.94-amd64_linux.tar.xz | \ | |
tar -xOf - upx-3.94-amd64_linux/upx > /bin/upx && \ | |
chmod a+x /bin/upx | |
# install glide | |
RUN go get github.com/Masterminds/glide | |
# setup the working directory | |
WORKDIR /go/src/app | |
ADD glide.yaml glide.yaml | |
ADD glide.lock glide.lock | |
# install dependencies | |
RUN glide install | |
# add source code | |
ADD src src | |
# build the source | |
RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o main src/main.go | |
# strip and compress the binary | |
RUN strip --strip-unneeded main | |
RUN upx main | |
# use a minimal alpine image | |
FROM alpine:3.7 | |
# add ca-certificates in case you need them | |
RUN apk update && apk add ca-certificates && rm -rf /var/cache/apk/* | |
# set working directory | |
WORKDIR /root | |
# copy the binary from builder | |
COPY --from=builder /go/src/app/main . | |
# run the binary | |
CMD ["./main"] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment