Merge pull request #374 from ilyaglow/docker-multistage

Improve Dockerfile
This commit is contained in:
Jimmy Zelinskie 2017-12-20 10:05:31 -05:00 committed by GitHub
commit ff269b0f44
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,5 +1,5 @@
FROM golang:alpine
MAINTAINER Jimmy Zelinskie <jimmyzelinskie@gmail.com>
FROM golang:alpine AS build-env
LABEL maintainer "Jimmy Zelinskie <jimmyzelinskie@gmail.com>"
# Install OS-level dependencies.
RUN apk update && \
@ -8,16 +8,21 @@ RUN apk update && \
# Copy our source code into the container.
WORKDIR /go/src/github.com/chihaya/chihaya
ADD . /go/src/github.com/chihaya/chihaya
COPY . /go/src/github.com/chihaya/chihaya
# Install our golang dependencies and compile our binary.
RUN glide install
RUN go install github.com/chihaya/chihaya/cmd/chihaya
RUN CGO_ENABLED=0 go install github.com/chihaya/chihaya/cmd/chihaya
# Delete the compiler from the container.
# This makes the container much smaller when using Quay's squashing feature.
RUN rm -r /usr/local/go
FROM alpine:latest
COPY --from=build-env /go/bin/chihaya /chihaya
RUN adduser -D chihaya
# Expose a docker interface to our binary.
EXPOSE 6880 6881
ENTRYPOINT ["chihaya"]
# Drop root privileges
USER chihaya
ENTRYPOINT ["/chihaya"]