From 3a20ca4b04882925de1c387df1953a431a8527ff Mon Sep 17 00:00:00 2001 From: Rouven Himmelstein Date: Wed, 28 Feb 2024 19:38:05 +0100 Subject: [PATCH] feat: use custom base image --- README.md | 3 +- container-data/Containerfile | 55 +++--------------------------- container-data/entrypoint.sh | 57 -------------------------------- container-data/pre.sh | 6 ++++ container-data/steam-game.script | 9 ----- 5 files changed, 12 insertions(+), 118 deletions(-) delete mode 100644 container-data/entrypoint.sh create mode 100755 container-data/pre.sh delete mode 100644 container-data/steam-game.script diff --git a/README.md b/README.md index e30ca35..cab3ade 100644 --- a/README.md +++ b/README.md @@ -57,7 +57,8 @@ When starting the server for the first time: * The config files and folders will be automatically created in the `config/` folder. * The server will download the latest version of the game from Steam to the `data/` folder. -* The server might need to be restarted once to apply the latest game update. + +> You have to restart after the first start. To restart the server after making changes to the configuration, use the following command: diff --git a/container-data/Containerfile b/container-data/Containerfile index f37f672..fc8c5b3 100644 --- a/container-data/Containerfile +++ b/container-data/Containerfile @@ -1,53 +1,6 @@ -# Use latest Ubuntu as base image -FROM ubuntu:devel +FROM rouhim/steamcmd-wine:latest -# Define environment variables -ENV USER_HOME "/home/ubuntu" -ENV STEAMCMD "$USER_HOME/steamcmd/steamcmd.sh" -ENV SERVER_DIR "/data" -ENV SERVER_CONFIG_DIR "/config" +ENV STEAM_APP_ID "2465200" +ENV STARTUP_COMMAND "wine SonsOfTheForestDS.exe -userdatapath $SERVER_CONFIG_DIR" -# Use default non root user ubuntu (1000) -WORKDIR $USER_HOME - -# Install steamcmd and its dependencies -RUN apt update && \ - apt install -y wget ca-certificates lib32gcc-s1 && \ - mkdir -p $USER_HOME/steamcmd && \ - wget -qO- 'https://steamcdn-a.akamaihd.net/client/installer/steamcmd_linux.tar.gz' | tar zxf - -C $USER_HOME/steamcmd && \ - chown -R ubuntu:ubuntu $USER_HOME/steamcmd - -# Install wine and its dependencies and do a full system upgrade to get the latest and greatest packages -RUN apt update && \ - apt install -y --no-install-recommends wine wine64 winbind xvfb && \ - apt upgrade -y - -# Cleanup, remove wget -RUN apt remove -y wget && \ - apt clean && \ - rm -rf /var/lib/apt/lists - -# Create game server and config directory -RUN mkdir -p $SERVER_DIR $SERVER_CONFIG_DIR -VOLUME $SERVER_DIR -VOLUME $SERVER_CONFIG_DIR - -# Copy steam-game.script to container -COPY steam-game.script $USER_HOME/steam-game.script - -# Change user to non-root user -RUN chown -R ubuntu:ubuntu $USER_HOME && \ - chown -R nobody:nogroup $SERVER_DIR $SERVER_CONFIG_DIR && \ - chmod 777 -R $SERVER_DIR $SERVER_CONFIG_DIR -USER ubuntu - -# Game port -EXPOSE 8766/udp -# Query port -EXPOSE 27016/udp -# Blobsync port -EXPOSE 9700/udp - -# Define entrypoint -COPY --chown=ubuntu:ubuntu --chmod=755 entrypoint.sh /sons-of-the-forest-server.sh -ENTRYPOINT ["/sons-of-the-forest-server.sh"] \ No newline at end of file +COPY pre.sh $USER_HOME/pre.sh \ No newline at end of file diff --git a/container-data/entrypoint.sh b/container-data/entrypoint.sh deleted file mode 100644 index bd3f162..0000000 --- a/container-data/entrypoint.sh +++ /dev/null @@ -1,57 +0,0 @@ -#!/usr/bin/env bash - -# Make sure that $SERVER_DIR is accessible for all -chmod -R 777 "$SERVER_DIR" 2> /dev/null -chown -R nobody:nogroup "$SERVER_DIR" 2> /dev/null - -# Make sure that $SERVER_CONFIG_DIR is accessible for all -chmod -R 777 "$SERVER_CONFIG_DIR" 2> /dev/null -chown -R nobody:nogroup "$SERVER_CONFIG_DIR" 2> /dev/null - -# Check if $SERVER_DIR is writeable -if [ ! -w "$SERVER_DIR" ]; then - echo "❌ Error: $SERVER_DIR is not writeable!" - exit 1 -fi -echo "✅ Server data is writeable!" - -# Check if $SERVER_DIR is readable -if [ ! -r "$SERVER_DIR" ]; then - echo "❌ Error: $SERVER_DIR is not readable!" - exit 1 -fi -echo "✅ Server data is readable!" - -# Check if $SERVER_CONFIG_DIR is writeable -if [ ! -w "$SERVER_CONFIG_DIR" ]; then - echo "❌ Error: $SERVER_CONFIG_DIR is not writeable!" - exit 1 -fi -echo "✅ Server config is writeable!" - -# Check if $SERVER_CONFIG_DIR is readable -if [ ! -r "$SERVER_CONFIG_DIR" ]; then - echo "❌ Error: $SERVER_CONFIG_DIR is not readable!" - exit 1 -fi -echo "✅ Server config is readable!" - -# Start virtual X server -echo "🖥️ Starting virtual display..." -export DISPLAY=":99" -rm -rf /tmp/.X* 2> /dev/null -Xvfb :99 -screen 0 1024x768x16 -nolisten tcp -nolisten unix & -wineboot -r - -# Update server -echo "🔄 Updating server..." -$STEAMCMD +runscript "$USER_HOME"/steam-game.script - -# Set skip network accessibility test to true -echo "🔧 Adjust server config..." -sed -i 's/"SkipNetworkAccessibilityTest": false/"SkipNetworkAccessibilityTest": true/g' "$SERVER_CONFIG_DIR"/dedicatedserver.cfg - -# Start server -echo "🎮 Starting server..." -cd "$SERVER_DIR" -wine SonsOfTheForestDS.exe -userdatapath "$SERVER_CONFIG_DIR" \ No newline at end of file diff --git a/container-data/pre.sh b/container-data/pre.sh new file mode 100755 index 0000000..83b062e --- /dev/null +++ b/container-data/pre.sh @@ -0,0 +1,6 @@ +#!/usr/bin/env sh + + +# Set skip network accessibility test to true +echo "🔧 Adjust server config..." +sed -i 's/"SkipNetworkAccessibilityTest": false/"SkipNetworkAccessibilityTest": true/g' "$SERVER_CONFIG_DIR"/dedicatedserver.cfg diff --git a/container-data/steam-game.script b/container-data/steam-game.script deleted file mode 100644 index 0358d26..0000000 --- a/container-data/steam-game.script +++ /dev/null @@ -1,9 +0,0 @@ -// Installs, updates and validates the server -// -@ShutdownOnFailedCommand 1 -@NoPromptForPassword 1 -@sSteamCmdForcePlatformType windows -force_install_dir /data -login anonymous -app_update 2465200 validate -quit \ No newline at end of file