Skip to content
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

feat : use --no-cache-dir flag to pip in dockerfiles to save space #512

Merged

Conversation

Rajpratik71
Copy link
Contributor

using the "--no-cache-dir" flag in pip install, make sure downloaded packages by pip don't cache on the system. This is a best practice that makes sure to fetch from a repo instead of using a local cached one. Further, in the case of Docker Containers, by restricting caching, we can reduce image size. In terms of stats, it depends upon the number of python packages multiplied by their respective size. e.g for heavy packages with a lot of dependencies it reduces a lot by don't cache pip packages.

Further, more detailed information can be found at

https://medium.com/sciforce/strategies-of-docker-images-optimization-2ca9cc5719b6

Signed-off-by: Pratik Raj Rajpratik71@gmail.com

  • I agree to contribute to the project under Apache 2 License.
  • To the best of my knowledge, the proposed patch is not based on a code under GPL or other license that is incompatible with FlexMeasures

@coveralls
Copy link
Collaborator

coveralls commented Oct 10, 2022

Pull Request Test Coverage Report for Build 3227950674

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.02%) to 65.032%

Totals Coverage Status
Change from base Build 3161787563: 0.02%
Covered Lines: 6480
Relevant Lines: 9358

💛 - Coveralls

@nhoening nhoening self-requested a review October 10, 2022 14:41
@nhoening nhoening added this to the 0.12.0 milestone Oct 10, 2022
@nhoening
Copy link
Contributor

Thanks for your PR, @Rajpratik71!

I can confirm this saves 300MB on a ~2GB image.

I also ran tests within that image and they passed - so this seems good to me :)

On another note, I read the article and also tried saving space on apt-get install. With --no-install-recommends, I saved another 300 MB (removing and purging afterwards only saved ~40 MB I think). That image also tested well.

If you want, you can add that to this PR to complete the reduction :)

Finally, I'd like to mention this in documentation/changelog.rst under "Infrastructure / Support", like this:

* Reduce size of Docker image (from 2GB o 1.4GB) [see `PR #512 <http://www.github.com/FlexMeasures/flexmeasures/pull/512>`_]

If you could add that line I'd appreciate it. Otherwise, I'll do it later.

@Rajpratik71
Copy link
Contributor Author

Thanks for your PR, @Rajpratik71!

I can confirm this saves 300MB on a ~2GB image.

I also ran tests within that image and they passed - so this seems good to me :)

On another note, I read the article and also tried saving space on apt-get install. With --no-install-recommends, I saved another 300 MB (removing and purging afterwards only saved ~40 MB I think). That image also tested well.

If you want, you can add that to this PR to complete the reduction :)

Finally, I'd like to mention this in documentation/changelog.rst under "Infrastructure / Support", like this:

* Reduce size of Docker image (from 2GB o 1.4GB) [see `PR #512 <http://www.github.com/FlexMeasures/flexmeasures/pull/512>`_]

If you could add that line I'd appreciate it. Otherwise, I'll do it later.

Sure @nhoening , I will add.

using the "--no-cache-dir" flag in pip install, make sure downloaded packages
by pip don't cache on the system. This is a best practice that makes sure
to fetch from a repo instead of using a local cached one. Further, in the case
of Docker Containers, by restricting caching, we can reduce image size.
In terms of stats, it depends upon the number of python packages
multiplied by their respective size. e.g for heavy packages with a lot
of dependencies it reduces a lot by don't cache pip packages.

Further, more detailed information can be found at

https://medium.com/sciforce/strategies-of-docker-images-optimization-2ca9cc5719b6

Signed-off-by: Pratik Raj <Rajpratik71@gmail.com>
@nhoening
Copy link
Contributor

Thanks. I'll test the combined Docker image but I don't expect issues

@nhoening nhoening merged commit 75db997 into FlexMeasures:main Oct 11, 2022
@Rajpratik71 Rajpratik71 deleted the optimization/pip-no-cache-dir branch October 14, 2022 12:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants