-
Notifications
You must be signed in to change notification settings - Fork 17.7k
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: narrow 'mod download' default set #44435
Comments
For clarity, right now Note that we would still need to download go.mod files for something like the whole original set, |
Based on the discussion above, this proposal seems like a likely accept. |
I think that this would break the cache warming case for when you only have This case is common when building docker containers as it allows you to populate a module cache before you copy the code in. If the module cache state is solely dependent on the code (which is what It seemed like based on #45551 (comment) that this was a supported case and would actually be improving in the future, but cc @jayconrod |
@zikaeroh, if you're setting up a fast Docker builder, you probably want to prime the build cache too — not just the module cache. In that case, you would either want to Or, to put it another way: if you're ok with wasting some space on the build image (as you would be with |
In my experience, getting the 2 GB of dependencies my project needs (or about 1 GB non-test) is much, much more time consuming than the actual build itself.
Unfortunately, docker can't work this way. The build context for docker is based on the current file system. I can't pre-copy a different version (which version?) of the code into the container when building because there's only one version; the current one. If I make any change to the source code, any layer that depended on it is invalidated, hence why I only copy in Note that I'm not "wasting space"; I build the binary, then copy it to another image (see: https://github.com/hortbot/hortbot/blob/master/Dockerfile). In this case, the only "waste" is the cache that'd on the builder (versus where the image runs), which is what I want to happen anyway. This is a common pattern when building docker images with compiled code; there's no reason to ship the source, the Go compiler, caches, etc. |
It can work that way: use an old version of your build stage as the base image for your newer builds. (Note newer The "wasting space" refers to your build stage, which you are obviously caching to be able to reuse it. In most cases an old copy of your code + accurate dependencies takes up less space than the extended set of dependencies. The wasted space also translates to longer build times if your CI is stateless as it now needs to restore/save larger caches from a remote |
If you believe it can be done, then I would appreciate some sort of example to look at; I'm having a hard time conceptualizing how that would work without shifting the caching responsibility to me or extra scripts (managing which parent image I'm using when that's encoded in Dockerfile, removing old items, etc) or breaking statelessness (some at-build volume). It seems like a shame to have to be managing all of this when it was so simple to achieve before following only docker's best practices documentation. |
This is only about changing the default for |
This proposal has been added to the active column of the proposals project |
@rsc I understand
This would not break anybody‘s builds (and even get rid of the parsing step?)- are there negative side effects? |
If the definition of "what's listed in go.mod" is that it will download only the modules listed in go.mod and none of their dependencies (as "all deps and their deps" is the old behavior), then the effect of that change would be to change over-warming to under-warming, as the rest of the dependencies would be pulled in at some future step, probably during The only way to avoid the unpredictability would be to bump the module to 1.17 to enable lazy loading and the extra entries in go.mod (which I'm not sure all projects will do given the misconceptions/lack of clarity around what the version actually indicates; #46201, #30791). |
Or, conversely: to only enable the new |
I like the idea of making the change contingent on the I agree that |
OK, so it sounds like we are converging on changing the 'mod download' set for go.mod that use module graph pruning (go 1.17+), but this feature would ship in Go 1.18 since we are already in the Go 1.17 freeze. Do I have that right? |
Based on the discussion above, this proposal seems like a likely accept. |
No change in consensus, so accepted. 🎉 |
Change https://golang.org/cl/357310 mentions this issue: |
Context
go mod download
is often used in build systems to "warm the cache" so subsequent operations don't need to fetch any more data. However, it can currently download more than expected. See #41431.In #41431 (comment), @bcmills suggests using
go list -test -deps ./...
instead. This would only fetch only the modules transitively imported by packages in the main module.A similar suggestion of
go list -test all
was made recently in the Gophers slack.Proposal
This issue proposes changing the default selection for
go mod download
to matchgo list all
. This would makego mod download
more intuitive for the cache-warming case which typically does not involve needing dependencies' test dependencies.The current selection could be moved to a flag if necessary.
The text was updated successfully, but these errors were encountered: