-
Notifications
You must be signed in to change notification settings - Fork 17.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
cmd/go: add go mod download to download modules #26610
Comments
go mod
vendor requires more than just go.modgo mod -vendor
requires more than just go.mod
content
Can you include some more detail about your use-case? (Why is that a thing you want to do?) |
@bcmills Sure. Let's say that you have your code build a Docker image on every git change (most pipelines do this and is probably the biggest use case).
|
Vendor is tailored for the dependencies of a specific module, Go modules have an actual cache, separate from the vendor directory.
That will trigger a download of every module from go.mod |
@rsc Hmm.. I'll give that a try. Is there a reason why this isn't a base |
@rsc: Your cache warming suggestion doesn't work out of the box. The fixed version is below:
Edit: Nope that doesn't work either fully. This should be working though (may need escaping for
^ this is really not something that should be found in Dockerfiles Edit 2 Third iteration that is the least messy so far:
IMO, If this seems like something that should be used often, it probably needs to get into the main CLI. As a sidenote to this hack, |
All the commands downloads modules as needed. That said, it seems to me that |
go mod -vendor
requires more than just go.mod
content
I got pretty close with #26610 (comment). To make this work for now, I am using the following Dockerfile: FROM golang as builder
RUN go get -u golang.org/x/vgo
WORKDIR /go/src/github.com/$ORG/$REPO
# Populate the module cache based on the go.{mod,sum} files.
COPY go.mod .
COPY go.sum .
RUN vgo list -e $(vgo list -f '{{.Path}}' -m all)
# Build all binaries, with -getmode=local, this will _not_ fetch packages over the network.
COPY . .
RUN vgo install -getmode=local ./...
# Runtime image
FROM alpine AS base
COPY --from=builder /go/bin/$PROG /bin/$PROG
ENTRYPOINT ["/bin/$PROG"] |
@moretea This takes care of caching downloads but if I add |
Small update for those that are using the |
@marwan-at-work I don't know why that issue would be abandoned 😢. Maybe it's because the v1.11 GA release date is tomorrow? As for using stdout, that's what the interim fix uses but it would be nice not to need Edit: Your PR looked fine to be tbh - I don't really understand the current stdout/stderr separation if stderr shows informational messages. |
@marwan-at-work I closed the CL based on our discussion, yes. Did I prematurely close it? Was there something I missed? @sgnn7 as things stand, stdout is defined to contain the JSON output; stderr informational messages, with the exit code ultimately used to then determine success or otherwise (with the caveat that Does that help to clarify things? |
@myitcv Makes sense though I wouldn't say that it increases simplicity/usability cases (compared to most other *nix tooling). Either way, this issue is not for that discussion and thank you for the clarification. 👍 |
I started looking at go get -d -m but it's a weird combination to redefine.
to warm a Docker image cache. |
Change https://golang.org/cl/128355 mentions this issue: |
There is a caveat here, you must have a main package in the directory with go.mod for |
@zangbuild no longer the case with go1.12, there's already a beta out if you want to give it a shot. |
Nice. I will try when I can. |
Does Edit: Will this do the what I want? |
@mbana |
Hi, related question: is there a |
@mcluseau, the |
So just to follow up, the best way I've found considering that is to use a Go proxy (athens) and the following from golang:1.12.1-alpine3.9 as build
run apk add --update git
env CGO_ENABLED=0
arg GOPROXY
workdir /src
add go.mod go.sum ./
run go mod download
add . ./
run go test ./...
run go install . ./cmd/...
from alpine:3.9
#entrypoint ...
copy --from=build /go/bin/ /bin/ |
More information about the issue can be found at: golang/go#26610
More information about the issue can be found at: golang/go#26610
is $ go mod download
.... [indeed download majority, maybe 99% of dependencies]
$ go build ...
..... [ but it still leaked a few to go build ... ]
go: finding github.com/alecthomas/template latest
go: downloading github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc
go: finding github.com/alecthomas/units latest
go: downloading github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf
go: extracting github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf
go: extracting github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc I'm not sure does this mean |
@c0b, if all dependencies are declared (that is, if If you find that is not the case, please open a new issue with steps to reproduce (ideally using |
More information about the issue can be found at: golang/go#26610
More information about the issue can be found at: golang/go#26610
So yeah
or
whatever, o/w I am just watching the command hang there forever, hoping that nothing is wrong. some feedback would be nice, like with |
What version of Go are you using (
go version
)?go1.11beta2
Does this issue reproduce with the latest release?
Yes (
1.11beta2
)What operating system and processor architecture are you using (
go env
)?amd64 - linux
What did you do?
Copying just
go.mod
into an empty directory should allowgo mod -vendor
(or maybe evengo mod -sync
) to download the dependencies regardless of having any other files within the directory. Without this, you cannot use something like Docker to cache the dependencies independent of the codebase itself.What did you expect to see?
go mod
should have downloadedgo.mod
dependencies based ongo.mod
content regardless if there's code in the repo or not.What did you see instead?
Neither
go mod -vendor
norgo mod -sync
downloaded anything.The text was updated successfully, but these errors were encountered: