Created
June 25, 2018 02:33
-
-
Save cjimti/c988db3ff1a798eb3e18d76f3d71e75a to your computer and use it in GitHub Desktop.
Golang Microservice Dockerfile boilerplate
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.10.2-alpine3.7 AS builder | |
ARG GITLAB_TOKEN | |
ARG GITLAB_DOMAIN | |
RUN apk update \ | |
&& apk add git | |
RUN mkdir -p /go/src \ | |
&& mkdir -p /go/bin \ | |
&& mkdir -p /go/pkg | |
ENV GOPATH=/go | |
ENV PATH=$GOPATH/bin:$PATH | |
RUN mkdir -p $GOPATH/src/app | |
ADD . $GOPATH/src/app | |
ADD . /go/src | |
WORKDIR $GOPATH/src/app | |
# go get uses git to pull lib dependencies | |
RUN git config --global url."https://oauth2:$GITLAB_TOKEN@$GITLAB_DOMAIN".insteadOf "https://$GITLAB_DOMAIN" | |
RUN go get . | |
RUN go get github.com/json-iterator/go | |
RUN CGO_ENABLED=0 go build -tags=jsoniter -a -installsuffix cgo -o /go/bin/server . | |
FROM alpine:3.7 | |
WORKDIR / | |
COPY --from=builder /go/bin/server /server | |
ENTRYPOINT ["/server"] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment