From e7f5666d7abe7aa74420a4bac3ff1a4b8cc71734 Mon Sep 17 00:00:00 2001 From: Wanjohi <71614375+wanjohiryan@users.noreply.github.com> Date: Mon, 15 Apr 2024 10:40:03 +0300 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20feat:=20Merge=20`recorder`=20and=20?= =?UTF-8?q?`ffmpeg`=20to=20`base`=20(#21)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Description **What(what issue does this code solve/what feature does it add):** We do not need the ffmpeg and recorder all sitting differently, as this will increase our docker image size **How(how does it solve it):** ## Required Checklist: - [ ] I have added any necessary documentation and comments in my code (where appropriate) - [ ] I have added tests to make sure my code runs in all contexts ## Further comments --- .dev/x11.sh | 5 +- .github/labeler.yml | 8 +- .github/labels.yml | 5 +- .github/workflows/{ffmpeg.yml => base.yml} | 18 ++--- .github/workflows/recorder.yml | 93 ---------------------- .scripts/entrypoint.sh | 29 +++++-- recorder.Dockerfile => base.Dockerfile | 31 +++++++- ffmpeg.Dockerfile | 19 ----- server.Dockerfile | 5 +- 9 files changed, 70 insertions(+), 143 deletions(-) rename .github/workflows/{ffmpeg.yml => base.yml} (88%) delete mode 100644 .github/workflows/recorder.yml rename recorder.Dockerfile => base.Dockerfile (67%) delete mode 100644 ffmpeg.Dockerfile diff --git a/.dev/x11.sh b/.dev/x11.sh index 9831c393..f684eb72 100644 --- a/.dev/x11.sh +++ b/.dev/x11.sh @@ -10,4 +10,7 @@ xhost weston --backend=x11-backend.so #Run inside the terminal of the weston you just created... cool right? -weston --backend=wayland-backend.so \ No newline at end of file +weston --backend=wayland-backend.so + +#Run +docker run --gpus all --entrypoint /bin/bash --rm -it -v $(pwd):/games -v /tmp/.X11-unix:/tmp/.X11-unix -e DISPLAY=$DISPLAY --cap-add=SYS_NICE --cap-add=SYS_ADMIN recorder diff --git a/.github/labeler.yml b/.github/labeler.yml index 8f242c19..9da6ced8 100644 --- a/.github/labeler.yml +++ b/.github/labeler.yml @@ -46,13 +46,9 @@ labels: files: - 'server.Dockerfile' - - label: 'scope/ffmpeg' + - label: 'scope/base' files: - - 'ffmpeg.Dockerfile' - - - label: 'scope/recorder' - files: - - 'recorder.Dockerfile' + - 'base.Dockerfile' - label: 'scope/ffmpeg' files: diff --git a/.github/labels.yml b/.github/labels.yml index 1a542e0e..4e3fc07a 100644 --- a/.github/labels.yml +++ b/.github/labels.yml @@ -74,10 +74,7 @@ - name: "scope/relay" color: "B61B66" -- name: "scope/ffmpeg" - color: "B61B66" - -- name: "scope/recorder" +- name: "scope/base" color: "B61B66" - name: "scope/back-end" diff --git a/.github/workflows/ffmpeg.yml b/.github/workflows/base.yml similarity index 88% rename from .github/workflows/ffmpeg.yml rename to .github/workflows/base.yml index 6531010b..4daf4878 100644 --- a/.github/workflows/ffmpeg.yml +++ b/.github/workflows/base.yml @@ -1,19 +1,19 @@ #Tabs not spaces, you moron :) -name: CI for netris:ffmpeg +name: CI for netris:base on: pull_request: paths: - - "ffmpeg.Dockerfile" - - ".github/workflows/ffmpeg.yml" + - "base.Dockerfile" + - ".github/workflows/base.yml" schedule: - cron: 0 0 * * * # At the end of everyday push: branches: [main] paths: - - "ffmpeg.Dockerfile" - - ".github/workflows/ffmpeg.yml" + - "base.Dockerfile" + - ".github/workflows/base.yml" tags: - v*.*.* release: @@ -26,7 +26,7 @@ concurrency: env: REGISTRY: ghcr.io IMAGE_NAME: wanjohiryan/netris - BASE_TAG_PREFIX: ffmpeg + BASE_TAG_PREFIX: base jobs: build-docker-pr: @@ -44,11 +44,11 @@ jobs: name: Build Docker image uses: docker/build-push-action@v5 with: - file: ffmpeg.Dockerfile + file: base.Dockerfile context: ./ push: false load: true - tags: netris:ffmpeg + tags: netris:base build-docker-main: name: Build image on merge @@ -86,7 +86,7 @@ jobs: name: Build Docker image uses: docker/build-push-action@v5 with: - file: ffmpeg.Dockerfile + file: base.Dockerfile context: ./ push: true tags: ${{ steps.meta.outputs.tags }} diff --git a/.github/workflows/recorder.yml b/.github/workflows/recorder.yml deleted file mode 100644 index 25378128..00000000 --- a/.github/workflows/recorder.yml +++ /dev/null @@ -1,93 +0,0 @@ -#Tabs not spaces, you moron :) - -name: CI for netris:recorder - -on: - pull_request: - paths: - - "recorder.Dockerfile" - - ".github/workflows/recorder.yml" - schedule: - - cron: 0 0 * * * # At the end of everyday - push: - branches: [main] - paths: - - "recorder.Dockerfile" - - ".github/workflows/recorder.yml" - tags: - - v*.*.* - release: - types: [created] - -concurrency: - group: ${{ github.workflow }}-${{ github.ref == 'refs/heads/main' && github.run_id || github.event.pull_request.number || github.ref }} - cancel-in-progress: true - -env: - REGISTRY: ghcr.io - IMAGE_NAME: wanjohiryan/netris - BASE_TAG_PREFIX: recorder - -jobs: - build-docker-pr: - name: Build image on pr - runs-on: ubuntu-latest - if: ${{ github.event_name == 'pull_request' }} - steps: - - - name: Checkout repo - uses: actions/checkout@v4 - - - name: Setup Docker Buildx - uses: docker/setup-buildx-action@v3 - - - name: Build Docker image - uses: docker/build-push-action@v5 - with: - file: recorder.Dockerfile - context: ./ - push: false - load: true - tags: netris:recorder - - build-docker-main: - name: Build image on merge - if: ${{github.ref == 'refs/heads/main'}} - runs-on: ubuntu-latest - permissions: - contents: read - packages: write - steps: - - - name: Checkout repo - uses: actions/checkout@v4 - - - name: Log into registry ${{ env.REGISTRY }} - uses: docker/login-action@v3 - with: - registry: ${{ env.REGISTRY }} - username: ${{ github.actor }} - password: ${{ secrets.GITHUB_TOKEN }} - - - name: Extract Container metadata - id: meta - uses: docker/metadata-action@v5 - with: - images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}/${{ env.BASE_TAG_PREFIX }} - # - #tag on release, and a nightly build for 'dev' - tags: | - type=raw,value=nightly,enable={{is_default_branch}} - type=ref,event=tag - type=semver,pattern={{version}} - type=semver,pattern={{major}}.{{minor}} - type=semver,pattern={{major}} - - - name: Build Docker image - uses: docker/build-push-action@v5 - with: - file: recorder.Dockerfile - context: ./ - push: true - tags: ${{ steps.meta.outputs.tags }} - labels: ${{ steps.meta.outputs.labels }} \ No newline at end of file diff --git a/.scripts/entrypoint.sh b/.scripts/entrypoint.sh index c671684c..c788aa58 100644 --- a/.scripts/entrypoint.sh +++ b/.scripts/entrypoint.sh @@ -1,9 +1,28 @@ #!/bin/bash -#Start pulseaudio -/usr/bin/pulseaudio --system --verbose --log-target=stderr --realtime=true --disallow-exit -F /etc/pulse/default.pa - # Attempt to set capabilities # Gotten from https://git.dec05eba.com/gpu-screen-recorder/tree/install.sh -setcap 'cap_sys_admin+ep' /usr/bin/gsr-kms-server -setcap 'cap_sys_nice+ep' /usr/bin/gpu-screen-recorder \ No newline at end of file +#TODO: remove this +# setcap 'cap_sys_admin+ep' /usr/bin/gsr-kms-server +# setcap 'cap_sys_nice+ep' /usr/bin/gpu-screen-recorder + +#Start dbus +/etc/init.d/dbus start + +#Start Pulseaudio Reference: https://github.com/wanjohiryan/warp/blob/ad9cd38d21f0ac4332e64358e219b48e01871870/docker/nvidia/entrypoint.sh#L38 +/usr/bin/pulseaudio -k >/dev/null 2>&1 || /usr/bin/pulseaudio --system --verbose --log-target=stderr -D --realtime=true --disallow-exit -L 'module-native-protocol-tcp auth-ip-acl=127.0.0.0/8 port=4713 auth-anonymous=1' +pacmd load-module module-virtual-sink sink_name=vsink +pacmd set-default-sink vsink +pacmd set-default-source vsink.monitor + +# Create and modify permissions of XDG_RUNTIME_DIR Reference: https://github.com/selkies-project/docker-nvidia-glx-desktop/blob/94b139c5d04395e1171202bb41e5d6f60e576a39/entrypoint.sh#L9C1-L10C1 +mkdir -pm700 /tmp/runtime-user +chown root:root /tmp/runtime-user +chmod 700 /tmp/runtime-user + +#FIXME: + +#Mangohud [Works] +# Mangohud errors: Selected GPU 0: Tesla T4, type: DiscreteGpu [2024-04-14 23:52:57.098] [MANGOHUD] [error] [loader_nvctrl.cpp:39] Failed to open 64bit libXNVCtrl.so.0: libXNVCtrl.so.0: cannot open shared object file: No such file or directory [2024-04-14 23:52:57.098] [MANGOHUD] [error] [nvctrl.cpp:45] XNVCtrl loader failed to load +# gpu-screen-recorder [Fails]: #/usr/games/gamescope -w 1920 -h 1080 -W 3440 -H 1440 -r 60 -f -F fsr -- mangohud vkcubeNo CAP_SYS_NICE, falling back to regular-priority compute and threads.Performance will be affected.wlserver: [backend/headless/backend.c:68] Creating headless backendvulkan: selecting physical device 'Tesla T4': queue family 2vulkan: physical device does not support DRM format modifiersvulkan: physical device has no render nodeFailed to initialize Vulkan +# TODO: replace gpu-screen-recorder with shadow-cast (has better documentation) \ No newline at end of file diff --git a/recorder.Dockerfile b/base.Dockerfile similarity index 67% rename from recorder.Dockerfile rename to base.Dockerfile index a94952ce..4b888301 100644 --- a/recorder.Dockerfile +++ b/base.Dockerfile @@ -9,7 +9,6 @@ ENV DEBIAN_FRONTEND=noninteractive # docker run --rm --cap-add SYS_ADMIN --cap-add SYS_NICE netris/gpu-screen-recorder #Build and install gpu-screen-recorder -#TODO: Install ffmpeg RUN apt-get update -y \ && apt-get install -y \ curl \ @@ -22,6 +21,8 @@ RUN apt-get update -y \ cmake \ ccache \ bison \ + software-properties-common \ + ca-certificates \ equivs \ ca-certificates\ libcap2-bin \ @@ -29,19 +30,24 @@ RUN apt-get update -y \ libavcodec-dev \ libavformat-dev \ libavutil-dev \ + libavfilter-dev \ + libavdevice-dev \ + libswresample-dev \ + libswscale-dev \ libx11-dev \ libxcomposite-dev \ + libkpipewire-dev \ libxrandr-dev \ libxfixes-dev \ libpulse-dev \ libswresample-dev \ - libavfilter-dev \ libva-dev \ libcap-dev \ libdrm-dev \ libgl-dev \ libegl-dev \ libwayland-dev \ + libnvidia-egl-wayland-dev \ libwayland-egl-backend-dev \ wayland-protocols \ && rm -rf /var/lib/apt/lists/* \ @@ -53,4 +59,23 @@ RUN apt-get update -y \ && echo "/usr/local/nvidia/lib" >> /etc/ld.so.conf.d/nvidia.conf && echo "/usr/local/nvidia/lib64" >> /etc/ld.so.conf.d/nvidia.conf \ && git clone https://repo.dec05eba.com/gpu-screen-recorder && cd gpu-screen-recorder \ && chmod +x ./build.sh ./install.sh \ - && ./install.sh \ No newline at end of file + && ./install.sh + +#Try building +RUN git clone https://github.com/gmbeard/shadow-cast && cd shadow-cast \ + && mkdir ./build && cd ./build \ + && cmake -DCMAKE_CXX_FLAGS="-Wno-error=unused-result" -DCMAKE_C_FLAGS="-Wno-error=unused-result" .. \ + && cmake --build . -- -j$(nproc) \ + && chmod +x ./install-helper.sh \ + && ./install-helper.sh + +RUN apt-get update -y; \ + apt-get upgrade -y; \ + add-apt-repository ppa:savoury1/ffmpeg4 \ + add-apt-repository ppa:savoury1/ffmpeg6 \ + apt-get update -y; \ + apt-get upgrade -y && apt-get dist-upgrade -y; \ + apt-get install ffmpeg -y; \ + # + # Log out the ffmpeg version + ffmpeg -version \ No newline at end of file diff --git a/ffmpeg.Dockerfile b/ffmpeg.Dockerfile deleted file mode 100644 index 05aed315..00000000 --- a/ffmpeg.Dockerfile +++ /dev/null @@ -1,19 +0,0 @@ -FROM ubuntu:23.10 - -RUN apt-get -yqq update \ - && apt-get install -yq --no-install-recommends \ - software-properties-common \ - ca-certificates \ - && apt-get autoremove -y \ - && apt-get clean -y - -RUN apt-get update -y; \ - apt-get upgrade -y; \ - add-apt-repository ppa:savoury1/ffmpeg4 \ - add-apt-repository ppa:savoury1/ffmpeg6 \ - apt-get update -y; \ - apt-get upgrade -y && apt-get dist-upgrade -y; \ - apt-get install ffmpeg -y; \ - # - # Log out the ffmpeg version - ffmpeg -version \ No newline at end of file diff --git a/server.Dockerfile b/server.Dockerfile index 25f93034..b0c5bb0d 100644 --- a/server.Dockerfile +++ b/server.Dockerfile @@ -38,7 +38,7 @@ ENV PATH=/usr/local/nvidia/bin:${PATH} \ # Disable VSYNC __GL_SYNC_TO_VBLANK=0 -ENV XDG_RUNTIME_DIR=/run/user/1000/ \ +ENV XDG_RUNTIME_DIR=/tmp/runtime-user \ # DISPLAY=:0 \ WAYLAND_DISPLAY=wayland-0 \ PUID=0 \ @@ -114,8 +114,7 @@ RUN apt-get update -y \ libasound2 \ libasound2-plugins \ pulseaudio \ - && rm -rf /var/lib/apt/lists/* \ - && echo "load-module module-native-protocol-tcp auth-anonymous=1" >> /etc/pulse/default.pa + && rm -rf /var/lib/apt/lists/* COPY .scripts/ /usr/bin/netris/ COPY warp /usr/bin/netris/