python-discord / snekbox

Easy, safe evaluation of arbitrary Python code
https://pythondiscord.com
MIT License
214 stars 39 forks source link

Install Multiple Python Versions in the Image #181

Closed MarkKoz closed 1 year ago

MarkKoz commented 1 year ago

158

This is an alternative implementation to #175

This just focuses on getting multiple Python interpreter versions into the image. There will be a follow-up PR with the API changes. The goal for the API is for users to be able to pass an arbitrary path to an executable binary (e.g. a path to a different Python interpreter).

See the changes in .github/CONTRIBUTING.md for an overview of how multiple Python versions are managed.

du -h --max-depth=1 /lang/python
93M /lang/python/3.11
88M /lang/python/3.12
181M    /lang/python
REPOSITORY                            TAG         IMAGE ID       CREATED              SIZE
ghcr.io/python-discord/snekbox        latest      77b91b95f4da   About a minute ago   511MB
ghcr.io/python-discord/snekbox-venv   dev         7fc66456bbdd   26 minutes ago       600MB

I observed smaller sizes (~70 MB) on Debian 12 (bookworm), but I've had trouble with test failures on bookworm, so the image remains on Debian 11 (buster) for now. About a third of the size seems to be occupied by the shared library.

du -h /lang/python/3.11/lib/libpython3.11.so.1.0
32M /lang/python/3.11/lib/libpython3.11.so.1.0

If anyone knows of additional compiler flags or configuration options to bring down the size, please share!

Each Python interpreter build takes around 6 minutes, and that's with full optimisation enabled. Thankfully each build stage can run in parallel.

coveralls commented 1 year ago

Coverage Status

coverage: 90.845%. remained the same when pulling 0b0b0fd76f50e5d69e9acfc5473216456b4ef630 on feat/158/multi-version into 38885785334c5b77748f1b4767ef44124cb4dd3f on main.

ChrisLovering commented 1 year ago

FWIW, I think this is a good approach as far as the image is concerned.