-
Notifications
You must be signed in to change notification settings - Fork 527
chore: move go mod download before copy source in Dockerfile #3460
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
chore: move go mod download before copy source in Dockerfile #3460
Conversation
Signed-off-by: fscnick <[email protected]>
Sorry I'm not that familiar with golang, just for my own curiosity, could you please elaborate a little bit on the problem you've seen? thank you! |
Usually, the modification of deps is less frequent than the modification of source code. In the origin Dockerfile, Lines 9 to 17 in 37cf2ac
go mod download is after copying the go source. Once source files has changed. the docker build will re-run go mod download without leveraging the cache.
Thus, move kuberay/ray-operator/Dockerfile Lines 6 to 10 in 37cf2ac
In addition, it copies Lines 96 to 99 in 37cf2ac
Kindly let me know if there is something unclear or wrong. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the detailed explanation! I think it makes sense a lot.
Could you please at least add the docker layer part into PR description? I didn't get it at first sight. Thank you a ton!
COPY ray-operator/go.sum ray-operator/go.sum | ||
|
||
# cache deps before building and copying source so that we don't need to re-download as much | ||
# and so that source changes don't invalidate our downloaded layer |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel like it's a recommended practice, to download all dependencies right after we figure out the go.mod`.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The change makes sense to me, but I'm curious about the difference between (1) the build time for updating the KubeRay API server source code without this PR, and (2) the build time for updating the KubeRay API server source code with this PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you!
…ject#3460) Signed-off-by: fscnick <[email protected]>
Why are these changes needed?
To avoid downloading dependences after changing the source file, move
go mod download
up before copying source files.In docker build, the cache depends on the previous layer. Which means the upper layer has changed, the following layers are subject to re-build.
Usually, the modification of deps is less frequent than the modification of source code. In the origin Dockerfile,
kuberay/apiserver/Dockerfile
Lines 9 to 17 in 37cf2ac
go mod download
is after copying the go source. Once source files has changed. the docker build will re-rungo mod download
without leveraging the cache.Thus, move
go mod download
before the copying the go source.Related issue number
Checks