How to download all dependencies with vgo and a given go.mod?
tl;dr: In current go master and in future go releases, go mod download
will do this job. For now you need a hack.
On the gophers slack, I was referred to this issue: https://github.com/golang/go/issues/26610 where I learned that this would do more or less what I want (assuming here that you're using go version 1.11beta3):
# Populate the module cache based on the go.{mod,sum} files.
COPY go.mod .
COPY go.sum .
RUN go list -e $(go list -f '{{.Path}}' -m all)
Later in the thread, Russ Cox implements go mod download
, which will be available in the next release of go
, allowing me to remove the silly go list
hack above.
update: go mod download
is now widely available and you should use it on go 1.12 and later