Skip to content

Instantly share code, notes, and snippets.

@cjimti
Created June 25, 2018 02:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cjimti/c988db3ff1a798eb3e18d76f3d71e75a to your computer and use it in GitHub Desktop.
Save cjimti/c988db3ff1a798eb3e18d76f3d71e75a to your computer and use it in GitHub Desktop.
Golang Microservice Dockerfile boilerplate
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