From 0ccf90faac5a0bb4ab7514eb23931691167c5e87 Mon Sep 17 00:00:00 2001 From: John Edwards Date: Sat, 30 Sep 2023 20:58:08 +0100 Subject: [PATCH] Initial commit --- README.md | 47 +++++++++++++++++++++++++++++++++++++ bullseye/.dockerignore | 1 + bullseye/Dockerfile | 53 ++++++++++++++++++++++++++++++++++++++++++ bullseye/etc/entry.sh | 20 ++++++++++++++++ bullseye/hooks/build | 5 ++++ bullseye/hooks/push | 2 ++ 6 files changed, 128 insertions(+) create mode 100644 README.md create mode 100644 bullseye/.dockerignore create mode 100644 bullseye/Dockerfile create mode 100644 bullseye/etc/entry.sh create mode 100644 bullseye/hooks/build create mode 100644 bullseye/hooks/push diff --git a/README.md b/README.md new file mode 100644 index 0000000..925bdbe --- /dev/null +++ b/README.md @@ -0,0 +1,47 @@ +# What is Counter-Strike 2 +For over two decades, Counter-Strike has offered an elite competitive experience, one shaped by millions of players from across the globe. And now the next chapter in the CS story is about to begin. This is Counter-Strike 2. +This Docker image contains the dedicated server of the game. + +> [CS2](https://store.steampowered.com/app/730/CounterStrike_2/) + +logo + +# How to use this image +## Hosting a simple game server + +Running on the *host* interface (recommended):
+```console +$ docker run -d --net=host --name=cs2 -e STEAMUSER={YOUR_STEAM_USER} -e STEAMPASS={YOUR_STEAM_PASSWD} joedwards32/cs2 +``` + +Running using a bind mount for data persistence on container recreation: +```console +$ mkdir -p $(pwd)/cs2-data +$ chmod 777 $(pwd)/cs2-data # Makes sure the directory is writeable by the unprivileged container user +$ docker run -d --net=host -v $(pwd)/cs2-data:/home/steam/cs2-dedicated/ --name=cs2-dedicated -e STEAMUSER={YOUR_STEAM_USER} -e STEAMPASS={YOUR_STEAM_PASSWD} joedwards32/cs2 +``` + +`STEAMUSER` and `STEAMPASS` **are required as unlike CS:GO, CS2 can not be downloaded anonymously (at time of writing).** + +**Steam Guard must be disabled on the Steam Account** + +**For security reasons, it is strongly recommended that you create a new Steam Account separate to your personal Steam Account.** + +**The container will automatically update the game on startup, so if there is a game update just restart the container.** + +# Configuration +## Environment Variables +Feel free to overwrite these environment variables, using -e (--env): +```dockerfile +STEAMUSER="changeme" (Steam User for SteamCMD. Steam Guard must be disabled.) +STEAMPASS="changeme" (Password for Steam User.) +CS2_PORT=27015 (CS2 server listen port tcp_udp) +CS2_RCONPW="changeme" (RCON password) +CS2_PW="changeme" (CS2 server password) +CS2_MAXPLAYERS=10 (Max players) +CS2_GAMETYPE=0 (Game type, see) +CS2_GAMEMODE=0 (Game mode, see) +CS2_MAPGROUP="mg_active" (Map pool) +CS2_STARTMAP="de_inferno" (Start map) +CS2_ADDITIONAL_ARGS="" (Optional additional arguments to pass into cs2) +``` diff --git a/bullseye/.dockerignore b/bullseye/.dockerignore new file mode 100644 index 0000000..c0362b8 --- /dev/null +++ b/bullseye/.dockerignore @@ -0,0 +1 @@ +hooks/ diff --git a/bullseye/Dockerfile b/bullseye/Dockerfile new file mode 100644 index 0000000..7a2b9ef --- /dev/null +++ b/bullseye/Dockerfile @@ -0,0 +1,53 @@ +########################################################### +# Dockerfile that builds a CS2 Gameserver +########################################################### +FROM cm2network/steamcmd:root as build_stage + +LABEL maintainer="joedwards32@gmail.com" + +ENV STEAMUSER "changeme" +ENV STEAMPASS "changeme" +ENV STEAMAPPID 730 +ENV STEAMAPP cs2 +ENV STEAMAPPDIR "${HOMEDIR}/${STEAMAPP}-dedicated" +ENV CFG_URL https://raw.githubusercontent.com/joedwards32/CS2/settings.tgz + +COPY etc/entry.sh "${HOMEDIR}/entry.sh" + +RUN set -x \ + # Install, update & upgrade packages + && apt-get update \ + && apt-get install -y --no-install-recommends --no-install-suggests \ + wget \ + ca-certificates \ + lib32z1 \ + && mkdir -p "${STEAMAPPDIR}" \ + # Add entry script + && chmod +x "${HOMEDIR}/entry.sh" \ + && chown -R "${USER}:${USER}" "${HOMEDIR}/entry.sh" "${STEAMAPPDIR}" \ + # Clean up + && rm -rf /var/lib/apt/lists/* + +FROM build_stage AS bullseye-base + +ENV CS2_PORT=27015 \ + CS2_MAXPLAYERS=10 \ + CS2_RCONPW="changeme" \ + CS2_PW="changeme" \ + CS2_MAPGROUP="mg_active" \ + CS2_STARTMAP="de_inferno" \ + CS2_GAMETYPE=0 \ + CS2_GAMEMODE=0 \ + CS2_ADDITIONAL_ARGS="" + +# Switch to user +USER ${USER} + +WORKDIR ${HOMEDIR} + +CMD ["bash", "entry.sh"] + +# Expose ports +EXPOSE 27015/tcp \ + 27015/udp \ + 27020/udp diff --git a/bullseye/etc/entry.sh b/bullseye/etc/entry.sh new file mode 100644 index 0000000..f988562 --- /dev/null +++ b/bullseye/etc/entry.sh @@ -0,0 +1,20 @@ +#!/bin/bash +mkdir -p "${STEAMAPPDIR}" || true + +bash "${STEAMCMDDIR}/steamcmd.sh" +force_install_dir "${STEAMAPPDIR}" \ + +login "${STEAMUSER}" "${STEAMPASS}" \ + +app_update "${STEAMAPPID}" \ + +quit + + +"${STEAMAPPDIR}/game/bin/linuxsteamrt64/cs2" -dedicated \ + -usercon \ + +game_type "${CS2_GAMETYPE}" \ + +game_mode "${CS2_GAMEMODE}" \ + +mapgroup "${CS2_MAPGROUP}" \ + +map "${CS2_STARTMAP}" \ + +sv_setsteamaccount \ + -maxplayers_override "${CS2_MAXPLAYERS}" \ + +rcon_password "${CS2_RCONPW}" \ + +sv_password "${CS2_PW}" \ + "${CS2_ADDITIONAL_ARGS}" diff --git a/bullseye/hooks/build b/bullseye/hooks/build new file mode 100644 index 0000000..cfffa83 --- /dev/null +++ b/bullseye/hooks/build @@ -0,0 +1,5 @@ +#!/bin/bash + +SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) + +docker build --target=bullseye-base -t $DOCKER_REPO:latest -t $DOCKER_REPO:base ${SCRIPT_DIR}/.. diff --git a/bullseye/hooks/push b/bullseye/hooks/push new file mode 100644 index 0000000..93a8d0d --- /dev/null +++ b/bullseye/hooks/push @@ -0,0 +1,2 @@ +#!/bin/bash +docker push --all-tags ${DOCKER_REPO}