-
-
Notifications
You must be signed in to change notification settings - Fork 1.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
Optimize Dockerfiles #4532
Optimize Dockerfiles #4532
Conversation
e7da948
to
ace607b
Compare
Saving a lot of layers at the top is not that efficiënt i think. |
ace607b
to
1325a13
Compare
Fair enough, if there's stuff here that you don't like just tell me and I'll remove it. I've been running my builds for a while with these changes and I figured other people might benefit from them as well. |
Do you build all arch's? |
amd64 and arm64, both for personal use |
A good tool to check this PR is https://github.com/wagoodman/dive |
I use that too indeed. But that will only work for the final image, not for the build layer. |
What do you guys think about including this as well for apt? |
It doesn't really add anything useful i think. Also, docker buildx does some nice caching by it self. And we already use build caches during our release pipeline. We used that before btw, which was useful back then, and not building in parallel. When building in parallel it gave some issues, which can be solved, but then it loses its benefits. |
While optimizing for layers does not have any benefit for the build part, it also doesn't hurt in this case. |
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.
Looks fine by me.
Move some ARGs closer to the build stage (potentially improving caching) Remove redundant COPY commands Remove redundant RUN command Move CARGO_HOME's "&&" operator to the first line (improves consistency)
1325a13
to
e1a5baf
Compare
Move some ARGs closer to the build stage (potentially improving caching):
Example: I usually set VW_VERSION to be the latest commit hash, without this change I'd have to also rebuild the dependencies even if they didn't change since the previous layers would get invalidated.
Remove redundant COPY commands:
They can be combined, no point in using extra layers if it can be avoided.
Remove redundant RUN command:
apt-get and xx-apt-get commands can be moved into the same RUN command, thus saving another layer.
Move CARGO_HOME's "&&" operator to the first line (improves consistency)