From 8331bdfa4239f8cc866cf7851b3a71c9e5cd3b63 Mon Sep 17 00:00:00 2001 From: MartinOscar <40749467+RMartinOscar@users.noreply.github.com> Date: Wed, 30 Oct 2024 00:30:32 +0100 Subject: [PATCH 1/4] Update Dockerfile --- games/rust/Dockerfile | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/games/rust/Dockerfile b/games/rust/Dockerfile index 8f15aaa..3a11f02 100644 --- a/games/rust/Dockerfile +++ b/games/rust/Dockerfile @@ -1,4 +1,4 @@ -FROM --platform=$TARGETOS/$TARGETARCH debian:bookworm-slim +FROM --platform=$TARGETOS/$TARGETARCH node:18-slim ENV DEBIAN_FRONTEND=noninteractive @@ -6,10 +6,8 @@ RUN dpkg --add-architecture i386 \ && apt update \ && apt upgrade -y \ && apt install -y lib32gcc-s1 lib32stdc++6 unzip curl iproute2 tzdata libgdiplus libsdl2-2.0-0:i386 \ - && curl -sL https://deb.nodesource.com/setup_14.x | bash - \ - && apt install -y nodejs \ && mkdir /node_modules \ - && npm install --prefix / ws \ + && npm install --prefix /node_modules ws \ && useradd -d /home/container -m container USER container From d5d2194f6b1715e5416138d83d875ac3e9c4a392 Mon Sep 17 00:00:00 2001 From: "Michael (Parker) Parker" Date: Thu, 31 Oct 2024 21:58:06 -0400 Subject: [PATCH 2/4] corrected new lines in file ran dos2unix on wrapper.js --- games/rust/wrapper.js | 278 +++++++++++++++++++++--------------------- 1 file changed, 139 insertions(+), 139 deletions(-) diff --git a/games/rust/wrapper.js b/games/rust/wrapper.js index ad79ced..f4f6cc5 100644 --- a/games/rust/wrapper.js +++ b/games/rust/wrapper.js @@ -1,140 +1,140 @@ -#!/usr/bin/env node - -var startupCmd = ""; -const fs = require("fs"); -fs.writeFile("latest.log", "", (err) => { - if (err) console.log("Callback error in appendFile:" + err); -}); - -var args = process.argv.splice(process.execArgv.length + 2); -for (var i = 0; i < args.length; i++) { - if (i === args.length - 1) { - startupCmd += args[i]; - } else { - startupCmd += args[i] + " "; - } -} - -if (startupCmd.length < 1) { - console.log("Error: Please specify a startup command."); - process.exit(); -} - -const seenPercentage = {}; - -function filter(data) { - const str = data.toString(); - if (str.startsWith("Loading Prefab Bundle ")) { // Rust seems to spam the same percentage, so filter out any duplicates. - const percentage = str.substr("Loading Prefab Bundle ".length); - if (seenPercentage[percentage]) return; - - seenPercentage[percentage] = true; - } - - console.log(str); -} - -var exec = require("child_process").exec; -console.log("Starting Rust..."); - -var exited = false; -const gameProcess = exec(startupCmd); -gameProcess.stdout.on('data', filter); -gameProcess.stderr.on('data', filter); -gameProcess.on('exit', function (code, signal) { - exited = true; - - if (code) { - console.log("Main game process exited with code " + code); - // process.exit(code); - } -}); - -function initialListener(data) { - const command = data.toString().trim(); - if (command === 'quit') { - gameProcess.kill('SIGTERM'); - } else { - console.log('Unable to run "' + command + '" due to RCON not being connected yet.'); - } -} -process.stdin.resume(); -process.stdin.setEncoding("utf8"); -process.stdin.on('data', initialListener); - -process.on('exit', function (code) { - if (exited) return; - - console.log("Received request to stop the process, stopping the game..."); - gameProcess.kill('SIGTERM'); -}); - -var waiting = true; -var poll = function () { - function createPacket(command) { - var packet = { - Identifier: -1, - Message: command, - Name: "WebRcon" - }; - return JSON.stringify(packet); - } - - var serverHostname = process.env.RCON_IP ? process.env.RCON_IP : "localhost"; - var serverPort = process.env.RCON_PORT; - var serverPassword = process.env.RCON_PASS; - var WebSocket = require("ws"); - var ws = new WebSocket("ws://" + serverHostname + ":" + serverPort + "/" + serverPassword); - - ws.on("open", function open() { - console.log("Connected to RCON. Generating the map now. Please wait until the server status switches to \"Running\"."); - waiting = false; - - // Hack to fix broken console output - ws.send(createPacket('status')); - - process.stdin.removeListener('data', initialListener); - gameProcess.stdout.removeListener('data', filter); - gameProcess.stderr.removeListener('data', filter); - process.stdin.on('data', function (text) { - ws.send(createPacket(text)); - }); - }); - - ws.on("message", function (data, flags) { - try { - var json = JSON.parse(data); - if (json !== undefined) { - if (json.Message !== undefined && json.Message.length > 0) { - console.log(json.Message); - const fs = require("fs"); - fs.appendFile("latest.log", "\n" + json.Message, (err) => { - if (err) console.log("Callback error in appendFile:" + err); - }); - } - } else { - console.log("Error: Invalid JSON received"); - } - } catch (e) { - if (e) { - console.log(e); - } - } - }); - - ws.on("error", function (err) { - waiting = true; - console.log("Waiting for RCON to come up..."); - setTimeout(poll, 5000); - }); - - ws.on("close", function () { - if (!waiting) { - console.log("Connection to server closed."); - - exited = true; - process.exit(); - } - }); -} +#!/usr/bin/env node + +var startupCmd = ""; +const fs = require("fs"); +fs.writeFile("latest.log", "", (err) => { + if (err) console.log("Callback error in appendFile:" + err); +}); + +var args = process.argv.splice(process.execArgv.length + 2); +for (var i = 0; i < args.length; i++) { + if (i === args.length - 1) { + startupCmd += args[i]; + } else { + startupCmd += args[i] + " "; + } +} + +if (startupCmd.length < 1) { + console.log("Error: Please specify a startup command."); + process.exit(); +} + +const seenPercentage = {}; + +function filter(data) { + const str = data.toString(); + if (str.startsWith("Loading Prefab Bundle ")) { // Rust seems to spam the same percentage, so filter out any duplicates. + const percentage = str.substr("Loading Prefab Bundle ".length); + if (seenPercentage[percentage]) return; + + seenPercentage[percentage] = true; + } + + console.log(str); +} + +var exec = require("child_process").exec; +console.log("Starting Rust..."); + +var exited = false; +const gameProcess = exec(startupCmd); +gameProcess.stdout.on('data', filter); +gameProcess.stderr.on('data', filter); +gameProcess.on('exit', function (code, signal) { + exited = true; + + if (code) { + console.log("Main game process exited with code " + code); + // process.exit(code); + } +}); + +function initialListener(data) { + const command = data.toString().trim(); + if (command === 'quit') { + gameProcess.kill('SIGTERM'); + } else { + console.log('Unable to run "' + command + '" due to RCON not being connected yet.'); + } +} +process.stdin.resume(); +process.stdin.setEncoding("utf8"); +process.stdin.on('data', initialListener); + +process.on('exit', function (code) { + if (exited) return; + + console.log("Received request to stop the process, stopping the game..."); + gameProcess.kill('SIGTERM'); +}); + +var waiting = true; +var poll = function () { + function createPacket(command) { + var packet = { + Identifier: -1, + Message: command, + Name: "WebRcon" + }; + return JSON.stringify(packet); + } + + var serverHostname = process.env.RCON_IP ? process.env.RCON_IP : "localhost"; + var serverPort = process.env.RCON_PORT; + var serverPassword = process.env.RCON_PASS; + var WebSocket = require("ws"); + var ws = new WebSocket("ws://" + serverHostname + ":" + serverPort + "/" + serverPassword); + + ws.on("open", function open() { + console.log("Connected to RCON. Generating the map now. Please wait until the server status switches to \"Running\"."); + waiting = false; + + // Hack to fix broken console output + ws.send(createPacket('status')); + + process.stdin.removeListener('data', initialListener); + gameProcess.stdout.removeListener('data', filter); + gameProcess.stderr.removeListener('data', filter); + process.stdin.on('data', function (text) { + ws.send(createPacket(text)); + }); + }); + + ws.on("message", function (data, flags) { + try { + var json = JSON.parse(data); + if (json !== undefined) { + if (json.Message !== undefined && json.Message.length > 0) { + console.log(json.Message); + const fs = require("fs"); + fs.appendFile("latest.log", "\n" + json.Message, (err) => { + if (err) console.log("Callback error in appendFile:" + err); + }); + } + } else { + console.log("Error: Invalid JSON received"); + } + } catch (e) { + if (e) { + console.log(e); + } + } + }); + + ws.on("error", function (err) { + waiting = true; + console.log("Waiting for RCON to come up..."); + setTimeout(poll, 5000); + }); + + ws.on("close", function () { + if (!waiting) { + console.log("Connection to server closed."); + + exited = true; + process.exit(); + } + }); +} poll(); \ No newline at end of file From 51edfd31b64107b635a3423a48dbcf624916f1a9 Mon Sep 17 00:00:00 2001 From: "Michael (Parker) Parker" Date: Thu, 31 Oct 2024 21:59:23 -0400 Subject: [PATCH 3/4] Changed wrapper location Installing `node_modules` in `/` fails made a directory named `/wrapper/` and moved files there to resolve. updated entrypoint to match new location. --- games/rust/Dockerfile | 8 ++++---- games/rust/entrypoint.sh | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/games/rust/Dockerfile b/games/rust/Dockerfile index 3a11f02..540f444 100644 --- a/games/rust/Dockerfile +++ b/games/rust/Dockerfile @@ -6,8 +6,8 @@ RUN dpkg --add-architecture i386 \ && apt update \ && apt upgrade -y \ && apt install -y lib32gcc-s1 lib32stdc++6 unzip curl iproute2 tzdata libgdiplus libsdl2-2.0-0:i386 \ - && mkdir /node_modules \ - && npm install --prefix /node_modules ws \ + && mkdir /wrapper \ + && npm install --prefix /wrapper ws \ && useradd -d /home/container -m container USER container @@ -16,6 +16,6 @@ ENV USER=container HOME=/home/container WORKDIR /home/container COPY ./entrypoint.sh /entrypoint.sh -COPY ./wrapper.js /wrapper.js +COPY ./wrapper.js /wrapper/wrapper.js -CMD [ "/bin/bash", "/entrypoint.sh" ] +CMD [ "/bin/bash", "/entrypoint.sh" ] \ No newline at end of file diff --git a/games/rust/entrypoint.sh b/games/rust/entrypoint.sh index e7c7dbf..03b51fb 100644 --- a/games/rust/entrypoint.sh +++ b/games/rust/entrypoint.sh @@ -45,4 +45,4 @@ fi export LD_LIBRARY_PATH=$(pwd)/RustDedicated_Data/Plugins/x86_64:$(pwd) # Run the Server -wrapper "${MODIFIED_STARTUP}" \ No newline at end of file +/wrapper/wrapper.js "${MODIFIED_STARTUP}" \ No newline at end of file From 0568f685282e45719ab32b522b7a3041d99859b9 Mon Sep 17 00:00:00 2001 From: "Michael (Parker) Parker" Date: Thu, 31 Oct 2024 22:55:26 -0400 Subject: [PATCH 4/4] Make wrapper executable forgot this part, --- games/rust/wrapper.js | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 games/rust/wrapper.js diff --git a/games/rust/wrapper.js b/games/rust/wrapper.js old mode 100644 new mode 100755