Skip to content

Commit 09d960f

Browse files
tjametanthonyfok
authored andcommitted
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>
1 parent a3a3f5b commit 09d960f

File tree

1 file changed

+10
-22
lines changed

1 file changed

+10
-22
lines changed

‎Dockerfile‎

Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,18 @@
1-
FROM alpine:3.6
1+
FROM golang:1.9.0-alpine3.6 AS build
22

3-
ENV GOPATH /go
4-
ENV PATH $GOPATH/bin:$PATH
3+
RUN apk add --no-cache --virtual git musl-dev
4+
RUN go get github.com/kardianos/govendor
5+
RUN govendor get github.com/gohugoio/hugo
6+
WORKDIR /go/src/github.com/gohugoio/hugo
7+
RUN rm -f $GOPATH/bin/hugo
8+
RUN go install -ldflags '-s -w'
59

10+
FROM alpine:3.6
611
RUN \
712
adduser -h /site -s /sbin/nologin -u 1000 -D hugo && \
813
apk add --no-cache \
9-
dumb-init && \
10-
apk add --no-cache --virtual .build-deps \
11-
gcc \
12-
musl-dev \
13-
go \
14-
git && \
15-
mkdir -p \
16-
${GOPATH}/bin \
17-
${GOPATH}/pkg \
18-
${GOPATH}/src && \
19-
go get github.com/kardianos/govendor && \
20-
govendor get github.com/gohugoio/hugo && \
21-
cd $GOPATH/src/github.com/gohugoio/hugo && \
22-
rm -f $GOPATH/bin/hugo && \
23-
go install -ldflags '-s -w' && \
24-
cd $GOPATH && \
25-
rm -rf pkg src .cache bin/govendor && \
26-
apk del .build-deps
27-
14+
dumb-init
15+
COPY --from=build /go/bin/hugo /bin/hugo
2816
USER hugo
2917
WORKDIR /site
3018
VOLUME /site

0 commit comments

Comments
 (0)