From 70860ab83ceece0dc80b4a439700581929aadd6d Mon Sep 17 00:00:00 2001 From: m1k1o Date: Thu, 1 Apr 2021 23:18:50 +0200 Subject: [PATCH] easy development tools. --- .m1k1o/.env.default | 18 ++++++++++++++++++ .m1k1o/README.md | 39 +++++++++++++++++++++++++++++++++++++++ .m1k1o/build | 27 ++++++++++++++++++++++----- .m1k1o/rebuild-server | 21 +++++++++++++++++++++ .m1k1o/serve-client | 29 +++++++++++++++++++++++++++++ .m1k1o/start-server | 32 ++++++++++++++++++++++++++++++++ README.md | 4 ++++ 7 files changed, 165 insertions(+), 5 deletions(-) create mode 100644 .m1k1o/.env.default create mode 100644 .m1k1o/README.md create mode 100755 .m1k1o/rebuild-server create mode 100755 .m1k1o/serve-client create mode 100755 .m1k1o/start-server diff --git a/.m1k1o/.env.default b/.m1k1o/.env.default new file mode 100644 index 0000000..b15828d --- /dev/null +++ b/.m1k1o/.env.default @@ -0,0 +1,18 @@ +# +# you can copy this file to .env.local, if you don't want to have it pushed to repository +# + +# this is how will be your images called. you can change it to your fork. +# only need to do this once. here. +BUILD_IMAGE="m1k1o/neko" + +# this is where your services will be acessible +CLIENT_PORT=8080 +SERVER_PORT=8081 + +# on which image you want to test it +SERVER_TAG="chromium" + +# this is needed for WebRTC. specify your local IP address and free UDP port range. +SERVER_EPR=55000-55009 +SERVER_IP=10.8.0.1 diff --git a/.m1k1o/README.md b/.m1k1o/README.md new file mode 100644 index 0000000..f99db0a --- /dev/null +++ b/.m1k1o/README.md @@ -0,0 +1,39 @@ +# How to contribute to neko + +If you want to contribute, but don't want to install anything on your host system, we got you covered. You only need docker. Technically, it could be donw using vs code development in container, but this is more fun:). + +You need to copy `.env.development` to `.env` and customize values. + +## Step 1: Building server + +- `./build` - You can use this command to build your specified `SERVER_TAG` along with base image. + +If you want, you can build other tags. `base` tag needs to be build first: + +- `./build base` +- `./build firefox` +- `./build chromium` +- etc... + +## Step 2: Starting server + +- `./start-server` - Starting server image you specified in `.env`. +- `./start-server -r` - Shortcut for rebuilding server binary and then starting. + +If you are changing something in the server code, you don't want to rebuild container each time. You can just rebuild your binary: + +- `./rebuild-server` - Rebuild only server binary. +- `./rebuild-server -f` - Force to rebuild whole golang environment (you should do this only of you change some dependencies). + +## Step 3: Seving client + +- `./serve-client` - Serving vue.js client. +- `./serve-client -i` - Install all depenencies. + +## Debug + +You can navigate to `CLIENT_PORT` and see live client there. It will be connected to your local server on `SERVER_PORT`. + +If you are leaving client as is and not changing it, you don't need to start `./serve-client` and you can access server's GUI directly on `SERVER_PORT`. + +Feel free to open new PR. diff --git a/.m1k1o/build b/.m1k1o/build index 9952f6d..70f1a00 100755 --- a/.m1k1o/build +++ b/.m1k1o/build @@ -2,7 +2,24 @@ cd "$(dirname "$0")" BASE="${PWD}/../" -IMAGE="m1k1o/neko" + +if [ -f ".env.default" ] +then + export $(cat .env.default | sed 's/#.*//g' | xargs) +fi + +if [ -f ".env" ] +then + export $(cat .env | sed 's/#.*//g' | xargs) +fi + +if [ -z "${1}" ] && [ ! -z "${SERVER_TAG}" ] +then + ./build base + ./build ${SERVER_TAG} + exit 0 +fi + build_client() { docker build -t neko-dev-client -f base/Dockerfile --target client "${BASE}" @@ -24,10 +41,10 @@ build() { if [ "$1" = "base" ] then # build base - docker build -t "${IMAGE}:base" -f base/Dockerfile "${BASE}" + docker build -t "${BUILD_IMAGE}:base" -f base/Dockerfile "${BASE}" else # buld image - docker build -t "${IMAGE}:$1" -f "$1/Dockerfile" "$1/" + docker build -t "${BUILD_IMAGE}:$1" --build-arg="BASE_IMAGE=${BUILD_IMAGE}:base" -f "$1/Dockerfile" "$1/" fi } @@ -35,10 +52,10 @@ build_arm() { if [ "$1" = "base" ] then # build ARM base - docker build -t "${IMAGE}:arm-base" -f arm-base/Dockerfile "${BASE}" + docker build -t "${BUILD_IMAGE}:arm-base" -f arm-base/Dockerfile "${BASE}" else # buld ARM image - docker build -t "${IMAGE}:arm-$1" --build-arg="BASE_IMAGE=${IMAGE}:arm-base" -f "$1/Dockerfile" "$1/" + docker build -t "${BUILD_IMAGE}:arm-$1" --build-arg="BASE_IMAGE=${BUILD_IMAGE}:arm-base" -f "$1/Dockerfile" "$1/" fi } diff --git a/.m1k1o/rebuild-server b/.m1k1o/rebuild-server new file mode 100755 index 0000000..a46e15a --- /dev/null +++ b/.m1k1o/rebuild-server @@ -0,0 +1,21 @@ +#!/bin/bash + +if [ -f ".env.default" ] +then + export $(cat .env.default | sed 's/#.*//g' | xargs) +fi + +if [ -f ".env" ] +then + export $(cat .env | sed 's/#.*//g' | xargs) +fi + +# use -f to force rebuild +if [ "$(docker images -q neko_dev_server 2> /dev/null)" == "" ] || [ "$1" == "-f" ]; then + docker build -t neko_dev_server -f base/Dockerfile --target server ../ +fi + +docker run --rm -it \ + -v "${PWD}/../server:/src" \ + --entrypoint="go" \ + neko_dev_server build -o "bin/neko" -i "cmd/neko/main.go" diff --git a/.m1k1o/serve-client b/.m1k1o/serve-client new file mode 100755 index 0000000..48053f1 --- /dev/null +++ b/.m1k1o/serve-client @@ -0,0 +1,29 @@ +#!/bin/bash + +if [ -f ".env.default" ] +then + export $(cat .env.default | sed 's/#.*//g' | xargs) +fi + +if [ -f ".env" ] +then + export $(cat .env | sed 's/#.*//g' | xargs) +fi + +# use -i to install +if [ ! -d "${PWD}/../client/node_modules" ] || [ "$1" == "-i" ]; then + docker run --rm -it \ + -v "${PWD}/../client:/app" \ + --workdir="/app" \ + --entrypoint="npm" \ + node:14-buster-slim install +fi + +docker run --rm -it \ + -p "${CLIENT_PORT}:8080" \ + -v "${PWD}/../client:/app" \ + -e "VUE_APP_SERVER_PORT=${SERVER_PORT}" \ + --workdir="/app" \ + --entrypoint="npm" \ + node:14-buster-slim run serve + \ No newline at end of file diff --git a/.m1k1o/start-server b/.m1k1o/start-server new file mode 100755 index 0000000..7613dc8 --- /dev/null +++ b/.m1k1o/start-server @@ -0,0 +1,32 @@ +#!/bin/bash + +if [ -f ".env.default" ] +then + export $(cat .env.default | sed 's/#.*//g' | xargs) +fi + +if [ -f ".env" ] +then + export $(cat .env | sed 's/#.*//g' | xargs) +fi + +BINARY_PATH="${PWD}/../server/bin/neko" + +# use -r to rebuild +if [ ! -f "${BINARY_PATH}" ] || [ "$1" == "-r" ]; then + ./rebuild-server +fi + +docker run --rm -it \ + --name "neko_dev" \ + -p "${SERVER_PORT}:8080" \ + -p "${SERVER_EPR}:${SERVER_EPR}/udp" \ + -e "NEKO_SCREEN=1920x1080@60" \ + -e "NEKO_EPR=${SERVER_EPR}" \ + -e "NEKO_NAT1TO1=${SERVER_IP}" \ + -e "NEKO_ICELITE=true" \ + -e "NEKO_MAX_FPS=25" \ + -v "${BINARY_PATH}:/usr/bin/neko" \ + --shm-size=2G \ + --cap-add SYS_ADMIN \ + ${BUILD_IMAGE}:${SERVER_TAG} diff --git a/README.md b/README.md index a4cc2c6..31ed619 100644 --- a/README.md +++ b/README.md @@ -272,3 +272,7 @@ NEKO_KEY: - e.g. '/certs/key.pem' ``` + +# How to contribute? + +Navigate to `.m1k1o/README.md` for further information.