Closed amayer5125 closed 3 days ago
Thank you for you suggestion on improvement.
I try and not to modify the default PATH
variable, as it changes the expected location of files.
Do you think there could be another approach in reducing the files? Could the wheel files be related (even though directory is removed)?
The PATH changes I make are the same thing a python virtual environment does when you run the activate script. I do append the existing PATH after the virtual environment location so any commands outside of the virtual environment should still work as expected.
The size difference almost certainly has to do with the wheel files from the COPY --from=build /wheel /wheel
line. That line copies the files to the image and creates a new layer. The subsequent line starts a new layer and runs rm -rf /wheel
which only deletes the files in the new layer. They still exist in the previous layer though, so they contribute to the overall size of the image. I cannot think of a way to copy the files into the new image for the duration of the install and then delete them.
I see what you mean.
Quickly looking, there may be something with RUN --mount
that is suggested https://stackoverflow.com/a/76670359, which sounds promising. I have yet to try it myself though.
I did some reading on --mount
. If you do not want to use virtual environments for the image I think it is a great alternative to reduce the size. Switching from COPY
to --mount
only saved about 21MB. I did some of the other refactors I did in this pull request and got the image size down way farther.
Here are my test results:
REPOSITORY TAG IMAGE ID CREATED SIZE
errbotio/errbot venv e2ceb54767df 34 seconds ago 216MB
errbotio/errbot mount-refactor 1f06e5451f5d 12 minutes ago 211MB
errbotio/errbot mount cb5f34d5318e 25 minutes ago 305MB
errbotio/errbot master 6d3c52d7d1b6 34 minutes ago 326MB
Built off of master with no modifications.
Remove COPY --from=build /wheel /wheel
line and add --mount=from=build,source=/wheel,target=/wheel
to the pip install line.
Same as mount tag, plus removed apt install git
, use python:3.9 image for build, and remove unneeded FROM base
.
This current pull request built with python:3.9 build stage and python:3.9-slim final image.
@amayer5125 Thank you for all the work with this. merging.
Use a virtual environment to make copying packages from build stage to the final stage easier. It also reduces the image size by 94Mb.
I used
python:3-slim
as the final image. Previously we were usingpython:3.9-slim
. I think using the newer python version is a good idea, but I can change it back if we don't want to use the newer version.Size comparison: