diff --git a/.docker_platforms b/.docker_platforms new file mode 100644 index 00000000000..11a8121d9e8 --- /dev/null +++ b/.docker_platforms @@ -0,0 +1 @@ +linux/amd64 \ No newline at end of file diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 00000000000..d5f417434e7 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,12 @@ +# Remove all, we'll include only the necessary folders via ! +* + +!cmake +!scripts +!src +!src_assets +!third-party +!CMakeLists.txt +!*.in +!LICENSE +!NOTICE diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index c9e6b0df0e6..dcac262c30c 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -73,7 +73,7 @@ jobs: steps: - name: Checkout - uses: actions/checkout@v2 + uses: actions/checkout@v3 - name: Setup Dependencies Linux AUR run: | diff --git a/.github/workflows/ci-docker.yml b/.github/workflows/ci-docker.yml new file mode 100644 index 00000000000..ed36038d1ed --- /dev/null +++ b/.github/workflows/ci-docker.yml @@ -0,0 +1,191 @@ +--- +# This action is centrally managed in https://github.com//.github/ +# Don't make changes to this file in this repo as they will be overwritten with changes made to the same file in +# the above-mentioned repo. + +name: CI Docker + +on: + pull_request: + branches: [master, nightly] + types: [opened, synchronize, reopened] + push: + branches: [master, nightly] + workflow_dispatch: + +jobs: + check_dockerfile: + name: Check Dockerfile + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v3 + + - name: Check + id: check + run: | + if [ -f "./Dockerfile" ] + then + FOUND=true + else + FOUND=false + fi + + echo "::set-output name=dockerfile::${FOUND}" + + outputs: + dockerfile: ${{ steps.check.outputs.dockerfile }} + + lint_dockerfile: + name: Lint Dockerfile + needs: [check_dockerfile] + if: ${{ needs.check_dockerfile.outputs.dockerfile == 'true' }} + runs-on: ubuntu-latest + steps: + - name: Lint Dockerfile + uses: actions/checkout@v3 + + - uses: hadolint/hadolint-action@v2.1.0 + with: + dockerfile: ./Dockerfile + + check_changelog: + name: Check Changelog + needs: [check_dockerfile] + if: ${{ needs.check_dockerfile.outputs.dockerfile == 'true' }} + runs-on: ubuntu-latest + steps: + - name: Checkout + if: ${{ github.ref == 'refs/heads/master' || github.base_ref == 'master' }} + uses: actions/checkout@v3 + + - name: Verify Changelog + id: verify_changelog + if: ${{ github.ref == 'refs/heads/master' || github.base_ref == 'master' }} + # base_ref for pull request check, ref for push + uses: LizardByte/.github/actions/verify_changelog@master + with: + token: ${{ secrets.GITHUB_TOKEN }} + outputs: + next_version: ${{ steps.verify_changelog.outputs.changelog_parser_version }} + + docker: + name: Docker + needs: [check_dockerfile, check_changelog] + if: ${{ needs.check_dockerfile.outputs.dockerfile == 'true' }} + runs-on: ubuntu-latest + permissions: + packages: write + contents: write + + steps: + - name: Checkout + uses: actions/checkout@v3 + with: + submodules: recursive + + - name: Prepare + id: prepare + env: + NEXT_VERSION: ${{ needs.check_changelog.outputs.next_version }} + run: | + # get branch name + BRANCH=${GITHUB_HEAD_REF} + + if [ -z "$BRANCH" ] + then + echo "This is a PUSH event" + BRANCH=${{ github.ref_name }} + fi + + # determine to push image to dockerhub and ghcr or not + if [[ $GITHUB_EVENT_NAME == "push" ]]; then + PUSH=true + else + PUSH=false + fi + + # setup the tags + REPOSITORY=${{ github.repository }} + BASE_TAG=$(echo $REPOSITORY | tr '[:upper:]' '[:lower:]') + COMMIT=${{ github.sha }} + + TAGS="${BASE_TAG}:${COMMIT:0:7},ghcr.io/${BASE_TAG}:${COMMIT:0:7}" + + if [[ $GITHUB_REF == refs/heads/master ]]; then + TAGS="${TAGS},${BASE_TAG}:latest,ghcr.io/${BASE_TAG}:latest" + TAGS="${TAGS},${BASE_TAG}:master,ghcr.io/${BASE_TAG}:master" + elif [[ $GITHUB_REF == refs/heads/nightly ]]; then + TAGS="${TAGS},${BASE_TAG}:nightly,ghcr.io/${BASE_TAG}:nightly" + else + TAGS="${TAGS},${BASE_TAG}:test,ghcr.io/${BASE_TAG}:test" + fi + + if [[ ${NEXT_VERSION} != "" ]]; then + TAGS="${TAGS},${BASE_TAG}:${NEXT_VERSION},ghcr.io/${BASE_TAG}:${NEXT_VERSION}" + fi + + # read the platforms from `.docker_platforms` + PLATFORMS=$(<.docker_platforms) + + echo ::set-output name=branch::${BRANCH} + echo ::set-output name=build_date::$(date -u +'%Y-%m-%dT%H:%M:%SZ') + echo ::set-output name=commit::${COMMIT} + echo ::set-output name=platforms::${PLATFORMS} + echo ::set-output name=push::${PUSH} + echo ::set-output name=tags::${TAGS} + + - name: Set Up QEMU + uses: docker/setup-qemu-action@v2 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + id: buildx + + - name: Cache Docker Layers + uses: actions/cache@v3 + with: + path: /tmp/.buildx-cache + key: ${{ runner.os }}-buildx-${{ github.sha }} + restore-keys: | + ${{ runner.os }}-buildx- + + - name: Log in to Docker Hub + if: ${{ steps.prepare.outputs.push == 'true' }} # PRs do not have access to secrets + uses: docker/login-action@v2 + with: + username: ${{ secrets.DOCKER_HUB_USERNAME }} + password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }} + + - name: Log in to the Container registry + if: ${{ steps.prepare.outputs.push == 'true' }} # PRs do not have access to secrets + uses: docker/login-action@v2 + with: + registry: ghcr.io + username: ${{ secrets.GH_BOT_NAME }} + password: ${{ secrets.GH_BOT_TOKEN }} + + - name: Build and push + uses: docker/build-push-action@v3 + with: + context: ./ + file: ./Dockerfile + push: ${{ steps.prepare.outputs.push }} + platforms: ${{ steps.prepare.outputs.platforms }} + build-args: | + BRANCH=${{ steps.prepare.outputs.branch }} + COMMIT=${{ steps.prepare.outputs.commit }} + BUILD_DATE=${{ steps.prepare.outputs.build_date }} + tags: ${{ steps.prepare.outputs.tags }} + cache-from: type=local,src=/tmp/.buildx-cache + cache-to: type=local,dest=/tmp/.buildx-cache + + - name: Update Docker Hub Description + if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/master' }} + uses: peter-evans/dockerhub-description@v3 + with: + username: ${{ secrets.DOCKER_HUB_USERNAME }} + password: ${{ secrets.DOCKER_HUB_PASSWORD }} # token is not currently supported + repository: ${{ env.BASE_TAG }} + short-description: ${{ github.event.repository.description }} + readme-filepath: ./DOCKER_README.md diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000000..1ed74b8ca6f --- /dev/null +++ b/Dockerfile @@ -0,0 +1,77 @@ +FROM debian:bullseye AS sunshine-build + +ARG DEBIAN_FRONTEND=noninteractive +ARG TZ="Europe/London" + +SHELL ["/bin/bash", "-o", "pipefail", "-c"] +RUN echo deb http://deb.debian.org/debian/ bullseye main contrib non-free | tee /etc/apt/sources.list.d/non-free.list +RUN apt-get update -y && \ + apt-get install --no-install-recommends -y \ + build-essential \ + cmake \ + rpm \ + libavdevice-dev \ + libboost-filesystem-dev \ + libboost-log-dev \ + libboost-thread-dev \ + libcap-dev \ + libdrm-dev \ + libevdev-dev \ + libpulse-dev \ + libopus-dev \ + libssl-dev \ + libwayland-dev \ + libx11-dev \ + libxcb-shm0-dev \ + libxcb-xfixes0-dev \ + libxcb1-dev \ + libxfixes-dev \ + libxrandr-dev \ + libxtst-dev \ + nvidia-cuda-dev \ + nvidia-cuda-toolkit + +RUN mkdir /root/sunshine +WORKDIR /root/sunshine + +COPY ./* . +RUN mkdir /root/sunshine-build + +# RUN /root/sunshine/scripts/build-sunshine.sh + +WORKDIR /root/sunshine-build + +RUN cmake \ + "-DCMAKE_BUILD_TYPE=Release" \ + "-DCMAKE_INSTALL_PREFIX=/etc" \ + "-DSUNSHINE_ASSETS_DIR=sunshine/assets" \ + "-DSUNSHINE_CONFIG_DIR=sunshine/config" \ + "-DSUNSHINE_EXECUTABLE_PATH=/usr/bin/sunshine" \ + "-DSUNSHINE_ENABLE_WAYLAND=ON" \ + "-DSUNSHINE_ENABLE_X11=ON" \ + "-DSUNSHINE_ENABLE_DRM=ON" \ + "-DSUNSHINE_ENABLE_CUDA=ON" \ + "/root/sunshine" + +RUN make -j ${nproc} + +RUN cpack -G DEB +# RUN cpack -G RPM + +FROM debian:bullseye-slim AS sunshine + +COPY --from=sunshine-build /root/sunshine-build/Sunshine.deb /Sunshine.deb +# COPY --from=sunshine-build /root/sunshine-build/Sunshine.rpm /Sunshine.rpm + +RUN apt-get update -y && \ + apt-get install --no-install-recommends -y -f /Sunshine.deb \ + && rm -rf /var/lib/apt/lists/* + +# Port configuration +# https://github.com/moonlight-stream/moonlight-docs/wiki/Setup-Guide#manual-port-forwarding-advanced +EXPOSE 47984-47990/tcp +EXPOSE 48010 +EXPOSE 48010/udp +EXPOSE 47998-48000/udp + +ENTRYPOINT ["/usr/bin/sunshine"] diff --git a/scripts/Dockerfile-debian b/scripts/Dockerfile-debian deleted file mode 100644 index fc77eb8e989..00000000000 --- a/scripts/Dockerfile-debian +++ /dev/null @@ -1,40 +0,0 @@ -FROM debian:bullseye AS sunshine-debian - -# Debian Bullseye end of life is TBD - -ARG DEBIAN_FRONTEND=noninteractive -ARG TZ="Europe/London" - -SHELL ["/bin/bash", "-o", "pipefail", "-c"] -RUN echo deb http://deb.debian.org/debian/ bullseye main contrib non-free | tee /etc/apt/sources.list.d/non-free.list -RUN apt-get update -y && \ - apt-get install -y \ - build-essential \ - cmake \ - git \ - libavdevice-dev \ - libboost-filesystem-dev \ - libboost-log-dev \ - libboost-thread-dev \ - libcap-dev \ - libdrm-dev \ - libevdev-dev \ - libpulse-dev \ - libopus-dev \ - libssl-dev \ - libwayland-dev \ - libx11-dev \ - libxcb-shm0-dev \ - libxcb-xfixes0-dev \ - libxcb1-dev \ - libxfixes-dev \ - libxrandr-dev \ - libxtst-dev \ - nvidia-cuda-dev \ - nvidia-cuda-toolkit \ - && apt-get clean \ - && rm -rf /var/lib/apt/lists/* - -# Entrypoint -COPY build-private.sh /root/build.sh -ENTRYPOINT ["/root/build.sh", "-deb"] diff --git a/scripts/Dockerfile-fedora_33 b/scripts/Dockerfile-fedora_33 deleted file mode 100644 index 320c6a6748c..00000000000 --- a/scripts/Dockerfile-fedora_33 +++ /dev/null @@ -1,32 +0,0 @@ -FROM fedora:33 AS sunshine-fedora_33 - -# Fedora 33 end of life is November 2021 -# This file remains for reference only - -SHELL ["/bin/bash", "-o", "pipefail", "-c"] -RUN dnf -y update && \ - dnf -y group install "Development Tools" && \ - dnf -y install https://mirrors.rpmfusion.org/free/fedora/rpmfusion-free-release-$(rpm -E %fedora).noarch.rpm https://mirrors.rpmfusion.org/nonfree/fedora/rpmfusion-nonfree-release-$(rpm -E %fedora).noarch.rpm && \ - dnf -y install \ - boost-devel \ - boost-static.x86_64 \ - cmake \ - ffmpeg-devel \ - libevdev-devel \ - libxcb-devel \ - libX11-devel \ - libXfixes-devel \ - libXrandr-devel \ - libXtst-devel \ - openssl-devel \ - opus-devel \ - pulseaudio-libs-devel \ - libcap-devel \ - libdrm-devel \ - rpm-build \ - && dnf clean all \ - && rm -rf /var/cache/yum - -# Entrypoint -COPY build-private.sh /root/build.sh -ENTRYPOINT ["/root/build.sh", "-rpm"] diff --git a/scripts/Dockerfile-fedora_35 b/scripts/Dockerfile-fedora_35 deleted file mode 100644 index 18f5bf53a56..00000000000 --- a/scripts/Dockerfile-fedora_35 +++ /dev/null @@ -1,36 +0,0 @@ -FROM fedora:35 AS sunshine-fedora_35 - -# Fedora 35 end of life is TBD - -SHELL ["/bin/bash", "-o", "pipefail", "-c"] -RUN dnf -y update && \ - dnf -y group install "Development Tools" && \ - dnf -y install https://mirrors.rpmfusion.org/free/fedora/rpmfusion-free-release-$(rpm -E %fedora).noarch.rpm https://mirrors.rpmfusion.org/nonfree/fedora/rpmfusion-nonfree-release-$(rpm -E %fedora).noarch.rpm && \ - dnf -y install \ - boost-devel \ - boost-static.x86_64 \ - cmake \ - ffmpeg-devel \ - gcc-c++ \ - libevdev-devel \ - libX11-devel \ - libxcb-devel \ - libXcursor-devel \ - libXfixes-devel \ - libXinerama-devel \ - libXi-devel \ - libXrandr-devel \ - libXtst-devel \ - mesa-libGL-devel \ - openssl-devel \ - opus-devel \ - pulseaudio-libs-devel \ - libcap-devel \ - libdrm-devel \ - rpm-build \ - && dnf clean all \ - && rm -rf /var/cache/yum - -# Entrypoint -COPY build-private.sh /root/build.sh -ENTRYPOINT ["/root/build.sh", "-rpm"] diff --git a/scripts/Dockerfile-ubuntu_18_04 b/scripts/Dockerfile-ubuntu_18_04 deleted file mode 100644 index 6ad3e8c02ad..00000000000 --- a/scripts/Dockerfile-ubuntu_18_04 +++ /dev/null @@ -1,63 +0,0 @@ -FROM ubuntu:18.04 AS sunshine-ubuntu_18_04 - -# Ubuntu 18.04 end of life is April 2028 - -ARG DEBIAN_FRONTEND=noninteractive -ARG TZ="Europe/London" - -SHELL ["/bin/bash", "-o", "pipefail", "-c"] -RUN apt-get update -y && \ - apt-get install -y \ - software-properties-common \ - && add-apt-repository ppa:savoury1/graphics && \ - add-apt-repository ppa:savoury1/multimedia && \ - add-apt-repository ppa:savoury1/ffmpeg4 && \ - add-apt-repository ppa:savoury1/boost-defaults-1.71 && \ - add-apt-repository ppa:ubuntu-toolchain-r/test && \ - apt-get update -y && \ - apt-get install -y \ - build-essential \ - cmake \ - gcc-10 \ - git \ - g++-10 \ - libavdevice-dev \ - libboost-filesystem1.71-dev \ - libboost-log1.71-dev \ - libboost-regex1.71-dev \ - libboost-thread1.71-dev \ - libcap-dev \ - libdrm-dev \ - libevdev-dev \ - libpulse-dev \ - libopus-dev \ - libssl-dev \ - libwayland-dev \ - libx11-dev \ - libxcb-shm0-dev \ - libxcb-xfixes0-dev \ - libxcb1-dev \ - libxfixes-dev \ - libxrandr-dev \ - libxtst-dev \ - wget \ - && apt-get clean \ - && rm -rf /var/lib/apt/lists/* - -# Update gcc alias -RUN update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-10 100 --slave /usr/bin/g++ g++ /usr/bin/g++-10 - -# Install CuDA -RUN wget https://developer.download.nvidia.com/compute/cuda/11.4.2/local_installers/cuda_11.4.2_470.57.02_linux.run --progress=bar:force:noscroll -q --show-progress -O /root/cuda.run && chmod a+x /root/cuda.run -RUN /root/cuda.run --silent --toolkit --toolkitpath=/usr --no-opengl-libs --no-man-page --no-drm && rm /root/cuda.run - -# Install cmake -ADD https://cmake.org/files/v3.22/cmake-3.22.2-linux-x86_64.sh /cmake-3.22.2-linux-x86_64.sh -RUN mkdir /opt/cmake -RUN sh /cmake-3.22.2-linux-x86_64.sh --prefix=/opt/cmake --skip-license -RUN ln -s /opt/cmake/bin/cmake /usr/local/bin/cmake -RUN cmake --version - -# Entrypoint -COPY build-private.sh /root/build.sh -ENTRYPOINT ["/root/build.sh", "-deb"] diff --git a/scripts/Dockerfile-ubuntu_20_04 b/scripts/Dockerfile-ubuntu_20_04 deleted file mode 100644 index 44e897a7586..00000000000 --- a/scripts/Dockerfile-ubuntu_20_04 +++ /dev/null @@ -1,46 +0,0 @@ -FROM ubuntu:20.04 AS sunshine-ubuntu_20_04 - -# Ubuntu 20.04 end of life is April 2030 - -ARG DEBIAN_FRONTEND=noninteractive -ARG TZ="Europe/London" - -SHELL ["/bin/bash", "-o", "pipefail", "-c"] -RUN apt-get update -y && \ - apt-get install -y \ - build-essential \ - cmake \ - git \ - g++-10 \ - libavdevice-dev \ - libboost-filesystem-dev \ - libboost-log-dev \ - libboost-thread-dev \ - libcap-dev \ - libdrm-dev \ - libevdev-dev \ - libpulse-dev \ - libopus-dev \ - libssl-dev \ - libwayland-dev \ - libx11-dev \ - libxcb-shm0-dev \ - libxcb-xfixes0-dev \ - libxcb1-dev \ - libxfixes-dev \ - libxrandr-dev \ - libxtst-dev \ - wget \ - && apt-get clean \ - && rm -rf /var/lib/apt/lists/* - -# Update gcc alias -RUN update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-10 100 --slave /usr/bin/g++ g++ /usr/bin/g++-10 - -# Install CuDA -RUN wget https://developer.download.nvidia.com/compute/cuda/11.4.2/local_installers/cuda_11.4.2_470.57.02_linux.run --progress=bar:force:noscroll -q --show-progress -O /root/cuda.run && chmod a+x /root/cuda.run -RUN /root/cuda.run --silent --toolkit --toolkitpath=/usr --no-opengl-libs --no-man-page --no-drm && rm /root/cuda.run - -# Entrypoint -COPY build-private.sh /root/build.sh -ENTRYPOINT ["/root/build.sh", "-deb"] diff --git a/scripts/Dockerfile-ubuntu_21_04 b/scripts/Dockerfile-ubuntu_21_04 deleted file mode 100644 index 012845a5b69..00000000000 --- a/scripts/Dockerfile-ubuntu_21_04 +++ /dev/null @@ -1,40 +0,0 @@ -FROM ubuntu:21.04 AS sunshine-ubuntu_21_04 - -# Ubuntu 21.04 end of life is January 2022 -# This file remains for reference only - -ARG DEBIAN_FRONTEND=noninteractive -ARG TZ="Europe/London" - -SHELL ["/bin/bash", "-o", "pipefail", "-c"] -RUN apt-get update -y && \ - apt-get install -y \ - build-essential \ - cmake \ - git \ - libavdevice-dev \ - libboost-thread-dev \ - libboost-filesystem-dev \ - libboost-log-dev \ - libcap-dev \ - libdrm-dev \ - libevdev-dev \ - libpulse-dev \ - libopus-dev \ - libssl-dev \ - libwayland-dev \ - libx11-dev \ - libxcb-shm0-dev \ - libxcb-xfixes0-dev \ - libxcb1-dev \ - libxfixes-dev \ - libxrandr-dev \ - libxtst-dev \ - nvidia-cuda-dev \ - nvidia-cuda-toolkit \ - && apt-get clean \ - && rm -rf /var/lib/apt/lists/* - -# Entrypoint -COPY build-private.sh /root/build.sh -ENTRYPOINT ["/root/build.sh", "-deb"] diff --git a/scripts/Dockerfile-ubuntu_21_10 b/scripts/Dockerfile-ubuntu_21_10 deleted file mode 100644 index 6be49dbe0cb..00000000000 --- a/scripts/Dockerfile-ubuntu_21_10 +++ /dev/null @@ -1,39 +0,0 @@ -FROM ubuntu:21.10 AS sunshine-ubuntu_21_10 - -# Ubuntu 21.10 end of life is July 2022 - -ARG DEBIAN_FRONTEND=noninteractive -ARG TZ="Europe/London" - -SHELL ["/bin/bash", "-o", "pipefail", "-c"] -RUN apt-get update -y && \ - apt-get install -y \ - build-essential \ - cmake \ - git \ - libavdevice-dev \ - libboost-filesystem-dev \ - libboost-log-dev \ - libboost-thread-dev \ - libcap-dev \ - libdrm-dev \ - libevdev-dev \ - libpulse-dev \ - libopus-dev \ - libssl-dev \ - libwayland-dev \ - libx11-dev \ - libxcb-shm0-dev \ - libxcb-xfixes0-dev \ - libxcb1-dev \ - libxfixes-dev \ - libxrandr-dev \ - libxtst-dev \ - nvidia-cuda-dev \ - nvidia-cuda-toolkit \ - && apt-get clean \ - && rm -rf /var/lib/apt/lists/* - -# Entrypoint -COPY build-private.sh /root/build.sh -ENTRYPOINT ["/root/build.sh", "-deb"] diff --git a/scripts/build-container.sh b/scripts/build-container.sh deleted file mode 100755 index 5da4784aef2..00000000000 --- a/scripts/build-container.sh +++ /dev/null @@ -1,179 +0,0 @@ -#!/bin/bash -e -set -e - -usage() { - echo "Usage: $0 [OPTIONS]" - echo " -c: command --> default [build]" - echo " | delete --> Delete the container, Dockerfile isn't mandatory" - echo " | build --> Build the container, Dockerfile is mandatory" - echo " | compile --> Builds the container, then compiles it. Dockerfile is mandatory" - echo "" - echo " -s: path: The path to the source for compilation" - echo " -n: name: Docker container name --> default [sunshine]" - echo " --> all: Build/Compile/Delete all available docker containers" - echo " -f: Dockerfile: The name of the docker file" -} - -# Attempt to turn relative paths into absolute paths -absolute_path() { - RELATIVE_PATH=$1 - if which realpath >/dev/null 2>/dev/null - then - RELATIVE_PATH=$(realpath $RELATIVE_PATH) - else - echo "Warning: realpath is not installed on your system, ensure [$1] is absolute" - fi - - RETURN=$RELATIVE_PATH -} - -CONTAINER_NAME=sunshine -COMMAND=BUILD - -build_container() { - CONTAINER_NAME=$1 - DOCKER_FILE=$2 - - if [ ! -f "$DOCKER_FILE" ] - then - echo "Error: $DOCKER_FILE doesn't exist" - exit 7 - fi - - echo "docker build . -t $CONTAINER_NAME -f $DOCKER_FILE" - docker build . -t "$CONTAINER_NAME" -f "$DOCKER_FILE" -} - -delete() { - CONTAINER_NAME_UPPER=$(echo "$CONTAINER_NAME" | tr '[:lower:]' '[:upper:]') - if [ "$CONTAINER_NAME_UPPER" = "ALL" ] - then - shopt -s nullglob - for file in $(find . -maxdepth 1 -iname "Dockerfile-*" -type f) - do - CURRENT_CONTAINER="sunshine-$(echo $file | cut -c 14-)" - - if docker inspect "$CURRENT_CONTAINER" > /dev/null 2> /dev/null - then - echo "docker rmi $CURRENT_CONTAINER" - docker rmi "$CURRENT_CONTAINER" - fi - done - shopt -u nullglob #revert nullglob back to it's normal default state - else - if docker inspect "$CONTAINER_NAME" > /dev/null 2> /dev/null - then - echo "docker rmi $CONTAINER_NAME" - docker rmi $CONTAINER_NAME - fi - fi -} - -build() { - CONTAINER_NAME_UPPER=$(echo "$CONTAINER_NAME" | tr '[:lower:]' '[:upper:]') - if [ "$CONTAINER_NAME_UPPER" = "ALL" ] - then - shopt -s nullglob - for file in $(find . -maxdepth 1 -iname "Dockerfile-*" -type f) - do - CURRENT_CONTAINER="sunshine-$(echo $file | cut -c 14-)" - build_container "$CURRENT_CONTAINER" "$file" - done - shopt -u nullglob #revert nullglob back to it's normal default state - else - if [[ -z "$DOCKER_FILE" ]] - then - echo "Error: if container name isn't equal to 'all', you need to specify the Dockerfile" - exit 6 - fi - - build_container "$CONTAINER_NAME" "$DOCKER_FILE" - fi -} - -abort() { - echo "$1" - exit 10 -} - -compile() { - CONTAINER_NAME_UPPER=$(echo "$CONTAINER_NAME" | tr '[:lower:]' '[:upper:]') - if [ "$CONTAINER_NAME_UPPER" = "ALL" ] - then - shopt -s nullglob - - # If any docker container doesn't exist, we cannot compile all of them - for file in $(find . -maxdepth 1 -iname "Dockerfile-*" -type f) - do - CURRENT_CONTAINER="sunshine-$(echo $file | cut -c 14-)" - - # If container doesn't exist --> abort. - docker inspect "$CURRENT_CONTAINER" > /dev/null 2> /dev/null || abort "Error: container image [$CURRENT_CONTAINER] doesn't exist" - done - - for file in $(find . -maxdepth 1 -iname "Dockerfile-*" -type f) - do - CURRENT_CONTAINER="sunshine-$(echo $file | cut -c 14-)" - - echo "$PWD/build-sunshine.sh -p -n $CURRENT_CONTAINER $SUNSHINE_SOURCES" - "$PWD/build-sunshine.sh" -p -n "$CURRENT_CONTAINER" $SUNSHINE_SOURCES - done - shopt -u nullglob #revert nullglob back to it's normal default state - else - # If container exists - if docker inspect "$CONTAINER_NAME" > /dev/null 2> /dev/null - then - echo "$PWD/build-sunshine.sh -p -n $CONTAINER_NAME $SUNSHINE_SOURCES" - "$PWD/build-sunshine.sh" -p -n "$CONTAINER_NAME" $SUNSHINE_SOURCES - else - echo "Error: container image [$CONTAINER_NAME] doesn't exist" - exit 9 - fi - fi -} - -while getopts ":c:hn:f:s:" arg; do - case ${arg} in - s) - SUNSHINE_SOURCES="-s $OPTARG" - ;; - c) - COMMAND=$(echo $OPTARG | tr '[:lower:]' '[:upper:]') - ;; - n) - echo "Container name: $OPTARG" - CONTAINER_NAME="$OPTARG" - ;; - f) - echo "Using Dockerfile [$OPTARG]" - DOCKER_FILE="$OPTARG" - ;; - h) - usage - exit 0 - ;; - esac -done - -echo "$0 set to $(echo $COMMAND | tr '[:upper:]' '[:lower:]')" - -if [ "$COMMAND" = "BUILD" ] -then - echo "Start building..." - delete - build - echo "Done." -elif [ "$COMMAND" = "COMPILE" ] -then - echo "Start compiling..." - compile - echo "Done." -elif [ "$COMMAND" = "DELETE" ] -then - echo "Start deleting..." - delete - echo "Done." -else - echo "Unknown command [$(echo $COMMAND | tr '[:upper:]' '[:lower:]')]" - exit 4 -fi diff --git a/scripts/build-private.sh b/scripts/build-private.sh deleted file mode 100755 index 80c7d6bcb49..00000000000 --- a/scripts/build-private.sh +++ /dev/null @@ -1,48 +0,0 @@ -#!/bin/bash -e -set -e - -CMAKE_BUILD_TYPE="${CMAKE_BUILD_TYPE:-Release}" -SUNSHINE_EXECUTABLE_PATH="${SUNSHINE_EXECUTABLE_PATH:-/usr/bin/sunshine}" -SUNSHINE_ASSETS_DIR="${SUNSHINE_ASSETS_DIR:-/etc/sunshine}" - - -SUNSHINE_ROOT="${SUNSHINE_ROOT:-/root/sunshine}" -SUNSHINE_TAG="${SUNSHINE_TAG:-master}" -SUNSHINE_GIT_URL="${SUNSHINE_GIT_URL:-https://github.com/lizardbyte/sunshine.git}" - - -SUNSHINE_ENABLE_WAYLAND=${SUNSHINE_ENABLE_WAYLAND:-ON} -SUNSHINE_ENABLE_X11=${SUNSHINE_ENABLE_X11:-ON} -SUNSHINE_ENABLE_DRM=${SUNSHINE_ENABLE_DRM:-ON} -SUNSHINE_ENABLE_CUDA=${SUNSHINE_ENABLE_CUDA:-ON} - -# For debugging, it would be usefull to have the sources on the host. -if [[ ! -d "$SUNSHINE_ROOT" ]] -then - git clone --depth 1 --branch "$SUNSHINE_TAG" "$SUNSHINE_GIT_URL" --recurse-submodules "$SUNSHINE_ROOT" -fi - -if [[ ! -d /root/sunshine-build ]] -then - mkdir -p /root/sunshine-build -fi -cd /root/sunshine-build - -cmake "-DCMAKE_BUILD_TYPE=$CMAKE_BUILD_TYPE" "-DSUNSHINE_EXECUTABLE_PATH=$SUNSHINE_EXECUTABLE_PATH" "-DSUNSHINE_ASSETS_DIR=$SUNSHINE_ASSETS_DIR" "-DSUNSHINE_ENABLE_WAYLAND=$SUNSHINE_ENABLE_WAYLAND" "-DSUNSHINE_ENABLE_X11=$SUNSHINE_ENABLE_X11" "-DSUNSHINE_ENABLE_DRM=$SUNSHINE_ENABLE_DRM" "-DSUNSHINE_ENABLE_CUDA=$SUNSHINE_ENABLE_CUDA" "$SUNSHINE_ROOT" - -make -j ${nproc} - -# Get preferred package format -if [ "$1" == "-rpm" ] -then - echo "Packaging in .rpm format." - ./gen-rpm -d -elif [ "$1" == "-deb" ] -then - echo "Packaging in .deb format." - ./gen-deb -else - echo "Preferred packaging not specified." - echo "Use -deb or -rpm to specify preferred package format." - exit 1 -fi diff --git a/scripts/build-sunshine.sh b/scripts/build-sunshine.sh index 4284375290b..a815b332f4e 100755 --- a/scripts/build-sunshine.sh +++ b/scripts/build-sunshine.sh @@ -1,132 +1,33 @@ #!/bin/bash -e set -e -usage() { - echo "Usage: $0" - echo " -d: Generate a debug build" - echo " -p: Generate a linux package" - echo " -e: Extension of package... i.e. 'deb', 'rpm' --> default [deb]" - echo " -u: The input device is not a TTY" - echo " -n name: Docker container name --> default [sunshine]" - echo " -s path/to/sources/sunshine: Use local sources instead of a git repository" - echo " -c path/to/cmake/binary/dir: Store cmake output on host OS" -} - -# Attempt to turn relative paths into absolute paths -absolute_path() { - RELATIVE_PATH=$1 - if which realpath >/dev/null 2>/dev/null - then - RELATIVE_PATH=$(realpath $RELATIVE_PATH) - else - echo "Warning: realpath is not installed on your system, ensure [$1] is absolute" - fi - - RETURN=$RELATIVE_PATH -} - -CMAKE_BUILD_TYPE="-e CMAKE_BUILD_TYPE=Release" -SUNSHINE_PACKAGE_BUILD=OFF -SUNSHINE_PACKAGE_EXTENSION=deb -SUNSHINE_GIT_URL=https://github.com/lizardbyte/sunshine.git -CONTAINER_NAME=sunshine - -# Docker will fail if ctrl+c is passed through and the input is not a tty -DOCKER_INTERACTIVE=-ti - -while getopts ":dpuhc:e:s:n:" arg; do - case ${arg} in - u) - echo "Input device is not a TTY" - USERNAME="$USER" - unset DOCKER_INTERACTIVE - ;; - d) - echo "Creating debug build" - CMAKE_BUILD_TYPE="-e CMAKE_BUILD_TYPE=Debug" - ;; - p) - echo "Creating package build" - SUNSHINE_PACKAGE_BUILD=ON - SUNSHINE_ASSETS_DIR="-e SUNSHINE_ASSETS_DIR=/etc/sunshine" - SUNSHINE_EXECUTABLE_PATH="-e SUNSHINE_EXECUTABLE_PATH=/usr/bin/sunshine" - ;; - e) - echo "Defining package extension: $OPTARG" - if [ "$OPTARG" == "deb" ] - then - SUNSHINE_PACKAGE_EXTENSION=$OPTARG - echo "Package extension: deb" - elif [ "$OPTARG" == "rpm" ] - then - SUNSHINE_PACKAGE_EXTENSION=$OPTARG - echo "Package extension: rpm" - else - echo "Package extension not supported: $OPTARG" - echo "Falling back to default package extension: $SUNSHINE_PACKAGE_EXTENSION" - fi - ;; - s) - absolute_path "$OPTARG" - OPTARG="$RETURN" - echo "Using sources from $OPTARG" - SUNSHINE_ROOT="-v $OPTARG:/root/sunshine" - ;; - c) - [ "$USERNAME" == "" ] && USERNAME=$(logname) - - absolute_path "$OPTARG" - OPTARG="$RETURN" - - echo "Using $OPTARG as cmake binary dir" - if [[ ! -d $OPTARG ]] - then - echo "cmake binary dir doesn't exist, a new one will be created." - mkdir -p "$OPTARG" - [ "$USERNAME" == "$USER"] || chown $USERNAME:$USERNAME "$OPTARG" - fi - - CMAKE_ROOT="-v $OPTARG:/root/sunshine-build" - ;; - n) - echo "Container name: $OPTARG" - CONTAINER_NAME=$OPTARG - ;; - h) - usage - exit 0 - ;; - esac -done - -[ "$USERNAME" = "" ] && USERNAME=$(logname) - -BUILD_DIR="$PWD/$CONTAINER_NAME-build" -[ "$SUNSHINE_ASSETS_DIR" = "" ] && SUNSHINE_ASSETS_DIR="-e SUNSHINE_ASSETS_DIR=$BUILD_DIR/assets" -[ "$SUNSHINE_EXECUTABLE_PATH" = "" ] && SUNSHINE_EXECUTABLE_PATH="-e SUNSHINE_EXECUTABLE_PATH=$BUILD_DIR/sunshine" - -echo "docker run $DOCKER_INTERACTIVE --privileged $SUNSHINE_ROOT $CMAKE_ROOT $SUNSHINE_ASSETS_DIR $SUNSHINE_EXECUTABLE_PATH $CMAKE_BUILD_TYPE --name $CONTAINER_NAME $CONTAINER_NAME" -docker run $DOCKER_INTERACTIVE --privileged $SUNSHINE_ROOT $CMAKE_ROOT $SUNSHINE_ASSETS_DIR $SUNSHINE_EXECUTABLE_PATH $CMAKE_BUILD_TYPE --name $CONTAINER_NAME $CONTAINER_NAME - -exit_code=$? - -if [ $exit_code -eq 0 ] -then - mkdir -p $BUILD_DIR - case $SUNSHINE_PACKAGE_BUILD in - ON) - echo "Downloading package to: $BUILD_DIR/$CONTAINER_NAME.$SUNSHINE_PACKAGE_EXTENSION" - docker cp $CONTAINER_NAME:/root/sunshine-build/package-$SUNSHINE_PACKAGE_EXTENSION/sunshine.$SUNSHINE_PACKAGE_EXTENSION "$BUILD_DIR/$CONTAINER_NAME.$SUNSHINE_PACKAGE_EXTENSION" - ;; - *) - echo "Downloading binary and assets to: $BUILD_DIR" - docker cp $CONTAINER_NAME:/root/sunshine/assets "$BUILD_DIR" - docker cp $CONTAINER_NAME:/root/sunshine-build/sunshine "$BUILD_DIR" - ;; - esac - echo "chown --recursive $USERNAME:$USERNAME $BUILD_DIR" - chown --recursive $USERNAME:$USERNAME "$BUILD_DIR" +CMAKE_BUILD_TYPE="${CMAKE_BUILD_TYPE:-Release}" +SUNSHINE_EXECUTABLE_PATH="${SUNSHINE_EXECUTABLE_PATH:-/usr/bin/sunshine}" +SUNSHINE_ROOT="${SUNSHINE_ROOT:-/root/sunshine}" +CMAKE_INSTALL_PREFIX="${CMAKE_INSTALL_PREFIX:-/etc}" +SUNSHINE_ASSETS_DIR="${SUNSHINE_ASSETS_DIR:-sunshine/assets}" +SUNSHINE_CONFIG_DIR="${SUNSHINE_CONFIG_DIR:-sunshine/config}" + +SUNSHINE_ENABLE_WAYLAND=${SUNSHINE_ENABLE_WAYLAND:-ON} +SUNSHINE_ENABLE_X11=${SUNSHINE_ENABLE_X11:-ON} +SUNSHINE_ENABLE_DRM=${SUNSHINE_ENABLE_DRM:-ON} +SUNSHINE_ENABLE_CUDA=${SUNSHINE_ENABLE_CUDA:-ON} + +if [[ ! -d /root/sunshine-build ]]; then + mkdir -p /root/sunshine-build fi - -echo "Removing docker container $CONTAINER_NAME" -docker rm $CONTAINER_NAME +cd /root/sunshine-build + +cmake \ + "-DCMAKE_BUILD_TYPE=$CMAKE_BUILD_TYPE" \ + "-DSUNSHINE_EXECUTABLE_PATH=$SUNSHINE_EXECUTABLE_PATH" \ + "-DSUNSHINE_ENABLE_WAYLAND=$SUNSHINE_ENABLE_WAYLAND" \ + "-DSUNSHINE_ENABLE_X11=$SUNSHINE_ENABLE_X11" \ + "-DSUNSHINE_ENABLE_DRM=$SUNSHINE_ENABLE_DRM" \ + "-DSUNSHINE_ENABLE_CUDA=$SUNSHINE_ENABLE_CUDA" \ + "-DCMAKE_INSTALL_PREFIX=$CMAKE_INSTALL_PREFIX" \ + "-DSUNSHINE_ASSETS_DIR=$SUNSHINE_ASSETS_DIR" \ + "-DSUNSHINE_CONFIG_DIR=$SUNSHINE_CONFIG_DIR" \ + "$SUNSHINE_ROOT" + +make -j ${nproc}