diff --git a/dockerfile b/dockerfile index 0c0bb5d..fb9933b 100644 --- a/dockerfile +++ b/dockerfile @@ -1,19 +1,24 @@ # syntax=docker/dockerfile:1 -FROM python:3.12.1-slim-bullseye +FROM python:3.12-slim-bullseye WORKDIR /app 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' +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/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 -CMD ["bash", "/app/entrypoint.sh"] +ENTRYPOINT ["/app/entrypoint.sh"] diff --git a/entrypoint.sh b/entrypoint.sh index 01bdb20..2378a3b 100644 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -4,25 +4,46 @@ echo ~~~ ydl_api_ng echo ~~~ Revision : $GIT_BRANCH - $GIT_REVISION 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/ -cp -n /app/setup/* /app/params/ -touch /app/data/database.json -ln -s /app/data/database.json ./database.json +mkdir -p /app/logs /app/downloads /app/params /app/tmp /app/data /root/yt-dlp-plugins /app/cookies/ + +getent group $GID > /dev/null +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 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 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 -pip3 install -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 +pip3 install --disable-pip-version-check -q --root-user-action=ignore -r /app/params/hooks_requirements if [ "$DISABLE_REDIS" == "false" ]; then cat <>/app/supervisord_workers.conf diff --git a/programmation_persistence_manager.py b/programmation_persistence_manager.py index 5a29845..224eee9 100644 --- a/programmation_persistence_manager.py +++ b/programmation_persistence_manager.py @@ -5,7 +5,7 @@ from programmation_class import Programmation class ProgrammationPersistenceManager: 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.__scheduled_jobs_table = self.__db.table('scheduled_jobs', cache_size=0)