Skip to content

Commit

Permalink
Feature (ci): Add srcds/cs2 support:
Browse files Browse the repository at this point in the history
- Bump base image in `build/Dockerfile` to `startersclan/steamcmd:git-20231109.0.0`
- Add custom `build` and `test` steps for `srcds/cs2`
- Add working command-line and `docker-compose` examples
- Update documentation on `srcds/cs2`

Co-authored-by: Leonard Jonathan Oh <[email protected]>
  • Loading branch information
joeltimothyoh and leojonathanoh committed Nov 11, 2023
1 parent 28892d7 commit 8aedd70
Show file tree
Hide file tree
Showing 13 changed files with 329 additions and 35 deletions.
4 changes: 4 additions & 0 deletions .generate/Generate-GameImageRepositoryReadme.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ $gameList = @(
EngineFullName = 'Source'
RegistryNamespace = 'sourceservers'
Game = @(
@{
Name = 'cs2'
FullName = 'Counter-Strike 2'
}
@{
Name = 'csgo'
FullName = 'Counter-Strike: Global Offensive'
Expand Down
13 changes: 12 additions & 1 deletion .github/workflows/ci-master-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,14 @@ jobs:
STEAM_USERNAME: ${{ secrets.STEAM_USERNAME }}
STEAM_PASSWORD: ${{ secrets.STEAM_PASSWORD }}

test-game-image-game-version:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Test
run: |
./test/test-game-image-game-version.sh
update-draft-release:
needs:
- test-build-hlds
Expand Down Expand Up @@ -128,8 +136,11 @@ jobs:
strategy:
matrix:
ENGINE: [srcds]
GAME: [csgo, cstrike, dod, hl2mp, left4dead, left4dead2, tf]
GAME: [cs2, csgo, cstrike, dod, hl2mp, left4dead, left4dead2, tf]
include:
- ENGINE: srcds
GAME: cs2
GAME_FULLNAME: 'Counter-Strike 2'
- ENGINE: srcds
GAME: csgo
GAME_FULLNAME: 'Counter-Strike: Global Offensive'
Expand Down
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ Dedicated servers hosted on Steam are usually required to be running the *latest

| Game | Image | Tag `v<tag>` | Size |
|:-:|:-:|:-:|:-:|
| Counter-Strike 2 | [`sourceservers/cs2`][srcds-cs2-dockerhub-link] | [![srcds-cs2-version-badge][]][srcds-cs2-metadata-link] | [![srcds-cs2-size-badge][]][srcds-cs2-metadata-link] | [![srcds-cs2-layers-badge][]][srcds-cs2-metadata-link] |
| Counter-Strike: Global Offensive | [`sourceservers/csgo`][srcds-csgo-dockerhub-link] | [![srcds-csgo-version-badge][]][srcds-csgo-metadata-link] | [![srcds-csgo-size-badge][]][srcds-csgo-metadata-link] | [![srcds-csgo-layers-badge][]][srcds-csgo-metadata-link] |
| Counter-Strike: Source | [`sourceservers/cstrike`][srcds-cstrike-dockerhub-link] | [![srcds-cstrike-version-badge][]][srcds-cstrike-metadata-link] | [![srcds-cstrike-size-badge][]][srcds-cstrike-metadata-link] | [![srcds-cstrike-layers-badge][]][srcds-cstrike-metadata-link] |
| Day of Defeat: Source | [`sourceservers/dod`][srcds-dod-dockerhub-link] | [![srcds-dod-version-badge][]][srcds-dod-metadata-link] | [![srcds-dod-size-badge][]][srcds-dod-metadata-link] | [![srcds-dod-layers-badge][]][srcds-dod-metadata-link] |
Expand All @@ -61,6 +62,11 @@ Dedicated servers hosted on Steam are usually required to be running the *latest
| Left 4 Dead 2 | [`sourceservers/left4dead2`][srcds-left4dead2-dockerhub-link] | [![srcds-left4dead2-version-badge][]][srcds-left4dead2-metadata-link] | [![srcds-left4dead2-size-badge][]][srcds-left4dead2-metadata-link] | [![srcds-left4dead2-layers-badge][]][srcds-left4dead2-metadata-link] |
| Team Fortress 2 | [`sourceservers/tf`][srcds-tf-dockerhub-link] | [![srcds-tf-version-badge][]][srcds-tf-metadata-link] | [![srcds-tf-size-badge][]][srcds-tf-metadata-link] | [![srcds-tf-layers-badge][]][srcds-tf-metadata-link] |

[srcds-cs2-dockerhub-link]: https://hub.docker.com/r/sourceservers/cs2
[srcds-cs2-version-badge]: https://img.shields.io/docker/v/sourceservers/cs2/latest?label=&style=flat-square
[srcds-cs2-size-badge]: https://img.shields.io/docker/image-size/sourceservers/cs2/latest?label=&style=flat-square
[srcds-cs2-metadata-link]: https://hub.docker.com/r/sourceservers/cs2/tags

[srcds-csgo-dockerhub-link]: https://hub.docker.com/r/sourceservers/csgo
[srcds-csgo-version-badge]: https://img.shields.io/docker/v/sourceservers/csgo/latest?label=&style=flat-square
[srcds-csgo-size-badge]: https://img.shields.io/docker/image-size/sourceservers/csgo/latest?label=&style=flat-square
Expand Down Expand Up @@ -194,6 +200,15 @@ The default [work directory](build/Dockerfile#L112) for all the images is [`/ser
##### Via command-line

```shell
# Counter-Strike 2
## Via default entrypoint (/bin/bash -c)
docker run -it --rm -p 27015:27015/tcp -p 27015:27015/udp sourceservers/cs2:latest 'game/bin/linuxsteamrt64/cs2 -dedicated -port 27015 +game_type 0 +game_mode 1 +mapgroup mg_active +map de_dust2'
docker run -it --rm -p 27015:27015/tcp -p 27015:27015/udp sourceservers/cs2:latest 'printenv && ls -al && exec game/bin/linuxsteamrt64/cs2 -dedicated -port 27015 +game_type 0 +game_mode 1 +mapgroup mg_active +map de_dust2'
## Via custom entrypoint (game binary)
docker run -it --rm -p 27015:27015/tcp -p 27015:27015/udp --entrypoint game/bin/linuxsteamrt64/cs2 sourceservers/cs2:latest -dedicated -port 27015 +game_type 0 +game_mode 1 +mapgroup mg_active +map de_dust2
## Via custom entrypoint (/bin/bash)
docker run -it --rm -p 27015:27015/tcp -p 27015:27015/udp --entrypoint /bin/bash sourceservers/cs2:latest -c 'printenv && ls -al && exec game/bin/linuxsteamrt64/cs2 -dedicated -port 27015 +game_type 0 +game_mode 1 +mapgroup mg_active +map de_dust2'

# Counter-Strike: Global Offensive
## Via default entrypoint (/bin/bash -c)
docker run -it --rm -p 27015:27015/tcp -p 27015:27015/udp sourceservers/csgo:latest 'srcds_linux -game csgo -port 27015 +game_type 0 +game_mode 0 +mapgroup mg_active +map de_dust2'
Expand Down
39 changes: 33 additions & 6 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,12 @@ if [ "$APPID" = 90 ]; then
else
DOCKER_REPOSITORY="${DOCKER_REPOSITORY:-${REGISTRY_SOURCE:?err}/$GAME}"
GAME_ENGINE='srcds'
GAME_BIN='srcds_linux'
# srcds/cs2
if [ "$APPID" = 730 ]; then
GAME_BIN='game/bin/linuxsteamrt64/cs2'
else
GAME_BIN='srcds_linux'
fi
fi
if [ "$PIPELINE" = 'build' ]; then
GAME_IMAGE_CLEAN="$DOCKER_REPOSITORY:$GAME_VERSION"
Expand Down Expand Up @@ -264,16 +269,38 @@ if [ ! "$NO_TEST" = 'true' ]; then
date
time docker run -t --rm "$GAME_IMAGE" 'printenv && ls -al'
date
time docker run -t --rm "$GAME_IMAGE" "$GAME_BIN -game $GAME +version +exit" | tee "$TEST_DIR/test"
# srcds/cs2
if [ "$APPID" = 730 ]; then
CONTAINER_ID=$( docker run -itd "$GAME_IMAGE" "$GAME_BIN -dedicated -port 27015 +map de_dust2" )
i=0; while [ "$i" -lt 30 ]; do
echo "Waiting for server to start"
docker container inspect -f '{{.State.Running}}' "$CONTAINER_ID" | grep '^true$' > /dev/null || break
docker logs "$CONTAINER_ID" | grep 'VAC secure mode is activated' && break || sleep 1
i=$(($i + 1))
done
docker logs "$CONTAINER_ID"
docker exec -it "$CONTAINER_ID" bash -c 'printf "\\xff\\xff\\xff\\xffTSource Engine Query\\x00" | nc -w1 -u 127.0.0.1 27015 | tr "[:cntrl:]" "\\n"' | tee "$TEST_DIR/test"
docker rm -f "$CONTAINER_ID" > /dev/null
else
time docker run -t --rm "$GAME_IMAGE" "$GAME_BIN -game $GAME +version +exit" | tee "$TEST_DIR/test"
fi
date

# Verify game version of the game image matches the value of GAME_VERSION
echo 'Verifying game image game version'
GAME_IMAGE_VERSION_LINES=$( cat "$TEST_DIR/test" | grep -iE '\bexe\b|version' | sed 's/[^0-9]//g' )
if ! echo "$GAME_IMAGE_VERSION_LINES" | grep -E "^$GAME_VERSION" > /dev/null; then
GAME_IMAGE_VERSION_LINES=$(
if [ "$APPID" = 730 ]; then
cat "$TEST_DIR/test" | grep -E '^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+'
else
cat "$TEST_DIR/test" | grep -iE '\bexe\b|version'
fi
)
echo 'GAME_IMAGE_VERSION_LINES:'
echo "$GAME_IMAGE_VERSION_LINES"
if echo "$GAME_IMAGE_VERSION_LINES" | sed 's/[^0-9]//g' | grep -E "^$GAME_VERSION" > /dev/null; then
echo "Game version matches GAME_VERSION=$GAME_VERSION"
else
echo "Game version does not match GAME_VERSION=$GAME_VERSION"
echo 'GAME_IMAGE_VERSION_LINES:'
echo "$GAME_IMAGE_VERSION_LINES"
exit 1
fi
rm -f "$TEST_DIR/test"
Expand Down
49 changes: 35 additions & 14 deletions build/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# Builds a clean image containing the latest version of the specified game.

FROM startersclan/steamcmd:git-20190605.0.0
FROM startersclan/steamcmd:git-20231109.0.0

ARG SERVER_DIR=/server
ARG APPMANIFEST_AR_URL=https://github.com/startersclan/hlds-appmanifest/archive/refs/tags/v2.0.0.tar.gz
Expand Down Expand Up @@ -75,30 +75,51 @@ RUN --mount=type=secret,id=STEAM_USERNAME \
fi; \
done; \
echo "[BUILD] Performing cleanup"; \
cd "$STEAMCMD_DIR" && rm -rf \
linux64 \
package \
public \
siteserverui \
steam \
linux32/libtier0_s.so \
linux32/libvstdlib_s.so \
linux32/steamclient.so \
linux32/steamconsole.so \
update_hosts_cached.vdf; \
rm -rf /root/.steam; \
# Clean up a different set of files for srcds/cs2
if [ "$APPID" = 730 ]; then \
cd "$STEAMCMD_DIR" && rm -rf \
package \
public \
siteserverui \
steam \
linux32/libtier0_s.so \
linux32/libvstdlib_s.so \
linux32/steamconsole.so \
update_hosts_cached.vdf; \
else \
cd "$STEAMCMD_DIR" && rm -rf \
linux64 \
package \
public \
siteserverui \
steam \
linux32/libtier0_s.so \
linux32/libvstdlib_s.so \
linux32/steamclient.so \
linux32/steamconsole.so \
update_hosts_cached.vdf; \
rm -rf /root/.steam; \
fi; \
if [ "$APPID" = 90 ]; then \
# Retain `/root/Steam/appcache` to prevent `steamcmd` from re-downloading `hlds` game entirely on game updates
rm -rf $( find /root/Steam -mindepth 1 -maxdepth 1 | grep -v '^/root/Steam/appcache' ); \
else \
# Cleanup. This also cleans up user data
rm -rf /root/Steam; \
fi;

# Apply game fixes
RUN echo "[BUILD] Applying game fixes"; \
# Create steam_appid.txt containing the game's appid to prevent crashes on first run
echo "[BUILD] CLIENT_APPID: $CLIENT_APPID"; \
echo "$CLIENT_APPID" > "$SERVER_DIR/steam_appid.txt"
echo "$CLIENT_APPID" > "$SERVER_DIR/steam_appid.txt"; \
# Create necessary symlinks for srcds/cs2
if [ "$APPID" = 730 ]; then \
mkdir -p /root/.steam/sdk64; \
mkdir -p /root/.steam/sdk32; \
ln -sf "/$STEAMCMD_DIR/linux64/steamclient.so" /root/.steam/sdk64/steamclient.so; \
ln -sf "/$STEAMCMD_DIR/linux32/steamclient.so" /root/.steam/sdk32/steamclient.so; \
fi;

# For directly running the hlds_linux / srcds_linux binary
ENV LD_LIBRARY_PATH .:bin:$LD_LIBRARY_PATH
Expand Down
35 changes: 35 additions & 0 deletions docs/image/readme/srcds-cs2.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
| `master` | `build` | `update` |
|:-:|:-:|:-:|
[![pipeline-github-master-badge][]][pipeline-github-master-link] | [![pipeline-travis-build-badge][]][pipeline-travis-build-link] [![pipeline-azurepipelines-build-badge][]][pipeline-azurepipelines-build-link] [![pipeline-circleci-build-badge][]][pipeline-circleci-build-link] [![pipeline-gitlab-build-badge][]][pipeline-gitlab-build-link] | [![pipeline-travis-update-badge][]][pipeline-travis-update-link] [![pipeline-azurepipelines-update-badge][]][pipeline-azurepipelines-update-link] [![pipeline-circleci-update-badge][]][pipeline-circleci-update-link] [![pipeline-gitlab-update-badge][]][pipeline-gitlab-update-link]

[pipeline-github-master-badge]: https://img.shields.io/github/actions/workflow/status/startersclan/docker-sourceservers/ci-master-pr.yml?branch=master&label=&logo=github&style=flat-square
[pipeline-github-master-link]: https://github.com/startersclan/docker-sourceservers/actions?query=branch%3Amaster

[pipeline-travis-build-badge]: https://img.shields.io/travis/com/startersclan/docker-sourceservers/build.svg?label=&logo=travis&style=flat-square
[pipeline-travis-build-link]: https://app.travis-ci.com/startersclan/docker-sourceservers/builds
[pipeline-travis-update-badge]: https://img.shields.io/travis/com/startersclan/docker-sourceservers/update.svg?label=&logo=travis&style=flat-square
[pipeline-travis-update-link]: https://app.travis-ci.com/startersclan/docker-sourceservers/builds

[pipeline-azurepipelines-build-badge]: https://img.shields.io/azure-devops/build/startersclan/docker-sourceservers/2/build.svg?label=&logo=azure-pipelines&style=flat-square
[pipeline-azurepipelines-build-link]: https://dev.azure.com/startersclan/docker-sourceservers/_build?definitionId=2
[pipeline-azurepipelines-update-badge]: https://img.shields.io/azure-devops/build/startersclan/docker-sourceservers/3/update.svg?label=&logo=azure-pipelines&style=flat-square
[pipeline-azurepipelines-update-link]: https://dev.azure.com/startersclan/docker-sourceservers/_build?definitionId=3

[pipeline-circleci-build-badge]: https://img.shields.io/circleci/build/gh/startersclan/docker-sourceservers/build.svg?label=&logo=circleci&style=flat-square
[pipeline-circleci-build-link]: https://app.circleci.com/pipelines/github/startersclan/docker-sourceservers?branch=build
[pipeline-circleci-update-badge]: https://img.shields.io/circleci/build/gh/startersclan/docker-sourceservers/update.svg?label=&logo=circleci&style=flat-square
[pipeline-circleci-update-link]: https://app.circleci.com/pipelines/github/startersclan/docker-sourceservers?branch=update

[pipeline-gitlab-build-badge]: https://img.shields.io/gitlab/pipeline-status/startersclan/docker-sourceservers?branch=build&label=&logo=gitlab&style=flat-square
[pipeline-gitlab-build-link]: https://gitlab.com/startersclan/docker-sourceservers/-/pipelines?page=1&scope=all&ref=build
[pipeline-gitlab-update-badge]: https://img.shields.io/gitlab/pipeline-status/startersclan/docker-sourceservers?branch=update&label=&logo=gitlab&style=flat-square
[pipeline-gitlab-update-link]: https://gitlab.com/startersclan/docker-sourceservers/-/pipelines?page=1&scope=all&ref=update

| Game | Image | Tag `v<tag>` | Size |
|:-:|:-:|:-:|:-:|
| Counter-Strike 2 | [`sourceservers/cs2`][srcds-cs2-dockerhub-link] | [![srcds-cs2-version-badge][]][srcds-cs2-metadata-link] | [![srcds-cs2-size-badge][]][srcds-cs2-metadata-link] | [![srcds-cs2-layers-badge][]][srcds-cs2-metadata-link] |

[srcds-cs2-dockerhub-link]: https://hub.docker.com/r/sourceservers/cs2
[srcds-cs2-version-badge]: https://img.shields.io/docker/v/sourceservers/cs2/latest?label=&style=flat-square
[srcds-cs2-size-badge]: https://img.shields.io/docker/image-size/sourceservers/cs2/latest?label=&style=flat-square
[srcds-cs2-metadata-link]: https://hub.docker.com/r/sourceservers/cs2/tags
15 changes: 15 additions & 0 deletions docs/samples/docker-compose/docker-compose.bash-c.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
version: '2.2'
services:
srcds-cs2:
image: sourceservers/cs2:latest
ports:
- 27015:27015/tcp
- 27015:27015/udp
stdin_open: true
tty: true
entrypoint:
- /bin/bash
- -c
command:
- |
set -e
game/bin/linuxsteamrt64/cs2 -dedicated -port 27015 +game_type 0 +game_mode 1 +mapgroup mg_active +map de_dust2
srcds-csgo:
image: sourceservers/csgo:latest
ports:
Expand Down
11 changes: 11 additions & 0 deletions docs/samples/docker-compose/docker-compose.binary.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
version: '2.2'
services:
srcds-cs2:
image: sourceservers/cs2:latest
ports:
- 27015:27015/tcp
- 27015:27015/udp
stdin_open: true
tty: true
entrypoint:
- game/bin/linuxsteamrt64/cs2
command: -dedicated -port 27015 +game_type 0 +game_mode 1 +mapgroup mg_active +map de_dust2

srcds-csgo:
image: sourceservers/csgo:latest
ports:
Expand Down
Loading

0 comments on commit 8aedd70

Please sign in to comment.