add files

main
Astra 2023-12-27 19:24:58 +00:00
commit e5a69f276a
10 changed files with 336 additions and 0 deletions

21
LICENSE 100644
View File

@ -0,0 +1,21 @@
MIT License
Copyright (c) 2023 John Edwards
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

86
README.md 100644
View File

@ -0,0 +1,86 @@
# 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](https://store.steampowered.com/app/730/CounterStrike_2/).
This Docker image contains the dedicated server of the game.
<img src="https://cdn.cloudflare.steamstatic.com/steam/apps/730/header.jpg?t=1696011820" alt="logo" width="600"/></img>
# How to use this image
## Hosting a simple game server
Running on the *host* interface (recommended):<br/>
```console
$ docker run -d --net=host --name=cs2 -e STEAMUSER={YOUR_STEAM_USER} -e STEAMPASS={YOUR_STEAM_PASSWD} git.zio.sh/astra/cs2:latest
```
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> \
git.zio.sh/astra/cs2:latest
```
`STEAMUSER` and `STEAMPASS` **are required as unlike CS:GO, CS2 can not be downloaded anonymously (at time of writing).**
`STEAMGUARD` **must be used to provide your more recent Steam Guard key if Steam Guard is enabled on your account.**
**The container will automatically update the game on startup, so if there is a game update just restart the container.**
# Configuration
## System Requirements
Please note that you need approximately 1.5g of free RAM. If this is not available, container will crash with err 137.
## Environment Variables
Feel free to overwrite these environment variables, using -e (--env) or --env-file (recommended):
### SteamCMD
```dockerfile
STEAMUSER="changeme" (Steam User for SteamCMD.)
STEAMPASS="changeme" (Password for Steam User.)
STEAMGUARD="" (Optional, Steam Guard key if enabled. Use your most recent Steam Guard key.)
```
### Server Configuration
```dockerfile
CS2_SERVERNAME="changeme" (Set the visible name for your private server)
CS2_IP=0.0.0.0 (CS2 server listening IP address, 0.0.0.0 - all IP addresses on the local machine, empty - IP identified automatically)
CS2_PORT=27015 (CS2 server listen port tcp_udp)
CS2_RCON_PORT="" (Optional, use a simple TCP proxy to have RCON listen on an alternative port.
Useful for services like AWS Fargate which do not support mixed protocol ports.)
CS2_LAN="0" (0 - LAN mode disabled, 1 - LAN Mode enabled)
CS2_RCONPW="changeme" (RCON password)
CS2_PW="changeme" (CS2 server password)
CS2_MAXPLAYERS=10 (Max players)
CS2_ADDITIONAL_ARGS="" (Optional additional arguments to pass into cs2)
```
### Game Modes
```dockerfile
CS2_GAMEALIAS="" (Game type, e.g. casual, competitive, deathmatch.
See https://developer.valvesoftware.com/wiki/Counter-Strike_2/Dedicated_Servers)
CS2_GAMETYPE=0 (Used if CS2_GAMEALIAS not defined. See https://developer.valvesoftware.com/wiki/Counter-Strike_2/Dedicated_Servers)
CS2_GAMEMODE=1 (Used if CS2_GAMEALIAS not defined. See https://developer.valvesoftware.com/wiki/Counter-Strike_2/Dedicated_Servers)
CS2_MAPGROUP="mg_active" (Map pool)
CS2_STARTMAP="de_inferno" (Start map)
```
### Bots
```dockerfile
CS2_BOT_DIFFICULTY="" (0 - easy, 1 - normal, 2 - hard, 3 - expert)
CS2_BOT_QUOTA="" (Number of bots)
CS2_BOT_QUOTA_MODE="" (fill, competitive)
```
# Credits
This container leans heavily on the work of [CM2Walki](https://github.com/CM2Walki/), especially his [SteamCMD](https://github.com/CM2Walki/steamcmd) container image. GG!

View File

@ -0,0 +1 @@
hooks/

View File

@ -0,0 +1,83 @@
###########################################################
# Dockerfile that builds a CS2 Gameserver
###########################################################
# BUILD STAGE
FROM cm2network/steamcmd:root as build_stage
LABEL maintainer="astra@zio.sh"
ENV STEAMAPPID 730
ENV STEAMAPP cs2
ENV STEAMAPPDIR "${HOMEDIR}/${STEAMAPP}-dedicated"
COPY etc/entry.sh "${HOMEDIR}/entry.sh"
COPY etc/server.cfg "/etc/server.cfg"
COPY etc/pre.sh "/etc/pre.sh"
COPY etc/post.sh "/etc/post.sh"
RUN set -x \
# Install, update & upgrade packages
&& dpkg --add-architecture i386 \
&& apt-get update \
&& apt-get install -y --no-install-recommends --no-install-suggests \
libcurl4:i386 \
wget \
ca-certificates \
lib32z1 \
simpleproxy \
libicu-dev \
&& mkdir -p "${STEAMAPPDIR}" \
# Add entry script
&& chmod +x "${HOMEDIR}/entry.sh" \
&& chown -R "${USER}:${USER}" "${HOMEDIR}/entry.sh" "${STEAMAPPDIR}" \
# Clean up
&& apt-get clean \
&& find /var/lib/apt/lists/ -type f -delete
# BASE
FROM build_stage AS bullseye-base
ENV CS2_SERVERNAME="cs2 private server" \
CS2_IP=0.0.0.0 \
CS2_PORT=27015 \
CS2_SERVER_HIBERNATE=0 \
CS2_RCON_PORT="" \
CS2_MAXPLAYERS=10 \
CS2_RCONPW="changeme" \
CS2_PW="changeme" \
CS2_MAPGROUP="mg_active" \
CS2_STARTMAP="de_inferno" \
CS2_GAMEALIAS="" \
CS2_GAMETYPE=0 \
CS2_GAMEMODE=1 \
CS2_LAN=0 \
TV_AUTORECORD=0 \
TV_ENABLE=0 \
TV_PW="changeme" \
TV_PORT=27020 \
TV_RELAY_PW="changeme" \
TV_MAXRATE=0 \
TV_DELAY=0 \
SRCDS_TOKEN="" \
CS2_ADDITIONAL_ARGS=""
# Set permissions on STEAMAPPDIR
# Permissions may need to be reset if persistent volume mounted
RUN set -x \
&& chown -R "${USER}:${USER}" "${STEAMAPPDIR}" \
&& chmod 0777 "${STEAMAPPDIR}"
# Switch to user
USER ${USER}
WORKDIR ${HOMEDIR}
CMD ["bash", "entry.sh"]
# Expose ports
EXPOSE 27015/tcp \
27015/udp \
27020/udp

View File

@ -0,0 +1,92 @@
#!/bin/bash
mkdir -p "${STEAMAPPDIR}" || true
# Download Updates
bash "${STEAMCMDDIR}/steamcmd.sh" +force_install_dir "${STEAMAPPDIR}" \
+login anonymous \
+app_update "${STEAMAPPID}" \
+quit
# steamclient.so fix
mkdir -p ~/.steam/sdk64
ln -sfT ${STEAMCMDDIR}/linux64/steamclient.so ~/.steam/sdk64/steamclient.so
# Install server.cfg
cp /etc/server.cfg "${STEAMAPPDIR}"/game/csgo/cfg/server.cfg
sed -i -e "s/hostname.*/hostname ${CS2_SERVERNAME}/g" "${STEAMAPPDIR}"/game/csgo/cfg/server.cfg \
-e "s/sv_password.*/sv_password ${CS2_PW}/g" "${STEAMAPPDIR}"/game/csgo/cfg/server.cfg \
-e "s/rcon_password.*/rcon_password ${CS2_RCONPW}/g" "${STEAMAPPDIR}"/game/csgo/cfg/server.cfg \
-e "s/tv_enable./tv_enable.*/tv_enable ${TV_ENABLE}/g" "${STEAMAPPDIR}"/game/csgo/cfg/server.cfg \
-e "s/tv_enable./tv_port.*/tv_port ${TV_PORT}/g" "${STEAMAPPDIR}"/game/csgo/cfg/server.cfg \
-e "s/tv_enable./tv_autorecord.*/tv_autorecord ${TV_AUTORECORD}/g" "${STEAMAPPDIR}"/game/csgo/cfg/server.cfg \
-e "s/tv_enable./tv_enable.*/tv_enable ${TV_PW}/g" "${STEAMAPPDIR}"/game/csgo/cfg/server.cfg \
-e "s/tv_enable./tv_relay_pw.*/tv_relay_pw ${TV_RELAY_PW}/g" "${STEAMAPPDIR}"/game/csgo/cfg/server.cfg \
-e "s/tv_enable./tv_maxrate.*/tv_maxrate ${TV_MAXRATE}/g" "${STEAMAPPDIR}"/game/csgo/cfg/server.cfg \
-e "s/tv_enable./tv_delay.*/tv_delay ${TV_DELAY}/g" "${STEAMAPPDIR}"/game/csgo/cfg/server.cfg
# Install hooks
if [[ ! -f "${STEAMAPPDIR}/pre.sh" ]] ; then
cp /etc/pre.sh "${STEAMAPPDIR}/pre.sh"
fi
if [[ ! -f "${STEAMAPPDIR}/post.sh" ]] ; then
cp /etc/post.sh "${STEAMAPPDIR}/post.sh"
fi
# Rewrite Config Files
if [[ ! -z $CS2_BOT_DIFFICULTY ]] ; then
sed -i "s/bot_difficulty.*/bot_difficulty ${CS2_BOT_DIFFICULTY}/" "${STEAMAPPDIR}"/game/csgo/cfg/*
fi
if [[ ! -z $CS2_BOT_QUOTA ]] ; then
sed -i "s/bot_quota.*/bot_quota ${CS2_BOT_QUOTA}/" "${STEAMAPPDIR}"/game/csgo/cfg/*
fi
if [[ ! -z $CS2_BOT_QUOTA_MODE ]] ; then
sed -i "s/bot_quota_mode.*/bot_quota_mode ${CS2_BOT_QUOTA_MODE}/" "${STEAMAPPDIR}"/game/csgo/cfg/*
fi
# Switch to server directory
cd "${STEAMAPPDIR}/game/bin/linuxsteamrt64"
# Pre Hook
bash "${STEAMAPPDIR}/pre.sh"
# Construct server arguments
if [[ -z $CS2_GAMEALIAS ]]; then
# If CS2_GAMEALIAS is undefined then default to CS2_GAMETYPE and CS2_GAMEMODE
CS2_GAME_MODE_ARGS="+game_type ${CS2_GAMETYPE} +game_mode ${CS2_GAMEMODE}"
else
# Else, use alias to determine game mode
CS2_GAME_MODE_ARGS="+game_alias ${CS2_GAMEALIAS}"
fi
if [[ -z $CS2_IP ]]; then
CS2_IP_ARGS=""
else
CS2_IP_ARGS="-ip ${CS2_IP}"
fi
if [[ ! -z $SRCDS_TOKEN ]]; then
SV_SETSTEAMACCOUNT_ARGS="+sv_setsteamaccount ${SRCDS_TOKEN}"
fi
# Start Server
if [[ ! -z $CS2_RCON_PORT ]]; then
echo "Establishing Simpleproxy for ${CS2_RCON_PORT} to 127.0.0.1:${CS2_PORT}"
simpleproxy -L "${CS2_RCON_PORT}" -R 127.0.0.1:"${CS2_PORT}" &
fi
eval "./cs2" -dedicated \
"${CS2_IP_ARGS}" -port "${CS2_PORT}" \
-console \
-usercon \
-maxplayers "${CS2_MAXPLAYERS}" \
"${CS2_GAME_MODE_ARGS}" \
+mapgroup "${CS2_MAPGROUP}" \
+map "${CS2_STARTMAP}" \
+rcon_password "${CS2_RCONPW}" \
"${SV_SETSTEAMACCOUNT_ARGS}" \
+sv_password "${CS2_PW}" \
+sv_lan "${CS2_LAN}" \
"${CS2_ADDITIONAL_ARGS}"
# Post Hook
bash "${STEAMAPPDIR}/post.sh"

View File

@ -0,0 +1,5 @@
#!/bin/bash
# POST HOOK
# Make your customisation here
echo "post-hook: noop"

View File

@ -0,0 +1,5 @@
#!/bin/bash
# PRE HOOK
# Make your customisation here
echo "pre-hook: noop"

View File

@ -0,0 +1,36 @@
// Server Defaults
hostname "changeme" // Set server hostname
sv_hibernate_when_empty 0 // Disable server hibernation
// Passwords
rcon_password "changeme" // Set rcon password
sv_password "changeme" // Set server password
// CSTV
sv_hibernate_postgame_delay 30 // Delay server hibernation after all clients disconnect
tv_allow_camera_man 1 // Auto director allows spectators to become camera man
tv_allow_static_shots 1 // Auto director uses fixed level cameras for shots
tv_autorecord 0 // Automatically records all games as CSTV demos: 0=off, 1=on.
tv_chatgroupsize 0 // Set the default chat group size
tv_chattimelimit 8 // Limits spectators to chat only every n seconds
tv_debug 0 // CSTV debug info.
tv_delay 30 // CSTV broadcast delay in seconds
tv_delaymapchange 1 // Delays map change until broadcast is complete
tv_deltacache 2 // Enable delta entity bit stream cache
tv_dispatchmode 1 // Dispatch clients to relay proxies: 0=never, 1=if appropriate, 2=always
tv_enable 0 // Activates CSTV on server: 0=off, 1=on.
tv_maxclients 10 // Maximum client number on CSTV server.
tv_maxrate 20000 // Max CSTV spectator bandwidth rate allowed, 0 == unlimited
tv_name "changeme" // CSTV host name
tv_overridemaster 0 // Overrides the CSTV master root address.
tv_port 0 // Host SourceTV port
tv_password "changeme" // CSTV password for clients
tv_relaypassword "changeme" // CSTV password for relay proxies
tv_relayvoice 1 // Relay voice data: 0=off, 1=on
tv_timeout 60 // CSTV connection timeout in seconds.
tv_title "changeme" // Set title for CSTV spectator UI
tv_transmitall 1 // Transmit all entities (not only director view)

View File

@ -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}/..

View File

@ -0,0 +1,2 @@
#!/bin/bash
docker push --all-tags ${DOCKER_REPO}