cher-nov / cryptg

Official Telethon extension to provide much faster cryptography for Telegram API requests.
https://pypi.org/project/cryptg/
Creative Commons Zero v1.0 Universal
75 stars 24 forks source link

Huge docker image size #30

Closed meowthpxnk closed 9 months ago

meowthpxnk commented 9 months ago

Hi, i'm trying to build docker image with installing cryptg.

I'm facing a problem that my build size is so huge. ~1.5 GB. This happens after installing cargo

apk add cargo

I'll want use «cryptg» for faster sending media files. Lib helps me very well.

After uninstalling cargo size of my image becomes less as ~1mb. But after uninstalling «cryptg» doesn't working.

Have u any ideas how i can reduce my build's size without uninstalling cargo package?

Lonami commented 9 months ago

cryptg depends on Rust, which by default uses LLVM, which is pretty large.

I don't know much about Docker, but I would imagine you should be able to build the cryptg artifact once and then use that binary without needing Rust and cargo to be available.

meowthpxnk commented 9 months ago

Removing Rust and Cargo after building cryptg causes my media files to take a very long time to be encrypted. And after reinstalling them, everything falls into place

Lonami commented 9 months ago

That shouldn't happen. You should make sure cryptg is being loaded correctly, perhaps trying outside Docker first.

meowthpxnk commented 9 months ago

That's right. Files encrypted fast without cargo if i remove that after run python script. But now i can't correctly restart my image because cryptg doesn't working correct without installed cargo.

Have u any ideas how i can previous build cryptg, and then remove cargo package?

Rongronggg9 commented 9 months ago

May you try

import cryptg

to see if it can be imported after you have cargo removed?

meowthpxnk commented 9 months ago

After removing cargo, I received the following error when importing cryptg.

2024-01-11 05:39:03 cryptg module not installed and libssl not found, falling back to (slower) Python encryption
2024-01-11 05:39:04 Traceback (most recent call last):
2024-01-11 05:39:04   File "/telegram/run.py", line 2, in <module>
2024-01-11 05:39:04     import cryptg
2024-01-11 05:39:04   File "/usr/local/lib/python3.11/site-packages/cryptg/__init__.py", line 1, in <module>
2024-01-11 05:39:04     from .cryptg import *
2024-01-11 05:39:04 ImportError: Error loading shared library libgcc_s.so.1: No such file or directory (needed by /usr/local/lib/python3.11/site-packages/cryptg/cryptg.cpython-311-x86_64-linux-musl.so)
Rongronggg9 commented 9 months ago

libgcc is the internal library used by programs/libraries compiled by GCC. Usually a distribution should have it installed by default as almost every program links to it. However, Alpine (I assume that you use Alpine as the package manager you used is apk), which is a musl-based distribution, is not the case. Thus, libgcc was installed as a dependency of cargo, but later got uninstalled along.

You just need to manually install it.

See also: https://github.com/fasibio/alpine-libgcc/blob/master/Dockerfile https://github.com/rust-lang/rustup/issues/2213

meowthpxnk commented 9 months ago

Thank you very much. It helped me.