Use Docker multi-stage builds to reduce final docker image size

For second stage use https://github.com/GoogleCloudPlatform/distroless which provides a minimal image with CA certificates.
Binary is compiled with CGO_ENABLED=0 to prevent dynamical linking to any libraries.
This commit is contained in:
Łukasz Mierzwa
2017-08-09 21:54:23 -07:00
parent 577c15ee77
commit 2a76843700
2 changed files with 7 additions and 12 deletions

View File

@@ -1,16 +1,11 @@
FROM golang:1.8.3-alpine
FROM golang:1.8.3-alpine3.6 as unsee-builder
COPY . /go/src/github.com/cloudflare/unsee
ARG VERSION
RUN apk add --update make git nodejs nodejs-npm
RUN CGO_ENABLED=0 make -C /go/src/github.com/cloudflare/unsee VERSION="${VERSION:-dev}" unsee
RUN apk add --update --no-cache --virtual .build-dependencies \
make git nodejs && \
make -C /go/src/github.com/cloudflare/unsee VERSION="${VERSION:-dev}" && \
mv /go/src/github.com/cloudflare/unsee/unsee /bin/unsee && \
rm -fr /go/src && \
apk del .build-dependencies
FROM gcr.io/distroless/base
COPY --from=unsee-builder /go/src/github.com/cloudflare/unsee/unsee /unsee
EXPOSE 8080
CMD ["unsee"]
CMD ["/unsee"]

View File

@@ -71,7 +71,7 @@ run: $(NAME)
./$(NAME)
.PHONY: docker-image
docker-image: bindata_assetfs.go
docker-image:
docker build --build-arg VERSION=$(VERSION) -t $(NAME):$(VERSION) .
.PHONY: run-docker