Split go build in Dockerfile
authorThibault Jamet <tjamet@users.noreply.github.com>
Thu, 7 Sep 2017 13:17:44 +0000 (15:17 +0200)
committerAnthony Fok <foka@debian.org>
Mon, 25 Sep 2017 16:28:13 +0000 (10:28 -0600)
To maximize the usage of cache, split the govendor get in steps:
- govendor fetch to get the pinned versions of dependencies
- go install to actually build the binary

Doing so allows not to re-download the whole dependencies when changing
lines in hugo repository

The current Dockerfile generates an image of 16.6MB

Signed-off-by: Thibault Jamet <tjamet@users.noreply.github.com>
Dockerfile

index ca165a986b934e333b815cefb76055aa9de7ce00..e0da7d83401161aef85ebb4438a94956da7830b5 100644 (file)
@@ -2,9 +2,11 @@ FROM golang:1.9.0-alpine3.6 AS build
 
 RUN apk add --no-cache --virtual git musl-dev
 RUN go get github.com/kardianos/govendor
-RUN govendor get github.com/gohugoio/hugo
+
+ADD vendor/vendor.json /go/src/github.com/gohugoio/hugo/vendor/vendor.json
 WORKDIR /go/src/github.com/gohugoio/hugo
-RUN rm -f $GOPATH/bin/hugo
+RUN govendor sync
+ADD . /go/src/github.com/gohugoio/hugo/
 RUN go install -ldflags '-s -w'
 
 FROM alpine:3.6