From 5492f2201f12441d0f56ed1259e6d352873a958d Mon Sep 17 00:00:00 2001 From: Wanjohi <71614375+wanjohiryan@users.noreply.github.com> Date: Wed, 3 Apr 2024 01:53:16 +0000 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20feat(server):=20Add=20gpu-screen-re?= =?UTF-8?q?corder=20(#9)?= 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):** So, we have our simple compositor (`gamescope`), now we need a way to capture audio and video. And i have found this "performant" **_citation needed_ ** and minimal screen recorder, which has the capability to even capture 30 second screen snippets. **How(how does it solve it):** 1. Add a minimal step inside the DockerFile to build and install the gpu-screen-recorder ## 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 --- .github/workflows/recorder.yml | 93 ++++++++++++++++++++++++++++++++++ recorder.Dockerfile | 56 ++++++++++++++++++++ server.Dockerfile | 30 ++--------- 3 files changed, 152 insertions(+), 27 deletions(-) create mode 100644 .github/workflows/recorder.yml create mode 100644 recorder.Dockerfile diff --git a/.github/workflows/recorder.yml b/.github/workflows/recorder.yml new file mode 100644 index 00000000..25378128 --- /dev/null +++ b/.github/workflows/recorder.yml @@ -0,0 +1,93 @@ +#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/recorder.Dockerfile b/recorder.Dockerfile new file mode 100644 index 00000000..a94952ce --- /dev/null +++ b/recorder.Dockerfile @@ -0,0 +1,56 @@ +# This builds and updates the screen recorder we use on Netris +# From https://git.dec05eba.com/gpu-screen-recorder +FROM ubuntu:23.10 + +ENV DEBIAN_FRONTEND=noninteractive + +# To run /usr/bin/gpu-screen-recorder. +# Add this to your runtime +# 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 \ + unzip \ + git \ + build-essential \ + ninja-build \ + gcc \ + meson \ + cmake \ + ccache \ + bison \ + equivs \ + ca-certificates\ + libcap2-bin \ + libllvm15 \ + libavcodec-dev \ + libavformat-dev \ + libavutil-dev \ + libx11-dev \ + libxcomposite-dev \ + libxrandr-dev \ + libxfixes-dev \ + libpulse-dev \ + libswresample-dev \ + libavfilter-dev \ + libva-dev \ + libcap-dev \ + libdrm-dev \ + libgl-dev \ + libegl-dev \ + libwayland-dev \ + libwayland-egl-backend-dev \ + wayland-protocols \ + && rm -rf /var/lib/apt/lists/* \ + #Install Cuda + && cd /tmp && curl -fsSL -o nvidia_cuda_nvrtc_linux_x86_64.whl "https://developer.download.nvidia.com/compute/redist/nvidia-cuda-nvrtc/nvidia_cuda_nvrtc-11.0.221-cp36-cp36m-linux_x86_64.whl" \ + && unzip -joq -d ./nvrtc nvidia_cuda_nvrtc_linux_x86_64.whl && cd nvrtc && chmod 755 libnvrtc* \ + && find . -maxdepth 1 -type f -name "*libnvrtc.so.*" -exec sh -c 'ln -snf $(basename {}) libnvrtc.so' \; \ + && mkdir -p /usr/local/nvidia/lib && mv -f libnvrtc* /usr/local/nvidia/lib \ + && 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 diff --git a/server.Dockerfile b/server.Dockerfile index 54e84cbd..0600eb63 100644 --- a/server.Dockerfile +++ b/server.Dockerfile @@ -1,11 +1,7 @@ #This contains all the necessary libs for the server to work. #NOTE: KEEP THIS IMAGE AS LEAN AS POSSIBLE. - FROM ubuntu:23.10 -#FIXME: install Vulkan drivers (should be done in the .scripts/gpu) -#FIXME: install https://git.dec05eba.com/gpu-screen-recorder (should be done in the .scripts/stream) - ENV DEBIAN_FRONTEND=noninteractive \ TIMEZONE=Africa/Nairobi @@ -98,34 +94,14 @@ RUN apt-get update -y \ # Prepare the XDG_RUNTIME_DIR for wayland && mkdir -p ${XDG_RUNTIME_DIR} && chmod 0700 ${XDG_RUNTIME_DIR} -WORKDIR /tmp -#Running gamescope flatpak run org.freedesktop.Platform.VulkanLayer.gamescope -#Install Mangohud, gamemode,gpu-screen-recorder and gamescope +#Install Mangohud, gamemode and gamescope RUN apt-get update -y \ && add-apt-repository -y multiverse \ && apt-get install -y --no-install-recommends \ flatpak \ mangohud \ - gamescope - # && flatpak remote-add --if-not-exists flathub https://flathub.org/repo/flathub.flatpakrepo \ - # && flatpak install flathub com.dec05eba.gpu_screen_recorder - #TODO: Add gamemode back in, when we get the time - # meson \ - # libsystemd-dev \ - # pkg-config \ - # ninja-build \ - # git \ - # libdbus-1-dev \ - # libinih-dev \ - # build-essential \ - # && git clone https://github.com/FeralInteractive/gamemode.git && cd gamemode \ - # && git checkout 1.7 && chmod +x ./bootstrap.sh && ./bootstrap.sh \ - # && gamemode -t \ - # && flatpak remote-add --if-not-exists flathub https://flathub.org/repo/flathub.flatpakrepo \ - # gamescope - # && com.valvesoftware.Steam.Utility.gamescope - # Gamemode - # && flatpak install -y com.valvesoftware.Steam.CompatibilityTool.Proton-GE + gamescope \ + && rm -rf /var/lib/apt/lists/* COPY .scripts/ /usr/bin/netris/