From 204730450c5d34ffe5963f7a6eae8b04c4859e92 Mon Sep 17 00:00:00 2001 From: Wanjohi <71614375+wanjohiryan@users.noreply.github.com> Date: Sat, 25 May 2024 00:24:45 +0300 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20feat(server):=20Add=20startup=20scr?= =?UTF-8?q?ipt=20(#63)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Description **What issue are you solving (or what feature are you adding) and how are you doing it?** We start the container using supervisord, which is limiting as the user has no way of telling the container what game to run. So, the idea is to run like so: `docker run... ghcr.io/netrisdotme/netris/server: netris-proton /game/yourgame.exe` Co-authored by @djpremier --- .scripts/startup.sh | 24 ++++++++++++++++++++++++ .scripts/supervisord.conf | 3 +++ .scripts/supervisord.d/game.ini | 14 ++++++++++++++ dev/build.sh | 3 +++ dev/run-input.sh | 3 +++ dev/run.sh | 5 +++++ {.scripts/dev => dev}/script.sh | 0 server.Dockerfile | 4 ++-- 8 files changed, 54 insertions(+), 2 deletions(-) create mode 100644 .scripts/startup.sh create mode 100644 .scripts/supervisord.d/game.ini create mode 100644 dev/build.sh create mode 100644 dev/run-input.sh create mode 100644 dev/run.sh rename {.scripts/dev => dev}/script.sh (100%) diff --git a/.scripts/startup.sh b/.scripts/startup.sh new file mode 100644 index 00000000..2ecb9dff --- /dev/null +++ b/.scripts/startup.sh @@ -0,0 +1,24 @@ +#!/bin/bash +#TODO: Fix the warp-input startup problem +if [ -z "$SESSION_ID" ]; then + echo "Error: SESSION_ID environment variable is not set." + exit 1 +fi + +xarg="$*" + +if [ -z "$xarg" ]; then + echo "Error: No command specified to run the game. Exiting." + exit 1 +fi + +#Open udp port to listed for QUIC events on +export PORT=${PORT:-"8080"} + +escaped_xarg=$(printf '%s\n' "$xarg" | sed -e 's/[\/&]/\\&/g') + +sudo sed -i "s|^command.*=.*$|command=bash -c \"$escaped_xarg\"|" /etc/supervisord.d/game.ini + +sudo sed -i 's|^autostart.*=.*$|autostart=true|' /etc/supervisord.d/game.ini + +sudo -E /usr/bin/supervisord -c /etc/supervisord.conf \ No newline at end of file diff --git a/.scripts/supervisord.conf b/.scripts/supervisord.conf index 35eb8828..dfa32fb5 100644 --- a/.scripts/supervisord.conf +++ b/.scripts/supervisord.conf @@ -5,6 +5,9 @@ loglevel=info logfile=/tmp/supervisord.log pidfile=/tmp/supervisord.pid +[include] +files = /etc/supervisord.d/*.ini + [program:entrypoint] command=/etc/entrypoint.sh logfile=/tmp/entrypoint.log diff --git a/.scripts/supervisord.d/game.ini b/.scripts/supervisord.d/game.ini new file mode 100644 index 00000000..2677ad81 --- /dev/null +++ b/.scripts/supervisord.d/game.ini @@ -0,0 +1,14 @@ +[program:game] +priority=30 +autostart=false +autorestart=true +user=netris +# directory=/ +command=netris-proton -r /games/AlanWake.exe +stopsignal=INT +logfile=/tmp/game.log +pidfile=/tmp/game.pid +stopsignal=INT +autostart=true +autorestart=true +redirect_stderr=true \ No newline at end of file diff --git a/dev/build.sh b/dev/build.sh new file mode 100644 index 00000000..4c56f454 --- /dev/null +++ b/dev/build.sh @@ -0,0 +1,3 @@ +#!/bin/bash -e + +docker build -t server -f server.Dockerfile . \ No newline at end of file diff --git a/dev/run-input.sh b/dev/run-input.sh new file mode 100644 index 00000000..c33faebc --- /dev/null +++ b/dev/run-input.sh @@ -0,0 +1,3 @@ +#!/bin/bash -e + +cargo run -- --namespace $SESSION_ID --bind "[::]:8080" https://fst.so:4443 \ No newline at end of file diff --git a/dev/run.sh b/dev/run.sh new file mode 100644 index 00000000..45bd50ae --- /dev/null +++ b/dev/run.sh @@ -0,0 +1,5 @@ +#!/bin/bash -e +NAME="${NAME:-$(head /dev/urandom | LC_ALL=C tr -dc 'a-zA-Z0-9' | head -c 16)}" + +# docker run --gpus all --device=/dev/dri --rm -it --entrypoint /bin/bash -e SESSION_ID=G4r06Kc8vDmwIXPG -v "$(pwd)":/game -p 8080:8080/udp --cap-add=SYS_NICE --cap-add=SYS_ADMIN server +docker run --gpus all --device=/dev/dri --rm -it --entrypoint /bin/bash -e SESSION_ID=$NAME -v "$(pwd)":/game -p 8080:8080/udp --cap-add=SYS_NICE --cap-add=SYS_ADMIN server \ No newline at end of file diff --git a/.scripts/dev/script.sh b/dev/script.sh similarity index 100% rename from .scripts/dev/script.sh rename to dev/script.sh diff --git a/server.Dockerfile b/server.Dockerfile index 7f3e63d2..a5042f65 100644 --- a/server.Dockerfile +++ b/server.Dockerfile @@ -70,8 +70,8 @@ RUN apt-get update && apt-get install --no-install-recommends -y \ COPY --from=ghcr.io/wanjohiryan/netris/warp:nightly /usr/bin/warp /usr/bin/ COPY --from=ghcr.io/games-on-whales/inputtino:stable /inputtino/input-server /inputtino/input-server RUN chmod +x /usr/bin/warp -COPY .scripts/entrypoint.sh .scripts/supervisord.conf /etc/ -RUN chmod 755 /etc/supervisord.conf /etc/entrypoint.sh +COPY .scripts /etc/ +RUN chmod 755 /etc/supervisord.conf /etc/entrypoint.sh /etc/startup.sh USER 1000 ENV SHELL=/bin/bash \