Skip to content

Instantly share code, notes, and snippets.

@lukepolo
Created April 3, 2024 12:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lukepolo/3dae459934262607de7532ef47bab907 to your computer and use it in GitHub Desktop.
Save lukepolo/3dae459934262607de7532ef47bab907 to your computer and use it in GitHub Desktop.
CSS Mutli Server Setup
FROM mcr.microsoft.com/dotnet/sdk:8.0-bookworm-slim AS build
WORKDIR /mod
COPY src/*.csproj .
RUN dotnet restore
COPY . .
RUN dotnet build -c Release -o release
RUN rm /mod/release/CounterStrikeSharp.API.dll
FROM debian:bookworm-slim
ENV DATA_DIR="/serverdata"
ENV STEAMCMD_DIR="${DATA_DIR}/steamcmd"
ENV BASE_SERVER_DIR="${DATA_DIR}/serverfiles"
ENV INSTANCE_SERVER_DIR="/opt/instance"
ENV GAME_ID="730"
ENV GAME_NAME="counter-strike"
ENV GAME_PARAMS=""
ENV GAME_PORT=27015
ENV VALIDATE=false
ENV UMASK=000
ENV UID=99
ENV GID=100
ENV USERNAME=""
ENV PASSWRD=""
ENV USER="steam"
ENV DATA_PERM=770
ENV SERVER_ID=""
# TODO -
ENV METAMOD_DOWNLOAD_LINK=""
ENV COUNTER_STRIKE_SHARP_URL=""
RUN apt-get update && \
apt-get -y install --no-install-recommends curl unzip lib32gcc-s1 lib32stdc++6 lib32z1 lsof libicu-dev && \
rm -rf /var/lib/apt/lists/*
RUN mkdir $DATA_DIR && \
mkdir $STEAMCMD_DIR && \
mkdir $BASE_SERVER_DIR && \
mkdir $INSTANCE_SERVER_DIR && \
useradd -d $DATA_DIR -s /bin/bash $USER && \
ulimit -n 2048
RUN mkdir /opt/metamod
ADD https://mms.alliedmods.net/mmsdrop/2.0/mmsource-2.0.0-git1284-linux.tar.gz /tmp/metamod.tar.gz
RUN tar -xz -C /opt/metamod -f /tmp/metamod.tar.gz && rm /tmp/metamod.tar.gz
RUN mkdir /opt/counterstrikesharp
ADD https://github.com/roflmuffin/CounterStrikeSharp/releases/download/v203/counterstrikesharp-with-runtime-build-203-linux-211516c.zip /tmp/counterstrikesharp.zip
RUN unzip /tmp/counterstrikesharp.zip -d /opt/counterstrikesharp && rm /tmp/counterstrikesharp.zip
COPY /cfg /opt/server-cfg
COPY /scripts /opt/scripts
COPY --from=build /mod/release /opt/mod
RUN mv /opt/metamod/addons /opt/addons
RUN cp -R /opt/counterstrikesharp/addons/metamod /opt/addons
RUN cp -R /opt/counterstrikesharp/addons/counterstrikesharp /opt/addons
RUN mkdir -p /opt/addons/counterstrikesharp/plugins
RUN rm -rf /opt/metamod
RUN rm -rf /opt/counterstrikesharp
#Server Start
ENTRYPOINT ["/opt/scripts/server.sh"]
#!/bin/bash
make_directories=(
"game/csgo/cfg"
"game/csgo/addons"
"game/csgo/maps/soundcache"
"game/csgo/logs"
)
for dir in "${make_directories[@]}"; do
mkdir -p "$INSTANCE_SERVER_DIR/$dir"
done
copy_directories=(
"game/bin"
"game/csgo/cfg"
)
for dir in "${copy_directories[@]}"; do
cp -R "$BASE_SERVER_DIR/$dir" "$INSTANCE_SERVER_DIR/$dir"
done
echo "---Create Symbolic Links---"
create_symlinks() {
local source_path="$1"
local destination_path="$2"
for file in "$source_path"/*; do
relative_path="${file#$source_path/}"
destination_file="$destination_path/$relative_path"
if [ -f "$file" ]; then
if [ ! -e "$destination_file" ]; then
ln -s "$file" "$destination_file"
fi
elif [ -d "$file" ]; then
if [ ! -e "$destination_file" ]; then
ln -s "$file" "$destination_file"
fi
create_symlinks "$file" "$destination_file"
fi
done
}
create_symlinks "$BASE_SERVER_DIR" "$INSTANCE_SERVER_DIR"
cp "/opt/server-cfg/server.cfg" "$INSTANCE_SERVER_DIR/game/csgo/cfg"
cp "/opt/server-cfg/base.cfg" "$INSTANCE_SERVER_DIR/game/csgo/cfg"
cp "/opt/server-cfg/warmup.cfg" "$INSTANCE_SERVER_DIR/game/csgo/cfg"
cp "/opt/server-cfg/knife.cfg" "$INSTANCE_SERVER_DIR/game/csgo/cfg"
cp "/opt/server-cfg/live.cfg" "$INSTANCE_SERVER_DIR/game/csgo/cfg"
cp "/opt/server-cfg/subscribed_file_ids.txt" "$INSTANCE_SERVER_DIR/game/csgo"
echo "---Install Addons---"
cp -r "/opt/addons" "${INSTANCE_SERVER_DIR}/game/csgo"
echo "---Install 5Stack---"
if [ "${DEV_SWAPPED}" == "1" ]; then
ln -s "/opt/dev" "${INSTANCE_SERVER_DIR}/game/csgo/addons/counterstrikesharp/plugins/FiveStack"
else
ln -s "/opt/mod" "${INSTANCE_SERVER_DIR}/game/csgo/addons/counterstrikesharp/plugins/FiveStack"
fi
cp "/opt/server-cfg/core.json" "$INSTANCE_SERVER_DIR/game/csgo/addons/counterstrikesharp/configs"
echo "---Check Metamod Install---"
gameinfo_path="${INSTANCE_SERVER_DIR}/game/csgo/gameinfo.gi"
new_line=" Game csgo/addons/metamod"
if ! grep -qFx "$new_line" "$gameinfo_path"; then
echo "---Adding Metamod Loader ---"
# If the line doesn't exist, add it
line_number=$(awk '/Game_LowViolence/{print NR; exit}' "$gameinfo_path")
echo "Found Game_LowViolence at line $line_number"
sed -i "${line_number}a\\$new_line" "$gameinfo_path"
fi
echo "---Prepare Server---"
mkdir -p /root/.steam/sdk64
cp -R "${STEAMCMD_DIR}/linux64/"* "/root/.steam/sdk64/"
echo "---Starting Server...--"
cd ${INSTANCE_SERVER_DIR}
${INSTANCE_SERVER_DIR}/game/bin/linuxsteamrt64/cs2 ${GAME_PARAMS}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment