Rework dockerfile, entrypoint. Image size reduced from 966MB to 275MB

This commit is contained in:
Code Faux 2024-05-21 14:48:37 -07:00
parent 0097a1a58e
commit 41ce38e860
3 changed files with 44 additions and 18 deletions

View File

@ -1,19 +1,24 @@
# syntax=docker/dockerfile:1 # syntax=docker/dockerfile:1
FROM python:3.12.1-slim-bullseye FROM python:3.12-slim-bullseye
WORKDIR /app WORKDIR /app
ARG GIT_BRANCH=unknown GIT_REVISION=unknown DATE=unknown ARG GIT_BRANCH=unknown GIT_REVISION=unknown DATE=unknown
ENV UID=1000 GID=1000 GIT_BRANCH=$GIT_BRANCH GIT_REVISION=$GIT_REVISION DATE=$DATE NB_WORKERS=5 LOG_LEVEL="info" DISABLE_REDIS='false' ENV UID=1000 GID=1000 GIT_BRANCH=$GIT_BRANCH GIT_REVISION=$GIT_REVISION DATE=$DATE NB_WORKERS=5 LOG_LEVEL="info" DISABLE_REDIS='false'
VOLUME ["/app/params", "/app/data", "/app/downloads", "/app/logs"]
EXPOSE 80
RUN apt update && apt install ffmpeg dos2unix gcc g++ python3-dev -y && apt-get autoremove && apt-get -y clean && rm -rf /var/lib/apt/lists/* # Use Python -- since it comes with the image -- to download and unpack the static ffmpeg binary
RUN pip install static-ffmpeg
COPY *.py entrypoint.sh pip_requirements ./ COPY --chmod=755 entrypoint.sh ./
COPY *.py pip_requirements ./
COPY params/*.py params/*.ini params/userscript.js params/hooks_requirements ./setup/ COPY params/*.py params/*.ini params/userscript.js params/hooks_requirements ./setup/
COPY params/params_docker.ini ./setup/params.ini COPY params/params_docker.ini ./setup/params.ini
RUN dos2unix * ./setup/* # Just write them properly in the first place.
#RUN dos2unix * ./setup/*
RUN pip3 install -r pip_requirements RUN pip3 install -r pip_requirements
CMD ["bash", "/app/entrypoint.sh"] ENTRYPOINT ["/app/entrypoint.sh"]

View File

@ -4,25 +4,46 @@ echo ~~~ ydl_api_ng
echo ~~~ Revision : $GIT_BRANCH - $GIT_REVISION echo ~~~ Revision : $GIT_BRANCH - $GIT_REVISION
echo ~~~ Docker image generated : $DATE echo ~~~ Docker image generated : $DATE
mkdir -p /app/logs /app/downloads /app/params /app/tmp /home/ydl_api_ng /app/data /root/yt-dlp-plugins /app/cookies/ mkdir -p /app/logs /app/downloads /app/params /app/tmp /app/data /root/yt-dlp-plugins /app/cookies/
cp -n /app/setup/* /app/params/
touch /app/data/database.json getent group $GID > /dev/null
ln -s /app/data/database.json ./database.json if [ $? -eq 0 ]; then
groupmod $(id --name --group $GID) -n ydl_api_ng
else
addgroup --gid $GID ydl_api_ng
fi
getent passwd $UID > /dev/null
if [ $? -eq 0 ]; then
usermod $(id --name --user $UID) -l ydl_api_ng
else
useradd -m --uid $UID --gid ydl_api_ng ydl_api_ng
fi
chown -R $UID:$GID /app
chown $UID:$GID /home/ydl_api_ng /root/yt-dlp-plugins
chmod a+x /root/ entrypoint.sh
# If paraps.ini exists, assume setup has been run. Don't copy extra files the user may have removed.
if [ ! -e '/app/params/params.ini' ]; then
cp -n /app/setup/* /app/params/
fi
# Just access the file from the correct place in the app
if [ ! -e /app/data/database.json ]; then
touch /app/data/database.json
fi
if [ "$FORCE_YTDLP_VERSION" == "" ]; then if [ "$FORCE_YTDLP_VERSION" == "" ]; then
echo --- Upgrade yt-dlp to the latest version --- echo --- Upgrade yt-dlp to the latest version ---
pip3 install yt-dlp --upgrade pip3 install yt-dlp --upgrade --disable-pip-version-check -q --root-user-action=ignore
else else
echo --- Force yt-dlp version $FORCE_YTDLP_VERSION --- echo --- Force yt-dlp version $FORCE_YTDLP_VERSION ---
pip3 install yt-dlp==$FORCE_YTDLP_VERSION --force-reinstall pip3 install --disable-pip-version-check -q --root-user-action=ignore yt-dlp==$FORCE_YTDLP_VERSION --force-reinstall
fi fi
pip3 install -r /app/params/hooks_requirements pip3 install --disable-pip-version-check -q --root-user-action=ignore -r /app/params/hooks_requirements
addgroup --gid $GID ydl_api_ng && useradd --uid $UID --gid ydl_api_ng ydl_api_ng
chown $UID:$GID /app/logs /app/downloads /home/ydl_api_ng /app/tmp /app/data /app/data/database.json /app/cookies /root/yt-dlp-plugins
chmod a+x /root/ entrypoint.sh
if [ "$DISABLE_REDIS" == "false" ]; then if [ "$DISABLE_REDIS" == "false" ]; then
cat <<EOT >>/app/supervisord_workers.conf cat <<EOT >>/app/supervisord_workers.conf

View File

@ -5,7 +5,7 @@ from programmation_class import Programmation
class ProgrammationPersistenceManager: class ProgrammationPersistenceManager:
def __init__(self, database_file=None, *args, **kwargs): def __init__(self, database_file=None, *args, **kwargs):
self.__database_file = database_file if database_file is not None else 'database.json' self.__database_file = database_file if database_file is not None else 'data/database.json'
self.__db = TinyDB(self.__database_file) self.__db = TinyDB(self.__database_file)
self.__scheduled_jobs_table = self.__db.table('scheduled_jobs', cache_size=0) self.__scheduled_jobs_table = self.__db.table('scheduled_jobs', cache_size=0)