diff --git a/src/Dockerfile b/src/Dockerfile index a33b722..4ca720c 100644 --- a/src/Dockerfile +++ b/src/Dockerfile @@ -1,17 +1,17 @@ FROM ghcr.io/commandcracker/ffmpeg:latest AS ffmpeg -FROM ffmpeg as sanjuuni +FROM ffmpeg AS sanjuuni -ENV SANJUUNI_VERSION=ed34c266cd489e4db796ca803e247b48b43853e0 +ENV SANJUUNI_VERSION=778644b164c8877e56f9f5512480dde857133815 -ARG SANJUUNI_SHA512SUM="9e482e3b8f8885e8f458856f11d5ee4c27a0aa469b8c54abe1aef943f630ca27eb148c8779ba7a053c1abcce298513e98b614747a77ae1c0cbc86a0a7c95a6d8 *sanjuuni.tar.gz" +ARG SANJUUNI_SHA512SUM="353b97e53ec2daba3046b3062c8a389c75066ea410f9abe089467a4648e83afe926cd65ad0904a0d59eca0520e3174e0f3190987cfee3abbdc9141a04a80ef1a *sanjuuni.tar.gz" SHELL ["/bin/ash", "-eo", "pipefail", "-c"] RUN set -eux; \ apk add --no-cache --update \ - g++=13.2.1_git20231014-r0 \ - zlib-dev=1.3.1-r0 \ + g++=13.2.1_git20240309-r0 \ + zlib-dev=1.3.1-r1 \ poco-dev=1.12.4-r0 \ make=4.4.1-r2; \ wget -q --output-document=sanjuuni.tar.gz https://github.com/MCJack123/sanjuuni/archive/${SANJUUNI_VERSION}.tar.gz; \ @@ -26,7 +26,7 @@ RUN set -eux; \ ./configure; \ make -FROM ghcr.io/commandcracker/alpine-pypy3.10-pip:3.19.0-pypy-7.3.14-pip-23.3.2 AS builder +FROM ghcr.io/commandcracker/alpine-pypy3.10-pip:3.20.1-pypy-7.3.14-pip-24.1.1 AS builder WORKDIR / @@ -40,22 +40,24 @@ RUN set -eux; \ python3 compile.py; \ pip uninstall pip -y -FROM alpine:3.19.0 +FROM alpine:3.20.1 WORKDIR /opt/server RUN set -eux; \ apk add --no-cache --update \ + # CVE-2024-5535 TODO: remove when base image is updated + openssl \ # pypy requirements - libffi=3.4.4-r3 libbz2=1.0.8-r6 \ + libffi=3.4.6-r0 libbz2=1.0.8-r6 \ # sanjuuni requirements poco=1.12.4-r0 \ # ffmpeg requirements - libgcc=13.2.1_git20231014-r \ - libstdc++=13.2.1_git20231014-r0 \ - ca-certificates=20230506-r0 \ - libgomp=13.2.1_git20231014-r0 \ - expat=2.5.0-r2; \ + libgcc=13.2.1_git20240309-r0 \ + libstdc++=13.2.1_git20240309-r0 \ + ca-certificates=20240226-r0 \ + libgomp=13.2.1_git20240309-r0 \ + expat=2.6.2-r0; \ apk add --no-cache --repository=http://dl-cdn.alpinelinux.org/alpine/v3.18/community libssl1.1=1.1.1u-r1 libcrypto1.1=1.1.1u-r1; \ chown 1000 /opt/server/ diff --git a/src/Dockerfile.nvidia b/src/Dockerfile.nvidia index 978ce49..0b1baba 100644 --- a/src/Dockerfile.nvidia +++ b/src/Dockerfile.nvidia @@ -1,21 +1,23 @@ +#!/usr/bin/env dockerfile-shebang + FROM ghcr.io/commandcracker/ubuntu-ffmpeg:latest AS ffmpeg -FROM ffmpeg as sanjuuni +FROM ffmpeg AS sanjuuni -ENV SANJUUNI_VERSION=0.4 +ENV SANJUUNI_VERSION=778644b164c8877e56f9f5512480dde857133815 -ARG SANJUUNI_SHA512SUM="952a6c608d167f37faad53ee7f2e0de8090a02bf73b6455fae7c6b6f648dd6a188e7749fe26caeee85126b2a38d7391389c19afb0100e9962dc551188b9de6ae *sanjuuni.tar.gz" +ARG SANJUUNI_SHA512SUM="353b97e53ec2daba3046b3062c8a389c75066ea410f9abe089467a4648e83afe926cd65ad0904a0d59eca0520e3174e0f3190987cfee3abbdc9141a04a80ef1a *sanjuuni.tar.gz" SHELL ["/bin/bash", "-o", "pipefail", "-c"] RUN set -eux; \ apt-get update; \ - apt-get install \ + apt-get install -y --no-install-recommends \ ocl-icd-opencl-dev=2.2.14-3 \ - wget=1.21.2-2ubuntu1 \ + wget=1.21.2-2ubuntu1.1 \ clang=1:14.0-55~exp2 \ make=4.3-4.1build1 \ - libpoco-dev=1.11.0-3 -y --no-install-recommends; \ + libpoco-dev=1.11.0-3; \ wget --progress=dot:giga --output-document=sanjuuni.tar.gz https://github.com/MCJack123/sanjuuni/archive/${SANJUUNI_VERSION}.tar.gz; \ echo "${SANJUUNI_SHA512SUM}" | sha512sum -c -; \ mkdir --parents sanjuuni; \ @@ -41,21 +43,17 @@ SHELL ["/bin/bash", "-o", "pipefail", "-c"] # hadolint ignore=SC1091 RUN set -eux; \ apt-get update; \ - apt-get install \ + apt-get install -y --no-install-recommends \ libpoco-dev=1.11.0-3 \ python3-pip=22.0.2+dfsg-1 \ - gnupg=2.2.27-3ubuntu2.1 \ - libcurl4=7.81.0-1 \ - curl=7.81.0-1 -y --no-install-recommends; \ + ocl-icd-libopencl1; \ + pip install -U pip; \ pip install --no-cache-dir -r requirements.txt; \ - curl -s -L "https://nvidia.github.io/nvidia-container-runtime/gpgkey" | apt-key add -; \ - distribution=$(. /etc/os-release;echo "$ID$VERSION_ID"); \ - curl -s -L "https://nvidia.github.io/nvidia-container-runtime/$distribution/nvidia-container-runtime.list" | tee /etc/apt/sources.list.d/nvidia-container-runtime.list; \ - apt-get update; \ - apt-get install \ - nvidia-opencl-dev=11.5.1-1ubuntu1 \ - nvidia-container-runtime=3.13.0-1 -y --no-install-recommends; \ - apt-get clean; \ - rm -rf /var/lib/apt/lists/* + mkdir -p /etc/OpenCL/vendors; \ + echo "libnvidia-opencl.so.1" > /etc/OpenCL/vendors/nvidia.icd + +ENV \ + NVIDIA_VISIBLE_DEVICES=all \ + NVIDIA_DRIVER_CAPABILITIES=compute,utility ENTRYPOINT ["python3", "youcube.py"] diff --git a/src/docker-compose.nvidia.yml b/src/docker-compose.nvidia.yml index f2d2d38..79577e3 100644 --- a/src/docker-compose.nvidia.yml +++ b/src/docker-compose.nvidia.yml @@ -1,7 +1,9 @@ -version: "2.0" +--- services: youcube: - build: . + build: + context: . + dockerfile: Dockerfile.nvidia image: youcube:nvidia restart: always hostname: youcube @@ -9,6 +11,4 @@ services: - 5000:5000 #env_file: .env runtime: nvidia - environment: - - NVIDIA_VISIBLE_DEVICES=all - - NVIDIA_DRIVER_CAPABILITIES=compute +... diff --git a/src/docker-compose.yml b/src/docker-compose.yml index 10fc378..9e657ea 100644 --- a/src/docker-compose.yml +++ b/src/docker-compose.yml @@ -1,4 +1,4 @@ -version: "2.0" +--- services: youcube: build: . @@ -8,3 +8,4 @@ services: ports: - 5000:5000 #env_file: .env +... diff --git a/src/requirements.txt b/src/requirements.txt index 991f68a..28a0ad7 100644 --- a/src/requirements.txt +++ b/src/requirements.txt @@ -1,5 +1,5 @@ -sanic~=23.12.1 -#uvloop~=0.19.0; platform_system != "Windows" -yt-dlp~=2023.12.30 -ujson~=5.9.0 -spotipy~=2.23.0 +sanic~=24.6.0 +#uvloop~=0.19.0; platform_system != "Windows" +yt-dlp~=2024.7.2 +#orjson~=3.10.6 +spotipy~=2.24.0 diff --git a/src/youcube/yc_download.py b/src/youcube/yc_download.py index 5ec535d..147d633 100644 --- a/src/youcube/yc_download.py +++ b/src/youcube/yc_download.py @@ -29,7 +29,7 @@ # optional pip modules try: - from ujson import dumps + from orjson import dumps except ModuleNotFoundError: from json import dumps diff --git a/src/youcube/yc_spotify.py b/src/youcube/yc_spotify.py index 7588b24..2a76328 100644 --- a/src/youcube/yc_spotify.py +++ b/src/youcube/yc_spotify.py @@ -17,9 +17,6 @@ from spotipy import MemoryCacheHandler, SpotifyClientCredentials from spotipy.client import Spotify -# https://github.com/spotipy-dev/spotipy/issues/1071 -# pylint: disable-next=line-too-long -REGEX_SPOTIFY_URL = r"^(http[s]?:\/\/)?open.spotify.com\/.*(?Ptrack|artist|album|playlist|show|episode|user)\/(?P[0-9A-Za-z]+)(\?.*)?$" # pylint: disable=missing-function-docstring # pylint: disable=missing-class-docstring @@ -116,7 +113,7 @@ def auto(self, url: str) -> Union[str, list]: # pylint: disable=protected-access for match in [ re_match(Spotify._regex_spotify_uri, url), - re_match(REGEX_SPOTIFY_URL, url), + re_match(Spotify._regex_spotify_url, url), ]: # pylint: enable=protected-access if match: diff --git a/src/youcube/youcube.py b/src/youcube/youcube.py index af621be..1c1e031 100644 --- a/src/youcube/youcube.py +++ b/src/youcube/youcube.py @@ -18,8 +18,8 @@ # optional pip module try: - from ujson import JSONDecodeError, dumps - from ujson import loads as load_json + from orjson import JSONDecodeError, dumps + from orjson import loads as load_json except ModuleNotFoundError: from json import dumps from json import loads as load_json @@ -237,7 +237,7 @@ async def get_chunk(message: dict, _unused, request: Request): file = join(DATA_FOLDER, file_name) request.app.shared_ctx.data[file_name] = datetime.now() - chunk = await get_chunk(file, chunkindex) + chunk = await getchunk(file, chunkindex) return {"action": "chunk", "chunk": b64encode(chunk).decode("ascii")} logger.warning("User tried to use special Characters") @@ -307,7 +307,7 @@ def default(self, request: Request, exception: Union[SanicException, Exception]) return super().default(request, exception) -app = Sanic(__name__) +app = Sanic("youcube") app.error_handler = CustomErrorHandler() # FIXME: The Client is not Responsing to Websocket pings app.config.WEBSOCKET_PING_INTERVAL = 0 @@ -378,10 +378,10 @@ async def main_start(app: Sanic): @app.route("/dfpwm//") async def stream_dfpwm(request: Request, id: str, chunkindex: int): - return raw(await get_chunk(join(DATA_FOLDER, get_audio_name(id)), chunkindex)) + return raw(await getchunk(join(DATA_FOLDER, get_audio_name(id)), chunkindex)) -@app.route("/32vid////", stream=True) +@app.route("/32vid////") # , stream=True async def stream_32vid( request: Request, id: str, width: int, height: int, tracker: int ):