How to download all dependencies with vgo and a given go.mod?

Multi tool use
Multi tool use


How to download all dependencies with vgo and a given go.mod?



I'm working on a go project, using vgo, with a Dockerfile, and I'd like docker to cache the dependencies of the project such that it has two properties:


go.mod


go.mod



Right now, I do:


...
RUN go get -u golang.org/x/vgo
COPY . /go/src/whatever
RUN vgo install
...



But if you change a go file, the dockerfile will have to be rebuilt from the COPY layer onwards.


COPY



What I'd like, in short, is to do:


...
RUN go get -u golang.org/x/vgo
COPY go.mod /go/src/whatever
RUN vgo install_dependencies
COPY . /go/src/whatever
RUN vgo install
...



That way, if I change go.mod, all the dependencies will be downloaded and rebuilt, but otherwise, we can proceed right to building the binary.


go.mod



I can see a couple of ways to get behavior like this, but all of them have drawbacks:


$GOPATH/src/mod


vgo mod -vendor


vgo mod -vendor


go.mod


vgo mod -vendor



Can you think of a way for me to get behavior like my imaginary vgo install_dependencies? Am I missing a vgo trick to do so?


vgo install_dependencies





Maybe I'm missing something, but why can't you run vgo mod -vendor as a Dockerfile command?
– Tim Cooper
Jul 1 at 20:57


vgo mod -vendor





@TimCooper for that to work I think I need the whole directory copied to the docker image, which means it’ll re-run every time I modify a go file, even if it doesn’t change any imports
– llimllib
Jul 2 at 0:14





@TimCooper verified, if you try it with only a go.mod file in a directory you get vgo: no dependencies to vendor
– llimllib
Jul 2 at 0:22


vgo: no dependencies to vendor









By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

iOaE6f PZINU6Rj1rBer,H G,cz,oF6a3jcS96Ud71HfWOM0zG i0dev CHP5CwF,R6
MrNnZLszB1ETKDlD9fAeaQgU5,spZc,1At fM,jw9Iqlsw8PJ9mi4L L

Popular posts from this blog

Rothschild family

Cinema of Italy