From 5f52900dedddd768244ba50ec7bf2d636043e825 Mon Sep 17 00:00:00 2001 From: Anton Franzluebbers Date: Sun, 6 Nov 2022 19:11:59 -0500 Subject: [PATCH] updated README with instructions for docker and docker-compose versions, added docker-compose config for running both the control panel and server with a shared log volume, reduced size of control panel image, use tuptime because uptime isn't installed anyway --- README.md | 41 +- control-panel/Dockerfile | 41 + control-panel/config.json | 2 +- control-panel/rebuild.bat | 4 + control-panel/src/main.rs | 16 +- control-panel/static/templates/index.hbs | 9 +- docker-compose.yaml | 19 + server/Cargo.lock | 798 ++++++++++++++++++ server/Cargo.toml | 16 + server/Dockerfile | 32 + server/config.json | 6 + server/src/main.rs | 993 +++++++++++++++++++++++ 12 files changed, 1959 insertions(+), 18 deletions(-) create mode 100644 control-panel/Dockerfile create mode 100644 control-panel/rebuild.bat create mode 100644 docker-compose.yaml create mode 100644 server/Cargo.lock create mode 100644 server/Cargo.toml create mode 100644 server/Dockerfile create mode 100644 server/config.json create mode 100644 server/src/main.rs diff --git a/README.md b/README.md index 8032246..f691097 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ -# VelNetServerRust +# VelNet Server -This basic, single-file relay server is designed to be used for network games, and is similar to Photon Realtime in design. It is written in Rust, with a single-threaded, non-blocking design and does not rely on any network frameworks (pure TCP/UDP). A Unity/C# client implementation can be found in our VelNetUnity repository. +This basic, single-file relay server is designed to be used for network games, and is similar to Photon Realtime in design. It is written in Rust, with a single-threaded, non-blocking design and does not rely on any network frameworks (pure TCP/UDP). A Unity/C# client implementation can be found in our [VelNetUnity](https://github.com/velaboratory/VelNetUnity) repository. Like Photon, there is no built-in persistence of rooms or data. Rooms are created when the first client joins and destroyed when the last client leaves. @@ -12,12 +12,45 @@ The server supports both TCP and UDP transports. ## Running -1. Get a linoox server (also runs fine on windows & osx, but the instructions below are for linux) +### Option 1: Pull from Docker Hub + +```sh +docker run -p 5000:5000 velaboratory/velnet +``` + +or + +```sh +docker run -p 5050:5000 --name velnet velaboratory/velnet +``` +To run on a different port and change the name of the container. + +### Option 2: Use docker-compose + +Runs both the control panel and the server. + +```sh +docker compose up -d +``` + +to run, and + +```sh +docker compose stop +``` +to stop. + +This builds the images from the local data in the folder, and doesn't pull anything from Docker Hub. + +### Option 3: Run Rust natively + +1. Get a linoox server (also runs fine on Windows & OSX, but the instructions below are for Linux) 2. Clone this repo -3. Edit config.json to an open port on your firewall +3. Edit `config.json` to an open port on your firewall 4. Modify the `user` field in `control-panel/config.json` to be your username. 5. Install rust through using rustup: https://rustup.rs/ 6. Install: `sudo ./install.sh` 7. Run server: `sudo systemctl start velnet` 8. Run control panel: `sudo systemctl start velnet-control-panel` +9. Install tuptime: `cargo install tuptime` 9. Install onefetch: `cargo install onefetch` diff --git a/control-panel/Dockerfile b/control-panel/Dockerfile new file mode 100644 index 0000000..19675d3 --- /dev/null +++ b/control-panel/Dockerfile @@ -0,0 +1,41 @@ +FROM rust:1.64 as build + +# 1. Create a new empty shell project +RUN USER=root cargo new --bin velnet_control_panel +WORKDIR /velnet_control_panel + +# 2. Copy our manifests +COPY ./Cargo.lock ./Cargo.lock +COPY ./Cargo.toml ./Cargo.toml + +# 3. Build only the dependencies to cache them +RUN cargo build --release && rm src/*.rs + +# 4. Now that the dependency is built, copy your source code +COPY ./src ./src + +# 5. Build for release. +RUN rm ./target/release/deps/velnet_control_panel* +RUN cargo build --release + +# our final base +FROM rust:1.64-slim +WORKDIR /velnet_control_panel + +# RUN apt-get update && apt-get install -y extra-runtime-dependencies && rm -rf /var/lib/apt/lists/* +RUN apt update && apt install -y tuptime + +# copy the build artifact from the build stage +COPY --from=build /velnet_control_panel/target/release/velnet_control_panel . + +# Copy the config files and helper scripts +COPY static static +COPY config.json . +COPY onefetch_file.sh . +COPY git_pull.sh . +COPY compile_server.sh . + +EXPOSE 8080 + +# run +CMD ["./velnet_control_panel"] \ No newline at end of file diff --git a/control-panel/config.json b/control-panel/config.json index 4147840..a9c75c1 100644 --- a/control-panel/config.json +++ b/control-panel/config.json @@ -1,7 +1,7 @@ { "port": 8080, "user": "ntsfranz", - "server_log_file": "../server.log", + "server_log_file": "../logs/server.log", "control_panel_log_file": "control_panel.log", "server_dir": "../", "handlebars_dev_mode": true diff --git a/control-panel/rebuild.bat b/control-panel/rebuild.bat new file mode 100644 index 0000000..cdaa7cb --- /dev/null +++ b/control-panel/rebuild.bat @@ -0,0 +1,4 @@ +docker stop velnet_control_panel +docker build -t velaboratory/velnet_control_panel . +docker rm velnet_control_panel +docker run -d -p 8080:8080 --name velnet_control_panel velaboratory/velnet_control_panel \ No newline at end of file diff --git a/control-panel/src/main.rs b/control-panel/src/main.rs index e2bf4f7..8c01a0a 100644 --- a/control-panel/src/main.rs +++ b/control-panel/src/main.rs @@ -49,24 +49,24 @@ async fn index(hb: web::Data>) -> HttpResponse { // let restarts_log = lines_from_file(config.restarts_log_file); - let uptime = Command::new("uptime") + let uptime = Command::new("tuptime") .output() .expect("failed to execute process"); - let _onefetch = Command::new("sh") - .arg("onefetch_file.sh") - .arg(config.user) - .output() - .expect("failed"); + // let _onefetch = Command::new("sh") + // .arg("onefetch_file.sh") + // .arg(config.user) + // .output() + // .expect("failed"); - let onefetch = fs::read_to_string("onefetch.out").unwrap(); + // let onefetch = fs::read_to_string("onefetch.out").unwrap(); let data = json!({ "log_output": &log_file[(cmp::max((log_file.len() as i64) - 1000, 0) as usize)..], // "restarts_output": &restarts_log[(cmp::max((restarts_log.len() as i64) - 1000, 0) as usize)..], "uptime": format!("{}", String::from_utf8_lossy(&uptime.stdout)), //"onefetch": format!("{}", String::from_utf8_lossy(&onefetch.stdout)) - "onefetch": onefetch.trim_end() + "onefetch": "" }); let body = hb.render("index", &data).unwrap(); diff --git a/control-panel/static/templates/index.hbs b/control-panel/static/templates/index.hbs index ea32a4c..3712404 100644 --- a/control-panel/static/templates/index.hbs +++ b/control-panel/static/templates/index.hbs @@ -18,7 +18,7 @@