bitcastza / mumbleice

GNU General Public License v3.0
3 stars 1 forks source link

feat: Reduce container image size #26

Closed vitoyucepi closed 1 month ago

vitoyucepi commented 2 months ago

Summary

I've noticed the main two problems of the bitcast/mumbleice:dev container image

  1. enormous size;
  2. not working.

I want to reduce the size by using an alpine container image. Make it work.

Details

Here's the image size chart image size
python:3.11 1.01GB
python:3.11 + ffmpeg 1.39GB
python:3.11-slim 130MB
python:3.11-slim + ffmpeg 603MB
python:3.11-alpine 52.5MB
python:3.11-alpine + ffmpeg 179MB
alpine:3.19 7.4MB
alpine:3.19 + python + ffmpeg 168MB

I use python:3.11-slim because pymumble is incompatible with python:3.12-slim. ~For the same reason, I use alpine:3.19.~

The python:3.11-slim almost always provides the smaller image without significant changes to the container file, ~but python:3.11-alpine will give an even smaller image when you can properly configure it.~ ~It would be sufficient to use python:3.11-alpine for my purpose, but it has a long-living problem with find_library, so I have to use alpine:3.19 instead.~

I think that using venv and multi-staged build is one of the most space-efficient ways to containerize a Python application. So, the resulting image is 614MB ~164MB - 10 times less than before~.

Additionally

It's possible to specify the STOPSIGNAL SIGINT so the container will stop gracefully, but this problem should be a part of another PR that will add proper signal handling. https://github.com/bitcastza/mumbleice/blob/bfc20b1058b9197fdea728bd0c48309c6a19eab8/mumbleice/bot.py#L65-L71

paddatrapper commented 2 months ago

Thanks for this. I definitely would like to ensure it is working, but I want to keep the Debian base - it makes it much easier for me to maintain because I understand Debian's process much better than Alpine

vitoyucepi commented 2 months ago

but I want to keep the Debian base

Could you give some insight on how to reduce the footprint of ffmpeg in Debian without recompiling the whole package? Basically, I can do the same Dockerfile, but with python:3.11-slim and 3.5x size.

ensure it is working

I think the provided container image has stopped working since 12d8592b9d3f619361860ee0b839f98263f6abfb. By the way, I've built my own container image on alpine:3.20 with ad-hoc packages and custom patches. And the application works, mostly.

paddatrapper commented 1 month ago

Could you give some insight on how to reduce the footprint of ffmpeg in Debian without recompiling the whole package? Basically, I can do the same Dockerfile, but with python:3.11-slim and 3.5x size.

I would do just that - use 3.11-slim and install ffmpeg from Debian repos. You can remove the apt cache directory /var/lib/apt/lists/* to reduce the size a bit

vitoyucepi commented 1 month ago

Hi @paddatrapper, I've updated the PR, so you could check it.

paddatrapper commented 1 month ago

Thanks! LGTM

github-actions[bot] commented 1 month ago

:tada: This PR is included in version 1.5.0 :tada:

The release is available on GitHub release

Your semantic-release bot :package::rocket: