Permalink
Browse files

Update Dockerfile to benefit build cache

Docker has recently introduces buikld-stages (as of version 17.05)

Build stages allows to benefit the docker build cache as well as
reducing the size of the resulting image c.f.
https://docs.docker.com/engine/userguide/eng-image/multistage-build/

This change allows to have faster builds when running `docker build`
several times after changing some little code

Signed-off-by: Thibault Jamet <tjamet@users.noreply.github.com>
  • Loading branch information...
tjamet authored and anthonyfok committed Sep 7, 2017
1 parent a3a3f5b commit 09d960f17396eb7fd2c8fe6527db9503d59f0b4f
Showing with 10 additions and 22 deletions.
  1. +10 −22 Dockerfile
View
@@ -1,30 +1,18 @@
FROM alpine:3.6
FROM golang:1.9.0-alpine3.6 AS build
ENV GOPATH /go
ENV PATH $GOPATH/bin:$PATH
RUN apk add --no-cache --virtual git musl-dev
RUN go get github.com/kardianos/govendor
RUN govendor get github.com/gohugoio/hugo
WORKDIR /go/src/github.com/gohugoio/hugo
RUN rm -f $GOPATH/bin/hugo
RUN go install -ldflags '-s -w'
FROM alpine:3.6
RUN \
adduser -h /site -s /sbin/nologin -u 1000 -D hugo && \
apk add --no-cache \
dumb-init && \
apk add --no-cache --virtual .build-deps \
gcc \
musl-dev \
go \
git && \
mkdir -p \
${GOPATH}/bin \
${GOPATH}/pkg \
${GOPATH}/src && \
go get github.com/kardianos/govendor && \
govendor get github.com/gohugoio/hugo && \
cd $GOPATH/src/github.com/gohugoio/hugo && \
rm -f $GOPATH/bin/hugo && \
go install -ldflags '-s -w' && \
cd $GOPATH && \
rm -rf pkg src .cache bin/govendor && \
apk del .build-deps
dumb-init
COPY --from=build /go/bin/hugo /bin/hugo
USER hugo
WORKDIR /site
VOLUME /site

0 comments on commit 09d960f

Please sign in to comment.