aaronwmorris / indi-allsky

Software to manage a Linux-based All Sky Camera.
GNU General Public License v3.0
252 stars 41 forks source link

docker: gunicorn: base on python:3.11 and shave 4gb off the image #1622

Closed USA-RedDragon closed 1 week ago

USA-RedDragon commented 1 week ago

This patch reduces the final size of the gunicorn image from a whopping 5.4GB down to 1.4GB. The Python dependencies alone take up 1.1GB (/usr/local/lib/python3.11/site-packages).

aaronwmorris commented 1 week ago

I think this image could be made even more simple. indilib has not been a requirement for the gunicorn process for a while, I just never revisited this particular container.

libindi and pyindi-client should no longer be necessary.

USA-RedDragon commented 1 week ago

Not a huge impact, less than 100mb so dive is still reporting 1.4gb

aaronwmorris commented 1 week ago

One last change here... I have a reduced set of python requirements for the gunicorn image: requirements_latest_web.txt

aaronwmorris commented 1 week ago

Looks good to me, I will merge if you are ready.

USA-RedDragon commented 1 week ago

Using the gunicorn-specific requirements brings the total image size to a nice round 1.0GB.

USA-RedDragon commented 1 week ago

Wait on this one, seems there's a missing dep

indi-allsky-gunicorn-57fc7b67cf-vg2zg gunicorn Error: While importing 'app', an ImportError was raised:
indi-allsky-gunicorn-57fc7b67cf-vg2zg gunicorn 
indi-allsky-gunicorn-57fc7b67cf-vg2zg gunicorn Traceback (most recent call last):
indi-allsky-gunicorn-57fc7b67cf-vg2zg gunicorn   File "/usr/local/lib/python3.11/site-packages/flask/cli.py", line 245, in locate_app
indi-allsky-gunicorn-57fc7b67cf-vg2zg gunicorn     __import__(module_name)
indi-allsky-gunicorn-57fc7b67cf-vg2zg gunicorn   File "/home/allsky/indi-allsky/app.py", line 4, in <module>
indi-allsky-gunicorn-57fc7b67cf-vg2zg gunicorn     app = create_app()
indi-allsky-gunicorn-57fc7b67cf-vg2zg gunicorn           ^^^^^^^^^^^^
indi-allsky-gunicorn-57fc7b67cf-vg2zg gunicorn   File "/home/allsky/indi-allsky/indi_allsky/flask/__init__.py", line 106, in create_app
indi-allsky-gunicorn-57fc7b67cf-vg2zg gunicorn     db.init_app(app)
indi-allsky-gunicorn-57fc7b67cf-vg2zg gunicorn   File "/usr/local/lib/python3.11/site-packages/flask_sqlalchemy/extension.py", line 374, in init_app
indi-allsky-gunicorn-57fc7b67cf-vg2zg gunicorn     engines[key] = self._make_engine(key, options, app)
indi-allsky-gunicorn-57fc7b67cf-vg2zg gunicorn                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
indi-allsky-gunicorn-57fc7b67cf-vg2zg gunicorn   File "/usr/local/lib/python3.11/site-packages/flask_sqlalchemy/extension.py", line 665, in _make_engine
indi-allsky-gunicorn-57fc7b67cf-vg2zg gunicorn     return sa.engine_from_config(options, prefix="")
indi-allsky-gunicorn-57fc7b67cf-vg2zg gunicorn            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
indi-allsky-gunicorn-57fc7b67cf-vg2zg gunicorn   File "/usr/local/lib/python3.11/site-packages/sqlalchemy/engine/create.py", line 820, in engine_from_config
indi-allsky-gunicorn-57fc7b67cf-vg2zg gunicorn     return create_engine(url, **options)
indi-allsky-gunicorn-57fc7b67cf-vg2zg gunicorn            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
indi-allsky-gunicorn-57fc7b67cf-vg2zg gunicorn   File "<string>", line 2, in create_engine
indi-allsky-gunicorn-57fc7b67cf-vg2zg gunicorn   File "/usr/local/lib/python3.11/site-packages/sqlalchemy/util/deprecations.py", line 281, in warned
indi-allsky-gunicorn-57fc7b67cf-vg2zg gunicorn     return fn(*args, **kwargs)  # type: ignore[no-any-return]
indi-allsky-gunicorn-57fc7b67cf-vg2zg gunicorn            ^^^^^^^^^^^^^^^^^^^
indi-allsky-gunicorn-57fc7b67cf-vg2zg gunicorn   File "/usr/local/lib/python3.11/site-packages/sqlalchemy/engine/create.py", line 599, in create_engine
indi-allsky-gunicorn-57fc7b67cf-vg2zg gunicorn     dbapi = dbapi_meth(**dbapi_args)
indi-allsky-gunicorn-57fc7b67cf-vg2zg gunicorn             ^^^^^^^^^^^^^^^^^^^^^^^^
indi-allsky-gunicorn-57fc7b67cf-vg2zg gunicorn   File "/usr/local/lib/python3.11/site-packages/sqlalchemy/dialects/mysql/mysqlconnector.py", line 83, in import_dbapi
indi-allsky-gunicorn-57fc7b67cf-vg2zg gunicorn     from mysql import connector
indi-allsky-gunicorn-57fc7b67cf-vg2zg gunicorn ModuleNotFoundError: No module named 'mysql'
USA-RedDragon commented 1 week ago

Ok, tested with the patch above and it fires up properly now. This one should be good to go