-
Notifications
You must be signed in to change notification settings - Fork 24
chore: optimize example docker files using multi-stage builds #232
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: optimize example docker files using multi-stage builds #232
Conversation
@vigith @kohlisid - I successfully reduced image size by 60% (from ~971MB to ~385MB) by fixing the broken multi-stage builds in all 17 Dockerfiles. The optimization removes build tools from final images while maintaining full functionality. |
The jobs are failing with the following error, please run
|
pyproject.toml
Outdated
aiorun = "^2023.7" | ||
uvloop = "^0.19.0" | ||
psutil = "^6.0.0" | ||
numpy = "^1.26.0" |
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.
why would you want to add numpy
?
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.
why would you want to add
numpy
?
Thank you for catching that! I had temporarily added numpy while testing one of the examples, but it’s not actually required for any of the examples or the project itself. I’ve now removed it from pyproject.toml and updated the lock file accordingly.
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #232 +/- ##
=======================================
Coverage 94.26% 94.26%
=======================================
Files 60 60
Lines 2441 2441
Branches 124 124
=======================================
Hits 2301 2301
Misses 101 101
Partials 39 39 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
could you please run |
|
@sapkota-aayush You can use the inbuild |
I wasn’t able to run make lint directly because of some setup issues, but I manually fixed the formatting errors with Black and double-checked everything looks good now. That should take care of the lint errors. Whenever you get a chance, maybe you could suggest the best way to run make lint on my setup? Thanks! |
looks like it ran successfully now. |
You can try to setup a virtual env for the project, and install the required dependencies from the project toml file |
Thanks @vigith Appreciate the tip @kohlisid — I’ll try setting up the virtual environment properly for smoother runs next time. Also noticed that even after optimizing the Dockerfile size, each UDF still takes over 2 mins to build, which feels a bit much. Not sure if there’s a better way — maybe we could try caching or something else to speed it up? Open to any suggestions — just trying to streamline things a bit. Appreciate the help as always! |
did you look into #181 (comment) ? |
@sapkota-aayush We can try to divide it into three multi stage layers
Then for each we can look at specific optimizations |
Thanks for the suggestion Sid! Working on it, breaking it into Base, Env Setup, and Builder stages makes a lot of sense. Will follow up soon with progress and results. Appreciate the input! |
c72542b
to
d6cbcb7
Compare
…ilds Signed-off-by: sapkota-aayush <[email protected]>
Signed-off-by: sapkota-aayush <[email protected]>
Signed-off-by: sapkota-aayush <[email protected]>
Signed-off-by: sapkota-aayush <[email protected]>
Signed-off-by: sapkota-aayush <[email protected]>
…fix cross-platform issues Signed-off-by: sapkota-aayush <[email protected]>
d6cbcb7
to
6ef3117
Compare
@vigith @kohlisid |
…rror Signed-off-by: sapkota-aayush <[email protected]>
Signed-off-by: sapkota-aayush <[email protected]>
@sapkota-aayush Have you tested the new images end-to-end by running in a pipeline? |
Yes, I have tested the new images end-to-end by running them in a Numaflow pipeline on Kubernetes. |
Signed-off-by: sapkota-aayush <[email protected]>
Thanks for taking it up and the collaboration on this @sapkota-aayush :D |
Thank you @vigith and @kohlisid for your guidance. Learned a lot. |
Optimize example Dockerfiles - Reduce image size by 60%
Fixed broken multi-stage builds in all 17 example Dockerfiles by changing FROM builder AS udf to FROM python:3.10-slim-bullseye AS udf. This removes build tools (gcc, git, build-essential, Poetry) from final images and only copies the virtual environment and application code.
Results
Before: ~971MB images (with build tools)
After: ~385MB images (clean runtime only)
Improvement: 60% size reduction (586MB saved per image)
Testing
Verified with examples/reduce/counter/Dockerfile - build tools successfully removed, functionality preserved.
Files Changed
All 17 example Dockerfiles across map, reduce, sink, source, and sourcetransform categories.
Closes #181