From 9874226646ba4a7920b3906c12aa2316f0466aed Mon Sep 17 00:00:00 2001 From: Unknown Date: Thu, 6 Jul 2017 23:40:39 -0400 Subject: [PATCH 1/6] Add Rust container --- Dockerfile | 22 +++++++++++++ README.md | 3 +- entrypoint.sh | 14 +++++++++ wrapper.js | 85 +++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 122 insertions(+), 2 deletions(-) create mode 100644 Dockerfile create mode 100644 entrypoint.sh create mode 100644 wrapper.js diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..b0273c5 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,22 @@ +FROM ubuntu:16.04 + +MAINTAINER Isaac A., + +RUN apt update && \ + apt upgrade -y && \ + apt install -y lib32gcc1 lib32stdc++6 curl && \ + curl -sL https://deb.nodesource.com/setup_6.x | bash - && \ + apt install -y nodejs && \ + useradd -d /home/container -m container + +USER container +ENV USER container +ENV HOME /home/container + +WORKDIR /home/container + +COPY ./entrypoint.sh /entrypoint.sh +COPY ./wrapper.js /wrapper.js +COPY ./node_modules/ /node_modules/ + +CMD ["/bin/bash", "/entrypoint.sh"] diff --git a/README.md b/README.md index 6362937..2f1d5ef 100644 --- a/README.md +++ b/README.md @@ -1,2 +1 @@ -# Containers -Generic docker containers designed to work with Pterodactyl Panel and its daemon. +# Rust diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100644 index 0000000..c89f06d --- /dev/null +++ b/entrypoint.sh @@ -0,0 +1,14 @@ +#!/bin/bash +sleep 2 + +cd /home/container + +# Update Rust Server +./steam/steamcmd.sh +login anonymous +force_install_dir /home/container +app_update 258550 +quit + +# Replace Startup Variables +MODIFIED_STARTUP=`eval echo $(echo ${STARTUP} | sed -e 's/{{/${/g' -e 's/}}/}/g')` +echo ":/home/container$ ${MODIFIED_STARTUP}" + +# Run the Server +node /wrapper.js "${MODIFIED_STARTUP}" diff --git a/wrapper.js b/wrapper.js new file mode 100644 index 0000000..3f61a94 --- /dev/null +++ b/wrapper.js @@ -0,0 +1,85 @@ +#!/usr/bin/env node + +var startupCmd = ""; +const fs = require("fs"); +fs.writeFile("latest.log", ""); + +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(); +} + +var exec = require("child_process").exec; +console.log("Starting Rust..."); +exec(startupCmd); + +var waiting = true; + +var poll = function( ) { + function createPacket(command) { + var packet = { + Identifier: -1, + Message: command, + Name: "WebRcon" + }; + return JSON.stringify(packet); + } + + var serverHostname = "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() { + waiting = false; + process.stdin.resume(); + process.stdin.setEncoding("utf8"); + var util = require("util"); + 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); + } + } 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."); + process.exit(); + } + }); +} +poll(); From 41e8bf3185d374d6171eb27e8c7841b49caa32c2 Mon Sep 17 00:00:00 2001 From: Unknown Date: Sun, 9 Jul 2017 21:17:44 -0400 Subject: [PATCH 2/6] Install 'ws' in Dockerfile --- Dockerfile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index b0273c5..9994dd3 100644 --- a/Dockerfile +++ b/Dockerfile @@ -7,6 +7,8 @@ RUN apt update && \ apt install -y lib32gcc1 lib32stdc++6 curl && \ curl -sL https://deb.nodesource.com/setup_6.x | bash - && \ apt install -y nodejs && \ + mkdir /node_modules && \ + npm install --prefix / ws && \ useradd -d /home/container -m container USER container @@ -17,6 +19,5 @@ WORKDIR /home/container COPY ./entrypoint.sh /entrypoint.sh COPY ./wrapper.js /wrapper.js -COPY ./node_modules/ /node_modules/ CMD ["/bin/bash", "/entrypoint.sh"] From 065be5e2993ca84f2ffe1c32e964c4c37f1b70a7 Mon Sep 17 00:00:00 2001 From: Unknown Date: Sun, 9 Jul 2017 21:52:30 -0400 Subject: [PATCH 3/6] Detect if OXIDE_FLAG exists, and update OxideMod if it does. --- entrypoint.sh | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/entrypoint.sh b/entrypoint.sh index c89f06d..4e97c75 100644 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -10,5 +10,12 @@ cd /home/container MODIFIED_STARTUP=`eval echo $(echo ${STARTUP} | sed -e 's/{{/${/g' -e 's/}}/}/g')` echo ":/home/container$ ${MODIFIED_STARTUP}" +if [ -f OXIDE_FLAG ]; then + echo "Updating OxideMod..." + curl "https://dl.bintray.com/oxidemod/builds/Oxide-Rust.zip" > oxide.zip + unzip oxide.zip + rm oxide.zip +fi + # Run the Server node /wrapper.js "${MODIFIED_STARTUP}" From 2e9c27f36adefc7c8799e3637ad563000ddc1013 Mon Sep 17 00:00:00 2001 From: Unknown Date: Sun, 9 Jul 2017 21:59:36 -0400 Subject: [PATCH 4/6] A way to do it without variables Found in the OxideMod example start script. Needs testing, but I'd imagine it works. --- entrypoint.sh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/entrypoint.sh b/entrypoint.sh index 4e97c75..0c5805e 100644 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -17,5 +17,8 @@ if [ -f OXIDE_FLAG ]; then rm oxide.zip fi +# Fix for Rust not starting +export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$(pwd) + # Run the Server node /wrapper.js "${MODIFIED_STARTUP}" From 5961d671744edc18a72bc9090c50d2f5a2ee14fa Mon Sep 17 00:00:00 2001 From: Unknown Date: Sun, 9 Jul 2017 22:25:53 -0400 Subject: [PATCH 5/6] Add unzip to Dockerfile --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 9994dd3..66054ca 100644 --- a/Dockerfile +++ b/Dockerfile @@ -4,7 +4,7 @@ MAINTAINER Isaac A., RUN apt update && \ apt upgrade -y && \ - apt install -y lib32gcc1 lib32stdc++6 curl && \ + apt install -y lib32gcc1 lib32stdc++6 unzip curl && \ curl -sL https://deb.nodesource.com/setup_6.x | bash - && \ apt install -y nodejs && \ mkdir /node_modules && \ From 1bef2974d49b3aaa722b5080e3c445bd1b36389d Mon Sep 17 00:00:00 2001 From: Unknown Date: Mon, 10 Jul 2017 10:17:23 -0400 Subject: [PATCH 6/6] Silently unzip & download --- entrypoint.sh | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/entrypoint.sh b/entrypoint.sh index 0c5805e..1e50f2e 100644 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -12,9 +12,10 @@ echo ":/home/container$ ${MODIFIED_STARTUP}" if [ -f OXIDE_FLAG ]; then echo "Updating OxideMod..." - curl "https://dl.bintray.com/oxidemod/builds/Oxide-Rust.zip" > oxide.zip - unzip oxide.zip + curl -sSL "https://dl.bintray.com/oxidemod/builds/Oxide-Rust.zip" > oxide.zip + unzip -o -q oxide.zip rm oxide.zip + echo "Done updating OxideMod!" fi # Fix for Rust not starting