aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Pooley (@zuedev) <zuedev@gmail.com>2026-04-17 21:42:43 +0100
committerAlex Pooley (@zuedev) <zuedev@gmail.com>2026-04-17 21:42:43 +0100
commitfb9210408c1d8792600410a08727b41404f6c418 (patch)
tree48cbcf6a821570c43175f3df9b169310c0148b76
parent74799435dca411e9bb5aa59f4b8bdc6dd1384ad4 (diff)
downloadNuclearOptionDedicatedServerDocker-fb9210408c1d8792600410a08727b41404f6c418.tar
NuclearOptionDedicatedServerDocker-fb9210408c1d8792600410a08727b41404f6c418.tar.gz
NuclearOptionDedicatedServerDocker-fb9210408c1d8792600410a08727b41404f6c418.tar.bz2
NuclearOptionDedicatedServerDocker-fb9210408c1d8792600410a08727b41404f6c418.tar.xz
NuclearOptionDedicatedServerDocker-fb9210408c1d8792600410a08727b41404f6c418.zip
use node instead of bash
-rw-r--r--Dockerfile7
-rw-r--r--entrypoint.bash58
-rw-r--r--entrypoint.mjs81
3 files changed, 84 insertions, 62 deletions
diff --git a/Dockerfile b/Dockerfile
index 77ecf3d..ce3ae15 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -2,9 +2,8 @@ FROM ghcr.io/steamcmd/steamcmd:debian-13
WORKDIR /app
RUN apt-get update && apt-get install -y --no-install-recommends \
- jq \
+ nodejs \
&& rm -rf /var/lib/apt/lists/*
-COPY entrypoint.bash /
-RUN chmod +x /entrypoint.bash
-ENTRYPOINT [ "/entrypoint.bash" ] \ No newline at end of file
+COPY entrypoint.mjs /
+ENTRYPOINT [ "node", "/entrypoint.mjs" ] \ No newline at end of file
diff --git a/entrypoint.bash b/entrypoint.bash
deleted file mode 100644
index fbb0efc..0000000
--- a/entrypoint.bash
+++ /dev/null
@@ -1,58 +0,0 @@
-#!/bin/bash
-
-# do we have a username and password?
-if [ "$STEAM_USERNAME" = "anonymous" ]; then
- echo "Using anonymous login. No password needed."
- STEAM_PASSWORD=""
-elif [ -z "$STEAM_USERNAME" ] || [ -z "$STEAM_PASSWORD" ]; then
- echo "Please set STEAM_USERNAME and STEAM_PASSWORD environment variables."
- echo "If you want to use anonymous login, set STEAM_USERNAME to 'anonymous' and leave STEAM_PASSWORD empty."
- exit 1
-fi
-
-# install game server via steamcmd
-steamcmd +login "$STEAM_USERNAME" "$STEAM_PASSWORD" +force_install_dir /app +app_update 3930080 validate +quit
-
-# apply overlay if it exists
-if [ -d "/overlay" ]; then
- echo "Applying overlay from /overlay to /app"
- cp -r /overlay/* /app/
-fi
-
-# handle configuration file changes via environment variables
-# pattern is: even index is the field name, odd index is the type (String, Boolean, Integer)
-CONFIG_FIELDS=(
- "MissionDirectory"
- "String"
- "ModdedServer"
- "Boolean"
- "Hidden"
- "Boolean"
- "ServerName"
- "String"
- "Password"
- "String"
- "MaxPlayers"
- "Integer"
- "DisableErrorKick"
- "Boolean"
- "NoPlayerStopTime"
- "Integer"
- "PostMissionDelay"
- "Integer"
- "RotationType"
- "Integer"
-)
-
-CONFIG_PATH="/app/DedicatedServerConfig.json"
-
-for FIELD in "${CONFIG_FIELDS[@]}"; do
- ENV_VAR_NAME="CONFIG_${FIELD^^}"
- if [ -n "${!ENV_VAR_NAME}" ]; then
- echo "Setting $FIELD to ${!ENV_VAR_NAME} in $CONFIG_PATH"
- jq --arg value "${!ENV_VAR_NAME}" --arg field "$FIELD" '(.[$field] // empty) |= ($value | if type == "boolean" then (if $value == "true" then true else false end) elif type == "number" then ($value | tonumber) else $value end)' "$CONFIG_PATH" > "$CONFIG_PATH.tmp" && mv "$CONFIG_PATH.tmp" "$CONFIG_PATH"
- fi
-done
-
-# run the server
-sh /app/RunServer.sh \ No newline at end of file
diff --git a/entrypoint.mjs b/entrypoint.mjs
new file mode 100644
index 0000000..10c90d7
--- /dev/null
+++ b/entrypoint.mjs
@@ -0,0 +1,81 @@
+import { execFileSync } from "node:child_process";
+import { existsSync, readFileSync, writeFileSync, cpSync } from "node:fs";
+
+const { STEAM_USERNAME = "", STEAM_PASSWORD = "" } = process.env;
+
+// Validate Steam credentials
+if (STEAM_USERNAME === "anonymous") {
+ console.log("Using anonymous login. No password needed.");
+} else if (!STEAM_USERNAME || !STEAM_PASSWORD) {
+ console.error(
+ "Please set STEAM_USERNAME and STEAM_PASSWORD environment variables.\n" +
+ "If you want to use anonymous login, set STEAM_USERNAME to 'anonymous' and leave STEAM_PASSWORD empty.",
+ );
+ process.exit(1);
+}
+
+// Install game server via steamcmd
+execFileSync(
+ "steamcmd",
+ [
+ "+login",
+ STEAM_USERNAME,
+ STEAM_PASSWORD || "",
+ "+force_install_dir",
+ "/app",
+ "+app_update",
+ "3930080",
+ "validate",
+ "+quit",
+ ],
+ { stdio: "inherit" },
+);
+
+// Apply overlay if it exists
+if (existsSync("/overlay")) {
+ console.log("Applying overlay from /overlay to /app");
+ cpSync("/overlay", "/app", { recursive: true });
+}
+
+// Handle configuration file changes via environment variables
+const CONFIG_FIELDS = [
+ { name: "MissionDirectory", type: "string" },
+ { name: "ModdedServer", type: "boolean" },
+ { name: "Hidden", type: "boolean" },
+ { name: "ServerName", type: "string" },
+ { name: "Password", type: "string" },
+ { name: "MaxPlayers", type: "number" },
+ { name: "DisableErrorKick", type: "boolean" },
+ { name: "NoPlayerStopTime", type: "number" },
+ { name: "PostMissionDelay", type: "number" },
+ { name: "RotationType", type: "number" },
+];
+
+const CONFIG_PATH = "/app/DedicatedServerConfig.json";
+const config = JSON.parse(readFileSync(CONFIG_PATH, "utf-8"));
+
+for (const { name, type } of CONFIG_FIELDS) {
+ const envVar = process.env[`CONFIG_${name.toUpperCase()}`];
+ if (envVar == null || envVar === "") continue;
+
+ console.log(`Setting ${name} to ${envVar} in ${CONFIG_PATH}`);
+
+ if (!(name in config)) continue;
+
+ switch (type) {
+ case "boolean":
+ config[name] = envVar === "true";
+ break;
+ case "number":
+ config[name] = Number(envVar);
+ break;
+ default:
+ config[name] = envVar;
+ break;
+ }
+}
+
+writeFileSync(CONFIG_PATH, JSON.stringify(config, null, 2) + "\n");
+
+// Run the server
+execFileSync("sh", ["/app/RunServer.sh"], { stdio: "inherit" });