move server to server directory.

This commit is contained in:
Miroslav Šedivý
2024-06-23 17:48:14 +02:00
parent da45f62ca8
commit 5b98344205
211 changed files with 18 additions and 10 deletions

23
server/dev/build Executable file
View File

@ -0,0 +1,23 @@
#!/bin/bash
cd "$(dirname "$0")"
#
# aborting if any command returns a non-zero value
set -e
GIT_COMMIT=`git rev-parse --short HEAD`
GIT_BRANCH=`git rev-parse --symbolic-full-name --abbrev-ref HEAD`
# if first argument is nvidia, use nvidia dockerfile
if [ "$1" = "nvidia" ]; then
echo "Building nvidia docker image"
DOCKERFILE="Dockerfile.nvidia"
else
echo "Building default docker image"
DOCKERFILE="Dockerfile"
fi
docker build -t neko_server_build --target build --build-arg "GIT_COMMIT=$GIT_COMMIT" --build-arg "GIT_BRANCH=$GIT_BRANCH" -f ../$DOCKERFILE ..
docker build -t neko_server_runtime --target runtime --build-arg "GIT_COMMIT=$GIT_COMMIT" --build-arg "GIT_BRANCH=$GIT_BRANCH" -f ../$DOCKERFILE ..
docker build -t neko_server_app --build-arg "BASE_IMAGE=neko_server_runtime" -f ./runtime/Dockerfile ./runtime

3
server/dev/exec Executable file
View File

@ -0,0 +1,3 @@
#!/bin/bash
docker exec -it neko_server_dev /bin/bash

12
server/dev/fmt Executable file
View File

@ -0,0 +1,12 @@
#!/bin/bash
cd "$(dirname "$0")"
if [ "$(docker images -q neko_server_build 2> /dev/null)" == "" ]; then
echo "Image 'neko_server_build' not found. Run ./build first."
exit 1
fi
docker run -it --rm \
--entrypoint="go" \
-v "${PWD}/../:/src" \
neko_server_build fmt ./...

25
server/dev/go Executable file
View File

@ -0,0 +1,25 @@
#!/bin/bash
cd "$(dirname "$0")"
if [ "$(docker images -q neko_server_build 2> /dev/null)" == "" ]; then
echo "Image 'neko_server_build' not found. Run ./build first."
exit 1
fi
docker run -it \
--name "neko_server_go" \
--entrypoint="go" \
-v "${PWD}/../:/src" \
neko_server_build "$@";
#
# copy package files
docker cp neko_server_go:/src/go.mod "../go.mod"
docker cp neko_server_go:/src/go.sum "../go.sum"
#
# commit changes to image
docker commit "neko_server_go" "neko_server_build"
#
# remove contianer
docker rm "neko_server_go"

14
server/dev/lint Executable file
View File

@ -0,0 +1,14 @@
#!/bin/bash
cd "$(dirname "$0")"
if [ "$(docker images -q neko_server_build 2> /dev/null)" == "" ]; then
echo "Image 'neko_server_build' not found. Run ./build first."
exit 1
fi
#
# build server
docker run --rm -it \
-v "${PWD}/../:/src" \
--entrypoint="/bin/bash" \
neko_server_build -c '[ -f ./bin/golangci-lint ] || curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s v1.31.0;./bin/golangci-lint run';

32
server/dev/rebuild Executable file
View File

@ -0,0 +1,32 @@
#!/bin/bash
cd "$(dirname "$0")"
#
# aborting if any command returns a non-zero value
set -e
#
# build server
docker run --rm -it \
-v "${PWD}/../:/src" \
--entrypoint="/bin/bash" \
neko_server_build "./build" "$@";
#
# remove old plugins
docker exec neko_server_dev rm -rf /etc/neko/plugins
#
# replace server binary in container
docker cp "${PWD}/../bin/neko" neko_server_dev:/usr/bin/neko
#
# replace plugin binaries in container
if [ -d "${PWD}/../bin/plugins" ];
then
docker cp "${PWD}/../bin/plugins" neko_server_dev:/etc/neko/plugins
fi
#
# restart server
docker exec neko_server_dev supervisorctl -c /etc/neko/supervisord.conf restart neko

32
server/dev/rebuild.input Executable file
View File

@ -0,0 +1,32 @@
#!/bin/bash
cd "$(dirname "$0")"
cd ../xorg/xf86-input-neko
#
# aborting if any command returns a non-zero value
set -e
#
# check if docker image exists
if [ -z "$(docker images -q xf86-input-neko)" ]; then
echo "Docker image not found, building it"
docker build -t xf86-input-neko .
fi
#
# if there is no ./configure script, run autogen.sh and configure
if [ ! -f ./configure ]; then
docker run -v $PWD/:/app --rm xf86-input-neko bash -c './autogen.sh && ./configure'
fi
#
# make install
docker run -v $PWD/:/app --rm xf86-input-neko bash -c 'make && make install DESTDIR=/app/build'
#
# replace input driver in container
docker cp "${PWD}/build/usr/local/lib/xorg/modules/input/neko_drv.so" neko_server_dev:/usr/lib/xorg/modules/input/neko_drv.so
#
# restart server
docker exec neko_server_dev supervisorctl -c /etc/neko/supervisord.conf restart x-server

View File

@ -0,0 +1,31 @@
ARG BASE_IMAGE=neko_server_runtime:latest
FROM $BASE_IMAGE
ARG SRC_URL="https://download.mozilla.org/?product=firefox-latest&os=linux64&lang=en-US"
#
# install xfce and firefox
RUN set -eux; apt-get update; \
apt-get install -y --no-install-recommends \
dbus-x11 xfce4 xfce4-terminal sudo \
xz-utils bzip2 libgtk-3-0 libdbus-glib-1-2; \
#
# fetch latest firefox release
wget -O /tmp/firefox-setup.tar.bz2 "${SRC_URL}"; \
mkdir /usr/lib/firefox; \
tar -xjf /tmp/firefox-setup.tar.bz2 -C /usr/lib; \
rm -f /tmp/firefox-setup.tar.bz2; \
ln -s /usr/lib/firefox/firefox /usr/bin/firefox; \
#
# add user to sudoers
usermod -aG sudo neko; \
echo "neko:neko" | chpasswd; \
echo "%sudo ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers; \
# clean up
apt-get --purge autoremove -y xz-utils bzip2; \
apt-get clean -y; \
rm -rf /var/lib/apt/lists/* /var/cache/apt/*
#
# copy configuation files
COPY supervisord.conf /etc/neko/supervisord/xfce.conf

View File

@ -0,0 +1,101 @@
capture:
video:
codec: h264
ids:
- nvh264enc
- x264enc
pipelines:
nvh264enc:
fps: 25
bitrate: 2
#gst_prefix: "! cudaupload ! cudaconvert ! video/x-raw(memory:CUDAMemory),format=NV12"
gst_prefix: "! video/x-raw,format=NV12"
gst_encoder: "nvh264enc"
gst_params:
bitrate: 3000
rc-mode: 5 # Low-Delay CBR, High Quality
preset: 5 # Low Latency, High Performance
zerolatency: true
gop-size: 25
gst_suffix: "! h264parse config-interval=-1 ! video/x-h264,stream-format=byte-stream,profile=constrained-baseline"
x264enc:
fps: 25
bitrate: 1
gst_prefix: "! video/x-raw,format=I420"
gst_encoder: "x264enc"
gst_params:
threads: 4
bitrate: 4096
key-int-max: 25
byte-stream: true
tune: zerolatency
speed-preset: veryfast
gst_suffix: "! video/x-h264,stream-format=byte-stream,profile=constrained-baseline"
server:
pprof: true
desktop:
screen: "1920x1080@60"
member:
provider: "object"
object:
users:
- username: "admin"
password: "admin"
profile:
name: "Administrator"
is_admin: true
can_login: true
can_connect: true
can_watch: true
can_host: true
can_share_media: true
can_access_clipboard: true
sends_inactive_cursor: true
can_see_inactive_cursors: true
- username: "user"
password: "neko"
profile:
name: "User"
is_admin: false
can_login: true
can_connect: true
can_watch: true
can_host: true
can_share_media: true
can_access_clipboard: true
sends_inactive_cursor: true
can_see_inactive_cursors: false
# provider: "file"
# file:
# path: "/home/neko/members.json"
# provider: "multiuser"
# multiuser:
# admin_password: "admin"
# user_password: "neko"
# provider: "noauth"
session:
# Allows reconnecting the websocket even if the previous
# connection was not closed. Can lead to session hijacking.
merciful_reconnect: true
# Show inactive cursors on the screen. Can lead to multiple
# data sent via WebSockets and additonal rendering cost on
# the clients.
inactive_cursors: true
api_token: "neko123"
cookie:
# Disabling cookies will result to use Bearer Authentication.
# This is less secure, because access token will be sent to
# client in playload and accessible via JS app.
enabled: false
secure: false
webrtc:
icelite: true
iceservers:
- urls: [ stun:stun.l.google.com:19302 ]
# username: foo
# credential: bar

View File

@ -0,0 +1,143 @@
capture:
video:
codec: vp8
ids: [ hq, lq ]
pipelines:
hq:
fps: 25
gst_encoder: vp8enc
gst_params:
target-bitrate: round(3072 * 650)
cpu-used: 4
end-usage: cbr
threads: 4
deadline: 1
undershoot: 95
buffer-size: (3072 * 4)
buffer-initial-size: (3072 * 2)
buffer-optimal-size: (3072 * 3)
keyframe-max-dist: 25
min-quantizer: 4
max-quantizer: 20
lq:
fps: 25
gst_encoder: vp8enc
gst_params:
target-bitrate: round(1024 * 650)
cpu-used: 4
end-usage: cbr
threads: 4
deadline: 1
undershoot: 95
buffer-size: (1024 * 4)
buffer-initial-size: (1024 * 2)
buffer-optimal-size: (1024 * 3)
keyframe-max-dist: 25
min-quantizer: 4
max-quantizer: 20
# video:
# codec: h264
# ids: [ main ]
# pipelines:
# main:
# width: (width / 3) * 2
# height: (height / 3) * 2
# fps: 20
# gst_prefix: "! video/x-raw,format=I420"
# gst_encoder: "x264enc"
# gst_params:
# threads: 4
# bitrate: 4096
# key-int-max: 15
# byte-stream: true
# tune: zerolatency
# speed-preset: veryfast
# gst_suffix: "! video/x-h264,stream-format=byte-stream"
screencast:
enabled: true
server:
pprof: true
desktop:
screen: "1920x1080@60"
member:
provider: "object"
object:
users:
- username: "admin"
password: "admin"
profile:
name: "Administrator"
is_admin: true
can_login: true
can_connect: true
can_watch: true
can_host: true
can_share_media: true
can_access_clipboard: true
sends_inactive_cursor: true
can_see_inactive_cursors: true
- username: "user"
password: "neko"
profile:
name: "User"
is_admin: false
can_login: true
can_connect: true
can_watch: true
can_host: true
can_share_media: true
can_access_clipboard: true
sends_inactive_cursor: true
can_see_inactive_cursors: false
# provider: "file"
# file:
# path: "/home/neko/members.json"
# provider: "multiuser"
# multiuser:
# admin_password: "admin"
# user_password: "neko"
# admin_profile: # optional
# user_profile: # optional
# provider: "noauth"
session:
# Allows reconnecting the websocket even if the previous
# connection was not closed. Can lead to session hijacking.
merciful_reconnect: true
# Show inactive cursors on the screen. Can lead to multiple
# data sent via WebSockets and additonal rendering cost on
# the clients.
inactive_cursors: true
api_token: "neko123"
cookie:
# Disabling cookies will result to use Bearer Authentication.
# This is less secure, because access token will be sent to
# client in playload and accessible via JS app.
enabled: false
secure: false
webrtc:
icelite: true
iceservers:
# Backend servers are ignored if icelite is true.
backend:
- urls: [ stun:stun.l.google.com:19302 ]
frontend:
- urls: [ stun:stun.l.google.com:19305 ]
#username: foo
#credential: bar
# estimator:
# enabled: true
# passive: false
# debug: true
# initial_bitrate: 1000000
# read_interval: 1s
# stable_duration: 10s
# unstable_duration: 5s
# stalled_duration: 20s
# downgrade_backoff: 10s
# upgrade_backoff: 30s
# diff_threshold: 0.5

View File

@ -0,0 +1,10 @@
[program:xfce]
environment=HOME="/home/%(ENV_USER)s",USER="%(ENV_USER)s",DISPLAY="%(ENV_DISPLAY)s"
command=/usr/bin/startxfce4
stopsignal=INT
autorestart=true
priority=500
user=%(ENV_USER)s
stdout_logfile=/dev/stderr
stdout_logfile_maxbytes=0
redirect_stderr=true

64
server/dev/start Executable file
View File

@ -0,0 +1,64 @@
#!/bin/bash
cd "$(dirname "$0")"
if [ -z "$(docker images -q neko_server_app 2> /dev/null)" ]; then
echo "Image 'neko_server_app' not found. Running ./build first."
./build
fi
if [ -z $NEKO_PORT ]; then
NEKO_PORT="3000"
fi
if [ -z $NEKO_MUX ]; then
NEKO_MUX="52100"
fi
if [ -z $NEKO_NAT1TO1 ]; then
for i in $(ifconfig -l 2>/dev/null); do
NEKO_NAT1TO1=$(ipconfig getifaddr $i)
if [ ! -z $NEKO_NAT1TO1 ]; then
break
fi
done
if [ -z $NEKO_NAT1TO1 ]; then
NEKO_NAT1TO1=$(hostname -I 2>/dev/null | awk '{print $1}')
fi
if [ -z $NEKO_NAT1TO1 ]; then
NEKO_NAT1TO1=$(hostname -i 2>/dev/null)
fi
fi
# if first argument is nvidia, start with nvidia runtime
if [ "$1" = "nvidia" ]; then
echo "Starting nvidia docker image"
EXTRAOPTS="--gpus all"
CONFIG="config.nvidia.yml"
else
echo "Starting default docker image"
EXTRAOPTS=""
CONFIG="config.yml"
fi
echo "Using app port: ${NEKO_PORT}"
echo "Using mux port: ${NEKO_MUX}"
echo "Using IP address: ${NEKO_NAT1TO1}"
# start server
docker run --rm -it \
--name "neko_server_dev" \
-p "${NEKO_PORT}:8080" \
-p "${NEKO_MUX}:${NEKO_MUX}/tcp" \
-p "${NEKO_MUX}:${NEKO_MUX}/udp" \
-e "NEKO_WEBRTC_UDPMUX=${NEKO_MUX}" \
-e "NEKO_WEBRTC_TCPMUX=${NEKO_MUX}" \
-e "NEKO_WEBRTC_NAT1TO1=${NEKO_NAT1TO1}" \
-e "NEKO_SESSION_FILE=/home/neko/sessions.txt" \
-v "${PWD}/runtime/$CONFIG:/etc/neko/neko.yml" \
-e "NEKO_DEBUG=1" \
--shm-size=2G \
--security-opt seccomp=unconfined \
$EXTRAOPTS \
neko_server_app:latest;