Totonyus / ydl_api_ng

GNU General Public License v3.0
134 stars 15 forks source link

Rework dockerfile, entrypoint #21

Closed codefaux closed 2 months ago

codefaux commented 2 months ago

As mentioned in #20.

Preface: This is not to sound like a lecture. I'm merely explaining the rationale, please don't take offense or feel spoken down to.

Docker images exist as layers. Re-using layers saves speed and time. Keep changes within the container absolutely minimal for optimal size.

Changed to a non-point-release image, so supplemental bugfixes are carried into this image, rather than fixing to the .1 point-release of Python 3.12 -- odds of breaking between 3.12.1 and 3.12.x are extremely minimal but bugfixes might matter.

Installing gcc, g++, python3-dev installs A LOT of libraries, dependencies, etc which are wholly not necessary for this app. Somehow even xorg stuff was getting pulled in. None of this is required. The container should only house necessary files. gcc and g++ are used by python in unsupported environments to build wheels. The python:x docker container is explicitly the most supported environment they have. python3-dev is only for users wishing to do development OF Python3 -- development targetting the internals of python3 or creation of Python extensions explicitly, not development of applications using python3 as a platform.

Installing dos2unix is not necessary if you just write the files correctly in the first place. Might not even be necessary at all. If you don't want to write the files correctly in the first place and must fix them as the image is built instead to work around deficiencies in your environment, let me know and I can rewrite this so dos2unix is not needlessly installed in the container but is instead merely used on the files before they're copied. The container should only house files necessary for the container to run. If you're using this because your repo is configured incorrectly and enforcing the wrong line endings, see [https://docs.github.com/en/get-started/getting-started-with-git/configuring-git-to-handle-line-endings]

Rather than installing ffmpeg from apt (and all the bloat that pulls in, as well as the cleanup we must do afterward) we're pulling the Python package static-ffmpeg which is the minimalist way to install static builds of ffmpeg on any system. (Static binaries run without ANY* libraries and are the slimmest, lowest-footprint way to go.)

Changing the entrypoint from CMD to ENTRYPOINT is really a bit of a preferential bias.

The VOLUME and EXPOSE keywords indicate to container management software how the container is intended to be "hooked up" so to speak. Not necessary, but nice.

I've moved UID/GID stuff to the top of the entrypoint, so that's all correct before we start using it.

Re-copying the setup files re-copies the examples and all of the other files, which some users might not need in their configuration, so we check first during the entrypoint.

For pip, --disable-pip-version-check -q --root-user-action=ignore is just to make pip complain less in the logs, so you see mostly valid information instead of a bunch of extra stuff.

Please test and verify before accepting the pull, I've looked at most things but I'm not positive I caught absolutely every edge case here. Definitely ask questions or request changes if you need them.

codefaux commented 2 months ago

Oh I should also mention --

image image

The new image is a bit smaller

codefaux commented 2 months ago

It seems there is a problem for arm containers

That makes sense, I didn't even consider arm. I'll poke at it soon, I have an arm device I can deploy on for a test.