From 8a87edf798b475ec6f71e6e7404eab77f7b8adb3 Mon Sep 17 00:00:00 2001 From: Daniel Ceregatti Date: Fri, 26 Jul 2024 21:44:21 -0700 Subject: [PATCH] Refactor docker compose build so a single server image is built for however many servers. Add horse mod, despite it being known to crash the Linux server. One day... Fix bashrc getting appended to instead of written to. Oops! --- docker-compose.yml | 104 ++++---- files/mods/3295021220/cfgenvironment.xml | 9 + files/mods/3295021220/cfgeventspawns.xml | 4 + files/mods/3295021220/events.xml | 24 ++ files/mods/3295021220/horses_chernarus.xml | 270 +++++++++++++++++++++ files/mods/3295021220/start.sh | 6 + files/mods/3295021220/xml.env | 3 + files/mods/@DayZHorse | 1 + web/Dockerfile | 151 ++++++++---- web/bin/start.sh | 2 +- 10 files changed, 482 insertions(+), 92 deletions(-) create mode 100755 files/mods/3295021220/cfgenvironment.xml create mode 100755 files/mods/3295021220/cfgeventspawns.xml create mode 100755 files/mods/3295021220/events.xml create mode 100755 files/mods/3295021220/horses_chernarus.xml create mode 100644 files/mods/3295021220/start.sh create mode 100644 files/mods/3295021220/xml.env create mode 120000 files/mods/@DayZHorse diff --git a/docker-compose.yml b/docker-compose.yml index 455c556..5602f90 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -26,6 +26,8 @@ volumes: services: web: + profiles: + - main build: context: web args: @@ -46,11 +48,23 @@ services: env_file: - .env - server1: + server-image: + &server-image + profiles: + - build build: context: server args: - USER_ID + image: server-image + pull_policy: never + env_file: + - .env + + server1: + <<: *server-image + profiles: + - main user: ${USER_ID} volumes: # Common volumes @@ -90,47 +104,47 @@ services: env_file: - .env1 - # Copy and paste this for every other server you want to run, replacing 2 with 3, and so on. - server2: # <-- here - build: - context: server - args: - - USER_ID - user: ${USER_ID} - volumes: - # Common volumes - - ./files:/files - - mods:/mods - - ./server:/server - - serverfiles:/serverfiles - - servermpmissions:/mpmissions:ro - # Server-specific volumes - - homedir_server2:/home/user # <-- here - - mpmissions2:/serverfiles/mpmissions # <-- here - - profiles2:/profiles # <-- here - network_mode: host - restart: no - env_file: - - .env2 # <-- here - - server3: # <-- here - build: - context: server - args: - - USER_ID - user: ${USER_ID} - volumes: - # Common volumes - - ./files:/files - - mods:/mods - - ./server:/server - - serverfiles:/serverfiles - - servermpmissions:/mpmissions:ro - # Server-specific volumes - - homedir_server3:/home/user # <-- here - - mpmissions3:/serverfiles/mpmissions # <-- here - - profiles3:/profiles # <-- here - network_mode: host - restart: no - env_file: - - .env3 # <-- here +# # Copy and paste this for every other server you want to run, replacing 2 with 3, and so on. +# server2: # <-- here +# build: +# context: server +# args: +# - USER_ID +# user: ${USER_ID} +# volumes: +# # Common volumes +# - ./files:/files +# - mods:/mods +# - ./server:/server +# - serverfiles:/serverfiles +# - servermpmissions:/mpmissions:ro +# # Server-specific volumes +# - homedir_server2:/home/user # <-- here +# - mpmissions2:/serverfiles/mpmissions # <-- here +# - profiles2:/profiles # <-- here +# network_mode: host +# restart: no +# env_file: +# - .env2 # <-- here +# +# server3: # <-- here +# build: +# context: server +# args: +# - USER_ID +# user: ${USER_ID} +# volumes: +# # Common volumes +# - ./files:/files +# - mods:/mods +# - ./server:/server +# - serverfiles:/serverfiles +# - servermpmissions:/mpmissions:ro +# # Server-specific volumes +# - homedir_server3:/home/user # <-- here +# - mpmissions3:/serverfiles/mpmissions # <-- here +# - profiles3:/profiles # <-- here +# network_mode: host +# restart: no +# env_file: +# - .env3 # <-- here diff --git a/files/mods/3295021220/cfgenvironment.xml b/files/mods/3295021220/cfgenvironment.xml new file mode 100755 index 0000000..aa1eeb4 --- /dev/null +++ b/files/mods/3295021220/cfgenvironment.xml @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/files/mods/3295021220/cfgeventspawns.xml b/files/mods/3295021220/cfgeventspawns.xml new file mode 100755 index 0000000..e8f22d7 --- /dev/null +++ b/files/mods/3295021220/cfgeventspawns.xml @@ -0,0 +1,4 @@ + + + + diff --git a/files/mods/3295021220/events.xml b/files/mods/3295021220/events.xml new file mode 100755 index 0000000..0937dce --- /dev/null +++ b/files/mods/3295021220/events.xml @@ -0,0 +1,24 @@ + + + + 8 + 1 + 4 + 180 + 0 + 200 + 0 + 0 + + fixed + child + 1 + + + + + + + + + diff --git a/files/mods/3295021220/horses_chernarus.xml b/files/mods/3295021220/horses_chernarus.xml new file mode 100755 index 0000000..c04fea5 --- /dev/null +++ b/files/mods/3295021220/horses_chernarus.xml @@ -0,0 +1,270 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/files/mods/3295021220/start.sh b/files/mods/3295021220/start.sh new file mode 100644 index 0000000..8123c60 --- /dev/null +++ b/files/mods/3295021220/start.sh @@ -0,0 +1,6 @@ +#!/usr/bin/env bash + +# This is run in the directory with the target files + +# Copy the territory file over +cp ${FILES}/mods/${ID}/horses_chernarus.xml env/wild_horse_territories.xml diff --git a/files/mods/3295021220/xml.env b/files/mods/3295021220/xml.env new file mode 100644 index 0000000..3487169 --- /dev/null +++ b/files/mods/3295021220/xml.env @@ -0,0 +1,3 @@ +CFGENVIRONMENT=local +CFGEVENTSPAWNS=local +EVENTS=local diff --git a/files/mods/@DayZHorse b/files/mods/@DayZHorse new file mode 120000 index 0000000..f5c8cc0 --- /dev/null +++ b/files/mods/@DayZHorse @@ -0,0 +1 @@ +3295021220 \ No newline at end of file diff --git a/web/Dockerfile b/web/Dockerfile index f9574e8..636b15d 100644 --- a/web/Dockerfile +++ b/web/Dockerfile @@ -1,48 +1,39 @@ -FROM debian:bookworm-slim +FROM debian:bookworm-slim AS download -# Replace shell with bash so we can source files -RUN rm /bin/sh && ln -s /bin/bash /bin/sh - -# Set debconf to run non-interactively and agree to the SteamCMD EULA -RUN echo 'debconf debconf/frontend select Noninteractive' | debconf-set-selections \ - && echo steam steam/question select "I AGREE" | debconf-set-selections \ - && echo steam steam/license note '' | debconf-set-selections \ - && dpkg --add-architecture i386 - -# Add backports and contrib -RUN sed -i /etc/apt/sources.list.d/debian.sources -e 's/Components: main/Components: main contrib non-free/g' - -# Install _only_ the necessary packages +# Install _only_ the necessary packages to download the .net SDK and Steamworks .net SDK RUN apt-get update && apt-get -y upgrade && apt-get -y install --no-install-recommends \ - binutils \ - curl \ - git \ - gwenhywfar-tools \ - jq \ - libxml2-utils \ - locales \ - nano \ - procps \ + ca-certificates \ wget \ - rename \ - steamcmd \ - xmlstarlet + unzip -# Set the locale -RUN sed -i '/en_US.UTF-8/s/^# //g' /etc/locale.gen && locale-gen -ENV LANG en_US.UTF-8 -ENV LANGUAGE en_US:en -ENV LC_ALL en_US.UTF-8 +# Download dotnet SDK to build the steam API client +RUN cd /tmp && \ + wget -q https://dotnetcli.azureedge.net/dotnet/Sdk/8.0.303/dotnet-sdk-8.0.303-linux-x64.tar.gz -# Steamcmd needs its path added, as it ends up in /usr/games. -# Our server script is bind mounted in /files in docker-compose. -ENV PATH /usr/games:/files/bin:/web/bin:${PATH} +# Download the Steamworks .net package +RUN cd /tmp && \ + wget -q https://github.com/rlabrecque/Steamworks.NET/releases/download/20.2.0/Steamworks.NET-Standalone_20.2.0.zip + +# Extract the dotnet SDK +RUN cd /usr/local && \ + mkdir -p dotnet && \ + cd dotnet && \ + tar xfz /tmp/dotnet-sdk-8.0.303-linux-x64.tar.gz + +# Extract the Steamworks .net SDK +RUN mkdir -p /usr/local/steamworks.net && \ + cd /usr/local/steamworks.net && \ + unzip /tmp/Steamworks.NET-Standalone_20.2.0.zip + +# Add bercon https://github.com/WoozyMasta/bercon +RUN wget -q https://github.com/WoozyMasta/bercon/releases/download/1.0.0/bercon \ + && chmod +x bercon \ + && mv bercon /usr/bin # Install nodejs RUN mkdir /usr/local/nvm ENV NVM_DIR /usr/local/nvm -ENV NODE_VERSION 20.12.2 -RUN echo $NODE_VERSION +ENV NODE_VERSION 20.15.1 # Install nvm with node and npm RUN wget -O - https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash \ @@ -51,8 +42,84 @@ RUN wget -O - https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | && nvm alias default $NODE_VERSION \ && nvm use default -ENV NODE_PATH $NVM_DIR/versions/node/v$NODE_VERSION/lib/node_modules -ENV PATH $NVM_DIR/versions/node/v$NODE_VERSION/bin:$PATH +FROM debian:bookworm-slim AS build + +COPY --from=download /usr/local/dotnet /usr/local/dotnet + +RUN apt-get update && apt-get -y upgrade && apt-get -y install --no-install-recommends \ + libicu72 \ + libssl3 + +# Disable MS telemetry +ENV DOTNET_CLI_TELEMETRY_OPTOUT=1 + +# Build the steam API client +COPY client /usr/local/client + +#RUN cd /usr/local/client && \ +# /usr/local/dotnet/dotnet build -c Release + +FROM debian:bookworm-slim + +COPY --from=download /usr/local/dotnet /usr/local/dotnet + +COPY --from=download /usr/local/steamworks.net /usr/local/steamworks.net + +COPY --from=download /usr/bin/bercon /usr/bin/bercon + +COPY --from=download /usr/local/nvm /usr/local/nvm + +COPY --from=build /usr/local/client/ /usr/local/client + +ENV DOTNET_ROOT /usr/local/dotnet + +# Add backports, contrib, and non-free +RUN sed -i /etc/apt/sources.list.d/debian.sources -e 's/Components: main/Components: main contrib non-free/g' + +# Set debconf to run non-interactively and agree to the SteamCMD EULA +RUN echo 'debconf debconf/frontend select Noninteractive' | debconf-set-selections \ + && echo steam steam/question select "I AGREE" | debconf-set-selections \ + && echo steam steam/license note '' | debconf-set-selections \ + && dpkg --add-architecture i386 + +# Install _only_ the necessary packages +RUN apt-get update && apt-get -y upgrade && apt-get -y install --no-install-recommends \ + binutils \ + curl \ + git \ + gwenhywfar-tools \ + jq \ + libicu72 \ + libssl3 \ + libxml2-utils \ + locales \ + nano \ + procps \ + wget \ + rename \ + steamcmd \ + xmlstarlet \ + unzip + +# Set the locale +RUN sed -i '/en_US.UTF-8/s/^# //g' /etc/locale.gen && locale-gen +ENV LANG=en_US.UTF-8 +ENV LANGUAGE=en_US:en +ENV LC_ALL=en_US.UTF-8 + +# This was installed in the download stage +ENV NVM_DIR /usr/local/nvm +ENV NODE_VERSION=20.15.1 + +ENV NODE_PATH=$NVM_DIR/versions/node/v$NODE_VERSION/lib/node_modules +ENV PATH=$NVM_DIR/versions/node/v$NODE_VERSION/bin:$PATH + +# Steamcmd needs its path added, as it ends up in /usr/games. +# Our server script is bind mounted in /files in docker-compose. +ENV PATH=/usr/games:/files/bin:/web/bin:${PATH} + +# Shut steamcmd up +RUN cd /usr/lib/i386-linux-gnu && ln -s /web/bin/steamservice.so # Setup a non-privileged user ARG USER_ID @@ -62,14 +129,6 @@ RUN groupadd -g ${USER_ID} user && \ mkdir -p /home/user /serverfiles/mpmissions /serverfiles/steamapps/workshop/content /web && \ chown -R user:user /home/user /serverfiles /web -# Shut steamcmd up -RUN cd /usr/lib/i386-linux-gnu && ln -s /web/bin/steamservice.so - -# Add bercon https://github.com/WoozyMasta/bercon -RUN wget https://github.com/WoozyMasta/bercon/releases/download/1.0.0/bercon \ - && chmod +x bercon \ - && mv bercon /usr/bin - # Use our non-privileged user USER user diff --git a/web/bin/start.sh b/web/bin/start.sh index 2e2e230..a5d6ade 100755 --- a/web/bin/start.sh +++ b/web/bin/start.sh @@ -4,7 +4,7 @@ if ! echo .bashrc | grep -q "dz-web" then echo "Adding PS1 to .bashrc..." - cat >> .bashrc < .bashrc <